Occasionally, we get a request to use an Internet radio station as a source for music on hold (MOH) on Asterisk or FreePBX.
Implementing this is actually fairly straightforward.
We will use:
The first step is to actually find the stream you want to use. Technically, you can use just about any streaming source that’s non-proprietary and use a Linux command-line player to send the output into something like SOX to produce the proper format for Asterisk. We’re going to keep is very easy and use an MP3 stream and the basic MPG123 command-line player. (This hasn’t shipped with Asterisk for some time, but you can find a download for it here.)
Choose a lower-bitrate styream if you can… No need to waste bandwidth on a hi-def 256kbps stream when we’re going to resample it down anyway.
So, I’m going to go to Shoutcast.com and click the Jazz category. The top result is SmoothJazz.com, so we’ll use that. Right-click on the link to get the .pls file and then open that using a text editor. We actually want the part that looks like this:
[playlist] numberofentries=22 File1=http://scfire-ntc-aa06.stream.aol.com:80/stream/1005 Title1=(#1 - 24/11500) SmoothJazz.com Global Radio - The World's First 24/7 Since 2000 - KJAZ.DB
Grab the URL on the File1 line. This will be the streaming URL.
The next step is to log into your FreePBX interface and navigate to the “Music on Hold” menu. (You’ll find it under Settings in recent versions of FreePBX.)
Click ‘Add Streaming Category’.
The Category Name is arbitrary, so here we can use the radio station name. (In my example, I’m going to use “SmoothJazz”.)
For Application, we’re going to use MPG123 to play the steam here. Make a note of this command line, as you’ll need to get the resampling parameters right. Replace the http://xxxx part with your URL from above.
/usr/bin/mpg123 -q -r 8000 -f 8192 --mono -s http://scfire-ntc-aa06.stream.aol.com:80/stream/1005
Leave the ‘Optional Format’ field blank.
That’s it! Submit Changes and you’ve now got a MOH class ready to use wherever you want on your system.