DIY Telephony With Asterisk, Part 3

Learn about configuring some of Asterisk's features, including hold music and conferencing.

By Carla Schroder | Posted Dec 6, 2005
Print ArticleEmail Article
  • Share on Facebook
  • Share on Twitter
  • Share on LinkedIn

Part 1 gave an overview of what you can do with Asterisk; part 2 showed the basics of using Asterisk@Home, which is a nice implementation of Asterisk that adds an excellent HTML-based management interface. Today we'll dig into setting up custom hold music, conferencing, and skim lightly over faxing and incorporating telephony into your home automation system.

Music on Hold
Setting up music on hold is your chance to express yourself, and to manage incoming calls. For example, suppose you're running a commercial tech-support call center. Chances are you really don't want to be bothered by customers calling in, so you have an arsenal of finely-tuned strategies to discourage them, like convoluted navigation menus, and long hold times. You can maximize your discouragement factors by using repellent hold music. Rap is a sure-fire repellent, unless your customers belong to a demographic that likes it. In that case, try some seriously hardcore operas, like Wagner, that even classical music aficionados have a hard time with.

The first thing to do is make sure you have Asterisk version 1.2 or newer. (Asterisk@Home version 1.5 has Asterisk version 1.2). Then you can ignore all the conflicting howtos about using mpg123, which is non-free and apparently non-maintained since January 2005, because Asterisk 1.2 finally has its own built-in music player.

So, happy Asterisk admin, you can now go directly to configuring your hold music. The one tweak you should make is to convert your music files to RAW mode, which is easily done with the usual Linux utilities. Using RAW streams rather than mp3 places less of a load on the server, since it doesn't need to continually decode the sound files. As far as I know, there are not any Linux tools to directly convert mp3s to to RAW, so here is one way to do it with lame and sox:

$ lame --decode soundfile1.mp3 soundfile1.wav
$ sox -V soundfile1.wav -r 8000 -c 1 -w soundfile1.raw

You don't need awesome fidelity and full stereo surround for telephones, so this creates an 8kHz sampling rate file in beautiful one-channel (mono) sound. To convert a whole clutch o' files, stick them all in the same directory and do this:

$ for i in *.mp3; do lame --decode $i `basename $i .mp3`.wav; done
$ for i in *.wav; do echo $i; sox $i ${i%%.wav}.raw ; echo ${i%%.wav}.raw; done

Next, configure Asterisk (version 1.2 and up only, don't use older versions) to use the RAW streaming format. Edit /etc/asterisk/musiconhold.conf :

; Music on Hold -- Sample Configuration

[default]
mode=files
directory=/var/lib/asterisk/mohmp3

Now take all your freshly-minted RAW files and put them in the /var/lib/asterisk/mohmp3 directory. Asterisk will play them in sequence.

To test your music on hold, create a test extension. This example uses a high-numbered extension to avoid conflict with real extensions. In /etc/asterisk/extensions.conf, add these lines:

exten => 9000,1,Answer
exten => 9000,2,SetMusicOnHold(default)
exten => 9000,3,WaitMusicOnHold(20)
exten => 9000,4,Hangup

This tells Asterisk to answer this extension with music from the "Default" music class for 20 seconds, then hang up.

Finally, restart Asterisk:

# asterisk -rx "restart gracefully"

Now call extension 9000 and listen to your customized tunes.

If you're using Asterisk@Home, use the Asterisk Management Portal (AMP) to set up the test extension, just like we did in part 2.

Conferencing
This is one of Asterisk's strongest features- you can easily set up a telephone conference, which traditionally on PBXes is difficult and painful. Using conferencing, or "meet me" conferencing as the telephony wonks say, inside the LAN is as easy as falling asleep. Asterisk@Home makes it especially easy, by having a default conference room already set up for each user, 8000 + the extension. For example, extension 200 has conference 8200.

Then (for Asterisk@Home only) set a numerical password for the conference by typing passwd-meetme from your Linux command line. Then conference participants only have to dial 8200 and enter the password to join. People can come and go, just as if they were wandering in and out of a physical conference room. There are, thankfully, no announcements of these entrances and exits.

Look for the "WebMeetme" page in AMP to manage the conference.

This is a sample /etc/asterisk/meetme.conf configuration for plain-vanilla Asterisk:

[rooms]
;
; Usage is conf => confno,pincode,adminpin
;
conf => 8000,1234
conf => 8001,4567
conf => 8002,7890

What if you want to enable users from outside your LAN to enter the conference? No problem, if you are set up with VoIP as we learned in part 2. All they need to do is call your office in the normal manner, then enter the conference extension and password.

Word of warning: don't hit the Hold button when you are connected to a conference, or conference attendees will be treated to your hold music.

Faxing
The easiest way to send and receive faxes is still to use a plain old fax machine on an analog line. Only spammers find it's worth the hassle of using any kind of computerized faxing, especially fax-over-IP. If you want to give it a try, see this page at voip-info.org.

Hooking Into Your Home Automation
Asterisk@Home comes ready to interface with any existing home automation system that uses the xPL protocol. This is the stuff than enables creative projects like Internet-controlled Christmas lights. Visit the Linux Home Automation page for more information on this subject than you even dreamed existed.

Migrating
As long as you stick to VoIP telephony, you shouldn't have too much trouble making it all work. The tricky bits are when you try to connect your Asterisk server to your PSTN (define), or regular telephone service. That's when you have to spend lots of money on interface hardware. Because Asterisk can happily use both, you can convert to VoIP service in increments, rather than having to do a big heroic all-at-once changeover.

Resources

Comment and Contribute
(Maximum characters: 1200). You have
characters left.
Get the Latest Scoop with Enterprise Networking Planet Newsletter