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:

  • MP3 files are extremely complex, and require a substantial amount of CPU to decode. If you have a lot of channels pulling music from the system (for example, people sometimes like to listen to music through their phone, or a call center may have several callers on hold), the load on the CPU caused by all of the transcoding of the stored MP3 files could place too much demand on a machine that is otherwise suitable to the performance needs of the system.

  • Current-generation hard drives hold a lot of data, so there may not be any reason to worry about cutting down hard drive use. Compressed audio makes sense from a distribution standpoint (an MP3 is a much smaller download than the equivalent in .wav format), but once on your system, do we really care how much space they take up?

  • MP3 files don’t usually come with the right sort of licensing. ;-)

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:

  • People don’t actually want to be on hold, so they are not usually planning to be there for long. This means that there is not much point in providing them with a mind-expanding musical experience. If things go as they hope, they won’t be there long enough to get into it.

  • The fidelity on a phone system does not allow for accurate reproduction of tones. Heavy bass generally sounds terrible, and high frequencies will typically just end up as noise. Keep the music simple, and it is more likely to sound good.

  • Musical tastes are as varied as people, and while it might be nice to try and cover a wide range of styles, music that is too eclectic is more likely to annoy than enlighten.

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.

Get Asterisk: The Future of Telephony, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.