Music on hold is a nice feature of asterisk, implemented through res_musiconhold.so. To setup music on hold the standard way you need to download recompile and install mpg123 as voip-info suggests.
Note that on Debian there's a symlink between mpg123 and mpg321 (which is not supported currently). So, download mpg123-0.59r.tar.gz, compile it, and install it (by default the package is installed in /usr/local/bin, which is the first path searched by asterisk).
Another way to setup music on hold is to integrate MoH patch (the patch is bundled with chanspy) into the asterisk package, thus enabling native file format decoding and removing mpg123 dependancy. What follows are some simple steps to setup a MoH extension using ulaw encoded files.
# apt-get install build-essential dh-make patch
# wget <url-to-chanspy-tar-gzip-archive>
# tar xzf chanspy.tar.gz
This command creates a directory named chanspy
1. Patch and rebuild asterisk
# apt-get source asterisk
This command creates a directory named asterisk-<current-version> (in my case asterisk-1.0.1)
# cd asterisk-1.0.1
# patch -p0 < ../chanspy/mohpatch.diff
# dpkg-buildpackage -D -b
If this last command fails, make sure to fulfill all the dependencies (don't be warned if more than 50 packages need to be installed).
# dpkg -i ../asterisk_*.deb
2. Add a sample extension to asterisk
First add the following lines to /etc/asterisk/extensions.conf
exten => 1234,1,Answer
exten => 1234,2,SetMusicOnHold(ulawfiles)
exten => 1234,3,MusicOnHold()
Then configure the ulawfiles class in /etc/asterisk/musiconhold.conf adding these lines
ulawfiles => /usr/share/asterisk/sounds/ulawfiles
Make sure to have some files to be played in the right place
# mkdir -p /usr/share/asterisk/sounds/ulawfiles
# sox -V example.mp3 -t au -r 8000 -U -b -c 1 \
/usr/share/asterisk/sounds/ulawfiles/example.ulaw resample -ql
3. Restart asterisk and make a call to 1234 and enjoy the music on hold...
# /etc/init.d/asterisk restart
4. Fine tuning and audio improvements
With format_mp3.so module MoH can also play mp3 files. Some files may play scratchy due to the high volume level, you can adjust the amplitude with the "-v volume" flag of sox.