Asterisk: Music on Hold
Wednesday, March 28, 2007, at 09:55AM
By Eric Richardson
I started a couple times to write grand posts about my progress building an Asterisk PBX and kept not finishing, so instead I think I'm just going to write up little things I figured out.
When I first installed Asterisk, I wanted to be able to call and hear something. Particularly I thought it would be kind of cool to use KCRW's music stream as a test music source (though it wouldn't be legal to use it as a music on hold source in production).
Vaguely following this wiki entry, here's how I got it working...
I created a /var/lib/asterisk/scripts/ directory and made a file in it called kcrwmoh.sh. That file contains:
#!/bin/bash
wget -O - http://scfire-dll0l-2.stream.aol.com:80/stream/1045 \
| madplay -Q -o raw:- -R 8000 -a -6 --mono -
A smarter script would actually grab KCRW's .pls file and parse the source URL out of it, but this was plenty for now. It grabs the stream data and feeds it into madplay, where it's converted from MP3 to a raw mono 8kbit stream. The output goes to STDOUT.
Next, in musiconhold.conf:
[default]
mode=custom
application=/var/lib/asterisk/scripts/kcrwmoh.sh
That tells asterisk to grab the audio using the script we just made.
Finally, to allow me to dial into music on hold and test it, I set this extension up in extensions.conf:
exten => 6000,1,Answer
exten => 6000,2,MusicOnHold()
You could put that in the default context, or some special internal context.
Then just dial 6000 and there's your music. Not the best quality, but it's a phone.