Music on Hold

Any popular PBX system offers the ability to supply a source of music to be played for callers while on hold. Asterisk allows for a lot of creativity in this regard.

Nowadays, everyone is familiar with the MP3 music format, and there is a lot of interest in using MP3s as a music-on-hold source. The concept sure seems like a good idea, but there are a few things that we think should be given some consideration:

Taking all of this into consideration, we recommend that you convert your music sources into the native format of the various codecs you may be supporting. For example, if you support μlaw for your internal phones, and G.729 on your VoIP circuits, you will want to store your music in both formats so that Asterisk will not have to perform transcoding to play music to calls on those channels.

We often use public domain music (or Creative Commons licensed music) on our systems. Creative Commons music often comes in ogg-Vorbis format (which is conceptually similar to MP3, but not compatible). In order to play .ogg or .mp3 files on our Asterisk system, we are going to convert them to a format that Asterisk can easily handle. This requires the following steps:

  1. We need to make sure that SoX, the Sound eXchange utility, is installed. If not, run the following command to install it:

    $ yum install sox
  2. Download the music that you have chosen to a working folder on your system (/tmp is probably a suitable location). As an example, the following command downloaded some nice piano music by Pachelbel for us:

    $ wget http://upload.wikimedia.org/wikipedia/commons/6/62/Pachelbel%27s_Canon.ogg
  3. Now we have to convert the song from ogg-Vorbis format to a format more suitable to Asterisk:

    $ sox Pachelbel\'s_Canon.ogg -r 8000 -c 1 -s -w moh1.wav resample -ql

    Tip

    You may also need to adjust the amplitude with the -v option.

    We’ve now taken our source file, converted it to a .wav file suitable to Asterisk,[146] and saved the resulting file as moh1.wav.

  4. Almost done now. We just need to create a folder for the permanent home of the new files (/tmp is certainly no place for them):

    $ mkdir /var/lib/asterisk/mohwav

    and then move them there:

    $ mv *.wav /var/lib/asterisk/mohwav
  5. Since we have placed our music files in a different folder from that where Asterisk installs its sample music, we will need to change the configuration file to reflect this. Edit your /etc/asterisk/musiconhold.conf file with one that contains the following:

    [default]
    mode=files
    directory=/var/lib/asterisk/mohwav
    random=yes

As for what to play, that will depend on what image you want to project to your callers. Regardless of your choice, you should keep some things in mind:

Classical music addresses all of the above criteria, and it is easy to obtain. It also sounds classy (go figure!), so it is a pretty safe choice, although we’ll admit it doesn’t usually score any points in the hipness department.

Asterisk includes three songs with the source code download that are licensed for use with Asterisk. These songs are intended as samples. Since there are only three of them, people who call you regularly will quickly tire of them. We have a recurring nightmare in which the worldwide success of Asterisk means that the human race is forced to listen to the same three songs as music on hold. That is why we wrote this section for you.



[145] Seed a search with the term “Creative Commons music” to find more freely usable music.

[146] Note that we could have used any format that was compatible with Asterisk; we’ve just chosen .wav for this example because it is easy for the CPU to transcode into μlaw/alaw/slin on the fly, yet remains easy to work with in other environments.