I am experimenting with audio players in the command line, and noticed something weird: if the sound is very short, most players will take up to a second or two after playback has finished, before they finally exit, and yield control back to the terminal!

ffplay seems to run a spectrogram when started with an audio file, and the advice to fix that is:

<hypnocat> how can i turn off the spectrogram display?
<sacarasc_> Why would you want to?
<hypnocat> i don't want an extra window to appear, or for ffplay to waste extra processing power displaying it
<hypnocat> it's distracting, annoying, and wasteful
<sacarasc_> Minimise it, and if it's wasteful, your computer is either really, really old or you're overly sensitive to waste...
<hypnocat> my computer is old

... so I wouldn't really count that as a command line player; but I've tried these commands on my Ubuntu 11.04's gnome-terminal:

aplay --buffer-size=10 -q /usr/share/sounds/speech-dispatcher/test.wav
canberra-gtk-play -c never -f /usr/share/sounds/speech-dispatcher/test.wav
mplayer -really-quiet /usr/share/sounds/speech-dispatcher/test.wav
pacat -p --rate 16000 --channels 1 --latency-msec=1 --process-time-msec=2 /usr/share/sounds/speech-dispatcher/test.wav
play -q /usr/share/sounds/speech-dispatcher/test.wav  # with sox

The speech-dispatcher/test.wav sound itself is 0.542 sec, yet these programs claim the terminal for about one or two seconds (or more) after that file has finished playing. Why does this happen - and how could I avoid that? If it is impossible for these applications, are there command line audio players in existence, which do exit immediately after an audio file has finished playing?

EDIT: for those interested, this is what I needed this for Question #208391 : Questions : “xorg” package : Ubuntu: Getting X11 XBell event to play through PulseAudio; and I worked around the waiting time issue by starting the player (in that case, canberra-gtk-play) as a process (with &). But I'd still like to know why this exit delay happens on short files? And how come cvlc, as per @Anthon's answer, can for instance exit immediately??

  • On my system, playing test.wav with any player (play, mplayer, aplay) takes about 0.64s, meaning an overhead of about 0.1s, not >1s. I don't use a sound server. You seem to be going through PulseAudio, I suspect it is the culprint. Try playing directly or over JACK. – Gilles 'SO- stop being evil' May 11 '13 at 22:33
  • I know this is nitpick-y, but if you're leaving this open 'for the why' instead of accepting Anthon's answer, you might change the title to reflect that (asking 'why the delay' instead of 'what program'). Actually probably 'should' open a separate Q, but I doubt anyone would mind the edit. Both good Questions, though. – hunter2 Jul 9 '13 at 3:26

try this for ffplay:

ffplay -autoexit -nodisp -loglevel panic /usr/share/sounds/speech-dispatcher/test.wav 
  • 1
    Thanks for the comment @narco, +1 for effort; however, even this command starts the visualizer window - and keeps it hanging for a second, two or more, before exiting - so, same problem as in the OP (and additionally, with a window). – sdaau May 11 '13 at 11:13

I use:

cvlc --no-one-instance --volume 150 <soundfile>

to play short sounds (< 1 second) as notifiers for program activities.

The --no-one-instance makes sure this playing does not get scheduled after something that might be running in my 'normal' vlc (like music) and which is setup to have a single instance and for which additional invocations (commandline, double-clicking), add the files to the playlist.

  • Many thanks for that, @Anthon - first of, this command completely failed for me; but that was because I hadn't initialized audio device for vlc (1.1.9) Preferences for this desktop environment. Once I set that, cvlc could play - but it kept looping the sound, which is a Playlist setting in Preferences. Once "Repeat all" was turned off, then it started playing - but it seems it has a problem with the .wav file used above, although no problems with .ogg. Finally, --no-one-instance seems to raise as process, but apparently for me it was more important ... – sdaau May 11 '13 at 11:17
  • 1
    The repeat is off in my 'normal' vlc as well. Being lazy, when I needed this, I just searched for the right combination of commandline options that made it work for me, not for all of the commandline options that would make it work with every conceivable setup of vlc ;-) – Anthon May 11 '13 at 11:20
  • ... to specify --play-and-exit; so finally, cvlc -q --play-and-exit /usr/share/sounds/ubuntu/stereo/service-logout.ogg does exit instantly - but any sounds shorter than a second, seem to be unreliably played back. Anyways, I'd like to know where does this delay come from, so I'll keep this question open for a while. Cheers! – sdaau May 11 '13 at 11:21
  • PS: Thanks for the clarification of --no-one-instance (wasn't what I expected :)) – sdaau May 11 '13 at 11:22
  • 1
    I have had these delay on audioplay problems with VLC in the past as well, but that must have been with Ubuntu 12.04. I am not sure what made them go away, but it might just have been a package upgrade, as I don't remember investigating it. I am not sure if such an upgrade made it into 11.04. If you have a chance I recommend to boot a more recent Ubuntu version from DVD/CD and see if you would still have the problem. – Anthon May 11 '13 at 11:42

SoX works on Ubuntu (in the ubuntu universe repo), & was installed on the live Linux Mint XFCE 16 disk. Can play files in a terminal, no new windows or anything & quits immediately after with:

play /this/file

It calls itself "SoX - Sound eXchange, the Swiss Army knife of audio manipulation" ... "particularly suited to making quick, simple edits and to batch processing" and is supposed to be able to do a bunch of stuff, effects, combine multiple inputs, write to output files. Apparently it's been around since 96 according to the changelog.

Answering an old question I know, but I was just searching how to answer the exact problem (sound notification script for new mail) and sox works perfectly, even better than vlc/cvlc (it took longer & sounded a little different with a little click at the end?).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.