Setting up music on hold
From Etel
Contents |
Title
Setting up music on hold
Problem
Music on hold can be as simple or as complicated as you want to make it. On the simple end, you can provide Asterisk with a few MP3 files and it will transcode them on the fly or you can transcode them ahead of time to save on CPU cycles. On the complicated end, you can connect Asterisk to a music stream from the Internet or a local radio station (though you should probably check on local legalities of doing so).
Solution
Simple
The most basic form is a single "class", set up as the default. In /etc/asterisk/musiconhold.conf, the configuration looks like:
[default] mode=files directory=/var/lib/asterisk/moh
The above causes Asterisk to play files left in /var/lib/asterisk/moh, in normal sorting order with no adjustments to the volume. Asterisk will transcode the file to whatever codec is needed unless the file already exists in that codec (pre-transcoding will save CPU cycles). Files can be in as many codecs as needed, they will only be played once in the order. You can make the order random by adding the following to the class definition:
random=yes
The following modes alter the above class definition so that only the MP3 files in the directory are played with the following attributes:
quietmp3 -- buffered at default volume mp3 -- buffered, loud mp3nb -- unbuffered, loud quietmp3nb -- unbuffered at default volume
Your "on hold" music can then be called in a number of ways. In your dial plan, you can call a specific class explicitly:
exten => 555,1,Answer() exten => 555,n,Playback(no-one-here) exten => 555,n,MusicOnHold(default)
The above causes the music to play without the channel being "on hold". You can set the music to be played whenever the caller to the channel is put on hold via the SetMusicOnHold application:
exten => 556,1,Answer() exten => 556,n,SetMusicOnHold(default) exten => 556,n,Dial(SIP/BobsDesk) exten => 556,n,Hangup()
Note: In the above examples, the word "default" can be left out. MusicOnHold() and SetMusicOnHold() will assume "default" if nothing is included between the parens.
Less simple
A slightly less simple configuration is to set up multiple folders and defining multiple classes in musiconhold.conf. You can then provide different types of audio of different sets of callers (e.g., customers hear your sales pitch, the boss's wife hears classical music, and your call center employees hear stats about the number of callers waiting in queue). The first two involve setting up multiple classes using the method above, then assigning that class to the context used by a specific person or category of persons (hint: don't assign your boss's wife to the same queue or context as those calling the help desk!) The third method can get quickly get quite complicated: pulling an audio stream in from somewhere (or providing your own).
Complicated
Other than playing stored files, Asterisk has the ability to pipe audio streams into a call. The problem is that Asterisk cannot play audio streams directly. It relies on external applications to transfer the audio data to the STDIN interface for Asterisk. To be able to hear audio streams, the audio must be converted to a specific sample rate and mono format. Very few programs have all three of these features. Fortunately, there are programs that can do this, mpg123 being one of them.
[holdmusic] mode=custom application=/usr/bin/mpg123 -q -r 8000 -f 8192 -b 0 --mono -s http://192.168.1.175:8000/holdmusic.mp3;
"-q" cause mpg123 to suppress any diagnostic message (i.e., quiet mode) "-r 8000" causes mpg123 to set a constant sample rate at 8000 "-f 8192" causes mpg123 to set the scaling factor to 8192 "-b 0" causes mpg123 to turn off buffering "--mono" (or "-m") causes mpg123 to mix both channels and output mono audio "-s" pipes the audio to STDOUT (you must have this!) "http://192.168.1.175:8000/holdmusic.mp3" is just an example URL
The URL above is just an example. You can point it at just about any URL that works with
mpg123 http://exampleurl
Note: It's recommended that you use "-b 0" to turn off buffering. Otherwise, the audio is likely to start/stop without warning.
Even More Complicated
These are just ideas:
- stand up your own Icecast server
- use Savonet/Liquidsoap to stream your media libary to Icecast
- use SqueezeCenter to stream your media library directly to mpg123 or to Icecast
Discussion
See Also:
- Savonet/Liquidsoap - http://savonet.sourceforge.net/
- SqueezeCenter (formerly SlimServer) - http://www.slimdevices.com/su_downloads.html
Metadata
- By: Tim Kramer
