It’s been over 7 years since we first wrote about streaming music on hold with Asterisk®. While we’re energized with Back to School Fever, we decided it was about time for a refresher. And, in honor of TWOfer Tuesday, we also have a terrific new SIP discovery to share. It won’t cost you a dime.
For long time readers of Nerd Vittles, you will note that all of the MOH syntax has changed since the early Asterisk days. So today we wanted to document how to integrate streaming music on hold into Asterisk 11 with or without FreePBX®.
Prerequisites: With the PIAF-Green platform, all of the Linux tools you’ll need are already in place. On other Asterisk platforms, you may need to install MPG123 before any of this will work. Before streaming audio can be used for Music on Hold (MOH) with Asterisk, there are three essential pieces. First, you must have a source of streaming audio that works. Second, you need a streaming audio player on your Asterisk/Linux server that can "talk" to Asterisk. And, finally, Asterisk has to be properly configured to support streaming audio as the source for your music on hold.
Legal Disclaimer. There are all sorts of licensing restrictions on streaming of commercial music. With commercial radio broadcasts, the short answer is you can’t do it without paying a fee. However, things get murky where your music on hold stream originates with an Internet provider who already has paid a fee for your use of the streaming content. Nevertheless, you should consult with an attorney before beginning your broadcasting career. It would be an understatement to suggest that the RIAA, ASCAP, and their friends in Congress and the White House, have made "music mooching" an expensive hobby. In addition, there is a move afoot by the White House to make streaming of copyrighted music a felony. Not surprisingly, the White House Copyright Czar just jumped ship to take a cushy job heading up the industry’s anti-piracy lobbying group. For those that are criminally inclined, it probably would be less expensive to return to the glory days of shoplifting music and playing it in the comfort of your home or dorm room… not that we would ever encourage criminal behavior, of course.
Choosing a Streaming Audio Source. An almost infinite variety of streaming audio exists on the net. If you’re just getting into streaming audio, head over to SHOUTcast.com for over 50,000 FREE sources to get you started. If you’d prefer to set up your own SHOUTcast server, Nerd Vittles has previously covered solutions for both the Windows (WinAMP) and Mac (NiceCast) platforms. This is one area where the Mac platform really shines. NiceCast works flawlessly. Insofar as Asterisk is concerned, here’s the bottom line. If the streaming audio source you’ve chosen sounds like crap when you play it on your PC or Mac, it will sound the same way (or worse) as your MOH source. So start your project by picking a source that sounds good and be sure it plays reliably on your desktop PC or Mac before proceeding further. Keep in mind that anything above a 24K mono stream is wasted on a telephone call so there’s no need to choose a 128K stereo audio stream unless you just want to eat up your bandwidth. Also keep in mind that, unless you’re using your own stream on your private LAN, the streaming audio will be using the same bandwidth that you need to support incoming and outgoing phone calls over your broadband connection. So less is more!
Configuring Asterisk for MOH Streaming Audio. Here are the three steps to get things working today. First, you’ll need the web link to your music source. Second, you’ll need to configure a MUSICCLASS Channel to support that stream using Asterisk. And third, you’ll need to set up a test extension to try out your music stream.
In the case of SHOUTcast.com, the procedure to obtain the necessary link for your streaming audio source is straight-forward. Find the station desired and Ctrl-Click or Right-Click on the station and copy the link to your clipboard. This is NOT the link you’ll need for Asterisk! Instead, open the link in a new browser window. It will download a .pls file to your desktop. Open this file using a text editor, and copy out one of the File* entries (if there are several). Choose the one that looks something like this: http://18.104.22.168:5016. If you’re using Nicecast on a Mac, start up the app, choose your music source, and then click the Share button. Nicecast will display two entries as shown below:
Using our example, the required Nicecast link for Asterisk running on the same LAN is http://192.168.0.105:8002.
Now set up a music on hold channel for your streaming audio: nano -w /etc/asterisk/musiconhold_custom.conf. If you’re using your own streaming audio server, then use the Nicecast entry from the procedure above. Otherwise, use the SHOUTcast entry following the procedure we outlined. Here are some examples:
application=/usr/bin/mpg123 -q -r 8000 -f 8192 -b 2048 --mono -s http://22.214.171.124:5016
application=/usr/bin/mpg123 -q -r 8000 -f 8192 -b 2048 --mono -s http://126.96.36.199:80
application=/usr/bin/mpg123 -q -r 8000 -f 8192 -b 2048 --mono -s http://sfstream1.somafm.com:8032
;application=/usr/bin/mpg123 -q -r 8000 -f 8192 -b 2048 --mono -s http://192.168.0.105:8002/
There’s a reason we’ve commented out the [nicecast] entry. If Asterisk doesn’t find it running, you’ll get an endless stream of "Interrupted system call" errors, not exactly the sort of stream we had in mind. And a cautionary note about bandwidth: a streaming audio source, once configured, continues streaming until you disable it in musiconhold_custom.conf and restart Asterisk. So choose your sources, the number of sources, and the amount of bandwidth each consumes carefully. Finally, here’s a tip about the volume of your audio stream. With MPG123, the -f setting is the closest thing there is to a volume setting. The values range from 1 to 32768. If some of your callers will be using cellphones, it has been reported that the 8192 setting is too high. Give 1192 a try and adjust as necessary to meet your own requirements.
Once you’ve specified your audio stream(s), save the updated musiconhold custom file: Ctrl-X, Y, then Enter.
Testing Your MOH Stream with Asterisk. With everything now properly configured, let’s set up an extension just to be sure it’s working correctly. Edit your extensions_custom.conf file in /etc/asterisk and insert the following snippet in the [from-internal-custom] context:
exten => 466,1,Answer
exten => 466,2,Playback(pls-hold-while-try)
exten => 466,3,Set(CHANNEL(MUSICCLASS)=nicecast)
exten => 466,4,MusicOnHold()
exten => 466,5,Hangup
exten => 467,1,Answer
exten => 467,2,Playback(pls-hold-while-try)
exten => 467,3,Set(CHANNEL(MUSICCLASS)=Reggae)
;exten => 467,3,Set(CHANNEL(MUSICCLASS)=Top40)
;exten => 467,3,Set(CHANNEL(MUSICCLASS)=NewAge)
exten => 467,4,MusicOnHold()
exten => 467,5,Hangup
Once you’ve added this extension code, save the updated file: Ctrl-X, Y, then Enter. Then restart Asterisk: amportal restart. Pick up a phone on your Asterisk system and dial 467. After you’re connected, it may take up to 2 minutes for the streaming audio to begin, but this delay only occurs after Asterisk is restarted. Once you’ve heard your audio stream playing, hang up and call back just to make sure. Remember, each stream you activate continues streaming! It’s your bandwidth.
Configuring FreePBX 2.11 for MOH Streaming Audio. Once you have everything working, let’s switch to FreePBX 2.11 and show you the quick-and-dirty way to accomplish the same thing with a single line of code. Just use the same Application string that was used in the musiconhold_custom.conf setup above. The only caution here is be sure to use different labels than the ones used above. For example, to use the same source as NewAge, just change the label to NewAge2 in FreePBX.
Now open FreePBX and click Settings -> Music on Hold -> Add Streaming Category. Then fill in the blanks like this:
Once you have one or more streaming categories defined, you can select your favorite when you create a new Inbound Route, Ring Group, or Conference.
SIP Nirvana. We have another terrific SIP discovery for you this week. Previously, we’ve raved about Sip2Sip’s free SIP URIs and AnveoDirect’s terrific SIP bargains for those that like wholesale prices. And last week we introduced SIP.US which finally hits the $20/trunk price point for unlimited inbound and outbound calling in US48. It also works hand-in-glove with FreePBX 2.11. Today we want to introduce Anveo’s commercial offering which includes residential, business, and free SIP services. Anveo is the hands-down winner of our "Best Free VoIP Resource on the Net" award. We’ll get to why, but there’s so much more…
Let’s begin with a quick summary of their DID offerings:
Anveo has one of the most robust VoIP offerings you’ll find in terms of feature set. Here’s a quick overview:
- SMS Messaging (1¢ per message)
- Fax and Fax-to-Email Integration
- Voicemail to Text
- Salesforce.com CRM
- ZOHO CRM
- G.729 and G.722 (HD Voice)
- Destination-based Outbound CallerID
- Text-to-Speech (41 voices in 17 languages)
- Google Contacts
- Google Analytics
- Web Calling
- Call Recording with Amazon S3 Integration
- Outbound Call Campaigns
- Conference Calls with Recording
- Worldwide DIDs and Number Porting
- Disposable Phone Numbers
- IVR Call Flow Builder
- Anveo Phone API
- Reseller Toolkit
For today, let’s focus on FREE. What a free Anveo account gets you is AMAZING. In addition to another SIP URI with fax support for your server, you also get access to Anveo’s Call Flow Builder to create templates with up to 10 items. None of it costs you a dime! Just sign up for a new account at anveo.com using the Nerd Vittles referral code: 9625450. That gets us a few shekels to keep the lights burning if you ever start spending real money with Anveo.
The shining star of Anveo is its drag-and-drop Call Flow Builder. The icing on the cake is Anveo’s Phone API which we will leave for exploration on another occasion. For Asterisk aficionados, think of Call Flow Builder as a drag-and-drop interface that actually creates Asterisk dialplan code on the fly. While you can create your own, there also is an impressive collection of sample templates from which to choose. Each takes less than 30 seconds to set up, and every template that you create gets its own dedicated SIP URI. For example, one click gets you a Fax-to-Email delivery service using any DID or SIP URI in your account. Another click gets you a Stealth AutoAttendant including automatic fax detection with email fax delivery plus SIP URI call forwarding, all for free. Very impressive! Here’s what it looks like when configured to send fax calls to email and non-fax inbound calls to Lenny. As we noted, this took less than 30 seconds to set up using a default template with any free Anveo account. All that we added was a SIP URI in the SIP Call Control by clicking on the Pencil icon to edit. Then we clicked SAVE in the blue title bar and, presto, Lenny worked!
First things first. Once you’ve signed up for a new account at anveo.com using the Nerd Vittles referral code: 9625450, Anveo will email your credentials. Sign in and activate a new SIP account. In order to register the Anveo SIP trunk with your Asterisk server, you’ll need two pieces of information which you will find under PBX -> Users/sub-accounts -> action.Preferences -> SIP Device Registration: Username and Password.
Once you have your username and password, open up FreePBX and add a new SIP Trunk with your credentials. You can create a custom DID for your trunk by tacking something like /12345 onto the end of the Registration String below.
Next, add an Inbound Route using the Custom DID you created above. Point it to an extension or other resource on your system. Then check to make sure your SIP registration was successful: Reports -> Asterisk Info -> SIP Info.
No exposure of your server to the Internet through your hardware-based firewall is required. However, for those using IPtables WhiteLists or Travelin’ Man for enhanced security, you will need to manually add a SIP entry for sip.anveo.com to /etc/sysconfig/iptables and restart IPtables. The appropriate entry should look like this:
-A INPUT -p udp -m udp -s sip.anveo.com --dport 5010 -j ACCEPT
Here’s what free gets you in addition to 15 megs of online storage for voicemails and faxes:
And Finally… The Magic. You now can receive free inbound SIP URI calls at zero cost from anywhere in the world using SIP/1555ACCOUNTNUMBER@sip.anveo.com:5010. And, if you prefer a more user-friendly SIP URI, take a look at last week’s Nerd Vittles cloaking service offering which is also free. Enjoy!
SIP URI Pricing Clarification. Inbound calls to your account’s SIP URI are always free. That means you can register an Asterisk trunk to your Anveo account, and all incoming SIP calls from your Anveo SIP URI will be free. If you sign up for a free IPKall DID as explained in our previous article, you’ll have a near perfect (and free) VoIP platform for your home or office. Give Lenny a try using our Anveo/IPKall/RentPBX combo:
On the Anveo Value Plans (see the DID screenshot above), be aware that calls using Call Flow templates that rely upon an additional Anveo SIP URI count against your daily bucket of "platform minutes." Free accounts get 40 free minutes a day. Business accounts get 150 minutes a day. Additional calls are billed at 1.5¢ per minute.1
A Word of Caution. For those considering commercial or home use of Anveo for "real calling," be advised that Anveo recently changed their pricing model on calls terminated in the United States.
Some of these calls now are $.005 per minute while others reportedly were as high as $.25 per minute! Pricing has changed every day this week. We would encourage you to find a different termination provider if costs are a consideration. After four attempts to implement a tiered pricing model for U.S. terminations, Anveo rolled back to flat rate pricing on Thursday evening. See the DSL Reports message thread for details.
Deals of the Week. There’s still an amazing deal on the street, but you’d better hurry. A new company called Copy.com is offering 20GB of free cloud storage with no restrictions on file size uploads (which are all too common with other free offers). Copy.com has free sync apps for Windows, Macs, and Linux systems. To take advantage of the offer, just click on our referral link here. We get 5GB of extra storage which will help avoid another PIAF Forum disaster.
Need help with Asterisk? Visit the PBX in a Flash Forum.
We are pleased to once again be able to offer Nerd Vittles’ readers a 20% discount on registration to attend this year’s 10th Anniversary AstriCon in Atlanta. Here’s the Nerd Vittles Discount Code: AC13NERD.
Special Thanks to Our Generous Sponsors
FULL DISCLOSURE: ClearlyIP, Skyetel, Vitelity, DigitalOcean, Vultr, VoIP.ms, 3CX, Sangoma, TelecomsXchange and VitalPBX have provided financial support to Nerd Vittles and our open source projects through advertising, referral revenue, and/or merchandise. As an Amazon Associate and Best Buy Affiliate, we also earn from qualifying purchases. We’ve chosen these providers not the other way around. Our decisions are based upon their corporate reputation and the quality of their offerings and pricing. Our recommendations regarding technology are reached without regard to financial compensation except in situations in which comparable products at comparable pricing are available from multiple sources. In this limited case, we support our sponsors because our sponsors support us.
BOGO Bonaza: Enjoy state-of-the-art VoIP service with a $10 credit and half-price SIP service on up to $500 of Skyetel trunking with free number porting when you fund your Skyetel account. No limits on number of simultaneous calls. Quadruple data center redundancy. $25 monthly minimum spend required. Tutorial and sign up details are here.
The lynchpin of Incredible PBX 2020 and beyond is ClearlyIP components which bring management of FreePBX modules and SIP phone integration to a level never before available with any other Asterisk distribution. And now you can configure and reconfigure your new Incredible PBX phones from the convenience of the Incredible PBX GUI.
VitalPBX is perhaps the fastest-growing PBX offering based upon Asterisk with an installed presence in more than 100 countries worldwide. VitalPBX has generously provided a customized White Label version of Incredible PBX tailored for use with all Incredible PBX and VitalPBX custom applications. Follow this link for a free test drive!
Special Thanks to Vitelity. Vitelity is now Voyant Communications and has halted new registrations for the time being. Our special thanks to Vitelity for their unwavering financial support over many years and to the many Nerd Vittles readers who continue to enjoy the benefits of their service offerings. We will keep everyone posted on further developments.
Some Recent Nerd Vittles Articles of Interest…
- We inquired about the SIP URI pricing with Anveo tech support. Their response is included in this section. The remainder of the article already had been written before contacting Anveo. In responding to the support request (in less than 10 minutes), Anveo generously offered us the use of additional platform minutes and a $5 "slush fund" for future testing and purchases of Call Flow PRO items (4¢ each). While we all may have our price for slanting reviews, we want to assure everyone that Anveo’s generosity in no way affected the contents or views expressed in this article. The FTC and NSA now can resume their naps. [↩]