How to make a sound once a process is complete?

I have started a long process through a terminal. Is it possible to make the Ubuntu terminal make a sound once the process is complete? This way, I don’t need to keep checking, but will instead be notified through a sound.


I use

make; spd-say done

Replace "make" with whatever long-running command you use.


There are at least three command line ways to accomplish this by putting the suiting command at the end of your script you may invoke for your lengthy process:

  1. The "classical" way to play a sound is to use beep.

    Beep will make a tone through the PC speaker. However this will not work in all cases (e.g. in my system PC speakers are completely disabled) You may have to remove pcspkr from /etc/modprobe/blacklist.conf and load the pcspkr kernel module:

    sudo sed -i 's/blacklist pcspkr/#blacklist pcspkr/g' /etc/modprobe.d/blacklist.conf
    sudo modprobe pcspkr
    beep [optional parameters]
    
  2. We can also play any sound file in wav format using aplay (installed by default):

     aplay /usr/share/sounds/alsa/Side_Right.wav
    
  3. Another way is to use the pulseaudio command line interface to enable playback of any sound files your system (in libsndfile) recognizes on the default audio output:

      paplay /usr/share/sounds/freedesktop/stereo/complete.oga
    

We can use default sound files from /usr/share/sounds/, or any other sound file we may have in a different location.


Just to have mentioned it, there is another nice way to achieve this by misusing espeak, which is installed by default in Ubuntu <= 12.04. See, or rather hear the following example:

#! /bin/bash

c=10; while [ $c -ge 0 ]; do espeak $c; let c--; done; sleep 1 ## here lengthy code
espeak "We are done with counting"

In Ubuntu >= 12.10 Orca uses speak-dispatcher. We can then install espeak, or alternatively use spd-say "Text".


According to this the \a character escapes ASCII code 7, which is the computer's beep.

So echo $'\a' works to make a beep sound on my local machine, even when it's executed on a bash shell running on a computer I'm connected to via a terminal interface like PuTTY.