5

I'm looking for a software that reproduces audio files (wav and mp3 if possible) and provides a way to change the playback speed in real-time, flawlessy. I mean, without any gap, pop, or noise. Like the sampling clock is changed smoothly.

I'm NOT interested in maintaining the pitch constant (like this question: Play a sound file slower or faster). Instead the pitch MUST follow the new speed.

I need to change the speed programmatically, say from 20% to 200% of the original one.

Is there something ready, without reinventing the wheel?

0

5 Answers 5

4

mplayer can playback wav and mp3 files, and you can interactively change the speed with keys [ and ], although wav files cannot be played slower than than their original speed. vlc can do the same and manages to slow down wav files too. Faster speeds move the frequencies up.

2
  • 1
    Same for mpv, a fork of mplayer. And both can play wav files at slower speeds on my machine.
    – xhienne
    Commented Aug 23, 2017 at 9:30
  • @xhienne You are right. mplayer did slow down some wav files, but I had one sampled at 8000Hz which it failed to slow down, whereas mpv managed ok. Perhaps I just have an old version.
    – meuh
    Commented Aug 23, 2017 at 9:50
3

You can use mplayer -af scaletempo -speed 0.5 filename.mp3 to change the playspeed without changing the audio pitch.

If you would like to change the speed in real time (after calling mplayer from the command line), you will have to create run player in slave mode.

References:

  1. https://stackoverflow.com/questions/36867732/slave-mode-mplayer-pipe
  2. https://stackoverflow.com/questions/15856922/python-send-command-to-mplayer-under-slave-mode

https://github.com/ankitects/anki/blob/484377b8091179504b21b29be1de6925c70af4bd/qt/aqt/sound.py#L374-L404

class SimpleMplayerPlayer(SimpleProcessPlayer, SoundOrVideoPlayer):
    args, env = _packagedCmd(["mplayer", "-really-quiet", "-noautosub"])
    if isWin:
        args += ["-ao", "win32"]

class SimpleMplayerSlaveModePlayer(SimpleMplayerPlayer):
    def __init__(self, taskman: TaskManager):
        super().__init__(taskman)
        self.args.append("-slave")

    def _play(self, tag: AVTag) -> None:
        assert isinstance(tag, SoundOrVideoTag)
        self._process = subprocess.Popen(
            self.args + [tag.filename],
            env=self.env,
            stdin=subprocess.PIPE,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
            startupinfo=startup_info(),
        )
        self._wait_for_termination(tag)

    def command(self, *args: Any) -> None:
        """Send a command over the slave interface.
        The trailing newline is automatically added."""
        str_args = [str(x) for x in args]
        if self._process:
            self._process.stdin.write(" ".join(str_args).encode("utf8") + b"\n")
            self._process.stdin.flush()

    def seek_relative(self, secs: int) -> None:
        self.command("seek", secs, 0)

    def toggle_pause(self) -> None:
        self.command("pause")
1
  • The scaletempo allows change in speed but does not change the pitch. The OP specifically states, "the pitch MUST follow the new speed". Omit the scaletempo option entirely to allow pitch to follow speed. Commented May 5, 2020 at 11:04
1

For those who need to set up speed from command line, use -speed SPEED option:

mplayer -speed 0.1 file

NOTE: you can change this speed in real time with [ and ] keys.

Of course, works for mpv as well.

Credits: https://linuxacademy.com/blog/linux/tutorial-playing-around-with-mplayer/

4
  • 2
    As far as I understand, this doesn't address the question because you cannot change the speed parameter in real time as requested.
    – Mark
    Commented Jun 4, 2018 at 7:53
  • @Mark you're right. Should I delete the question?
    – pevik
    Commented Jun 4, 2018 at 7:56
  • Or just edit the answer adding that it doesn't work in real time. Perhaps others might find it useful anyway.
    – Mark
    Commented Jun 4, 2018 at 7:57
  • 1
    @Mark OK like this?
    – pevik
    Commented Jun 4, 2018 at 9:12
0

For readers in 2022 with mplayer (in my case installed via brew), put this in your terminal config (in my case .zshrc):

alias mplayer="mplayer -af scaletempo=speed=tempo"

then during playing you can tune the playback speed via ](increase) and [(decrease). Don't forget that /(decrease volume), and *.

-1

As user said

mplayer -af scaletempo file.mp4

Is what you need. Scale tempo (speed) while maintaining pitch. Basically the speed changes but you don't get the chipmunk/ghost effect when the speed is much higher/lower.

More info on scaletempo here

Now, using "[" or "]" you can increase/decrease the playback speed on the fly.

As that cannot be preset on settings (or I couldn't find how), I decided to create a desktop entry (kind of alias for an app in LXDE desktop) so I can open the relevant files from file explorer with that coded loaded in.

I leave it here in case someone wants it.

[Desktop Entry]
Type=Application
Name=mplayer scaletempo
GenericName=Media Player
X-GNOME-FullName=MPlayer Media Player
Comment=Play movies and songs
Keywords=Player;Capture;Audio;Music;Song;Video;Movie;Film;Clip;DVD;VCD;CD;Disc;DVB;TV;
Icon=mplayer
#TryExec=gmplayer
Exec=/usr/bin/mplayer -af scaletempo %F
Terminal=false
Categories=GTK;AudioVideo;Audio;Video;Player;TV;
MimeType=application/x-cd-image;application/x-cue;application/x-mpegurl;application/mxf;application/x-netshow-channel;application/ogg;application/ram;application/vnd.adobe.flash.movie;application/vnd.apple.mpegurl;application/vnd.rn-realmedia;application/x-shockwave-flash;application/smil;audio/aac;audio/ac3;audio/x-adpcm;audio/x-aiff;audio/AMR;audio/AMR-WB;audio/x-ape;audio/basic;audio/flac;audio/x-flac;audio/x-flac+ogg;audio/x-m4b;audio/x-matroska;audio/mp2;audio/mp4;audio/mpeg;audio/x-mpegurl;audio/x-ms-asx;audio/x-ms-wma;audio/x-musepack;audio/ogg;audio/vnd.rn-realaudio;audio/x-scpls;audio/x-voc;audio/x-vorbis+ogg;audio/x-wav;audio/x-wavpack;video/3gpp;video/3gpp2;video/dv;video/x-flic;video/x-flv;video/x-matroska;video/mp2t;video/mp4;video/mpeg;video/vnd.mpegurl;video/x-ms-asf;video/x-ms-wmv;video/x-msvideo;video/x-nsv;video/ogg;video/x-ogm+ogg;video/quicktime;video/vnd.rn-realvideo;video/x-theora+ogg;video/webm;x-content/audio-cdda;x-content/audio-dvd;x-content/video-dvd;x-content/video-svcd;x-content/video-vcd;

If you put that on a text file as blah.desktop you have your "new" application ready to be used from the window manager.

1
  • 1
    The scaletempo allows change in speed but does not change the pitch. The OP specifically states, "the pitch MUST follow the new speed". Omit the scaletempo option entirely to allow pitch to follow speed. Commented May 5, 2020 at 11:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .