VoIPowering Your Office with Asterisk: SOHO VoIP, Part 5
Today we're going to learn how to play Asterisk .gsm files with a special audio player, and how to construct a sturdy, reliable digital receptionist to answer and route all incoming calls. As usual, let us establish our terminology first. Automated attendant, digital receptionist, and Interactive Voice Response (IVR) are all pretty much the same thing; the old "press 1 to record a compliment, press the circumference of a circle with a radius of eleventy-eight yards, in millimeters, to record a complaint" dance we all know and love. Interactive Voice Response covers all the bases, so that's the term I'll use.
But first, here's the answer to the burning question "How in the heck can I play soundfiles in GSM format the easy way?"
Playing Asterisk sounds
Asterisk's spoken-word audio files are recorded in the GSM format, which most audio players don't support. Fortunately you can download a nice GSM player, Zgsmplay. The nice thing about Zgsmplay is it doesn't require X Windows. Most Linux admins don't install X Windows on servers. It has an NCURSES interface, so you still get a graphical interface in the console. Chances are you'll have to build it from sources, which is almost as easy as falling over. You'll also need ncurses and ncurses-devel installed. (On Debian systems look for libncurses5, ncurses-base and ncurses-bin.) Change to the directory where you want to download it, then follow these steps to download and install it:
# wget http://www.ibiblio.org/pub/Linux/apps/sound/players/zgsmplay-1.4.tar.gz
# tar zxvf zgsmplay-1.4.tar.gz
# cd zgsmplay-1.4
# make install
If you run into installation problems check out the README and INSTALL files in the source tree.
man zgsmplay gives complete instructions on playing GSM files, or run zgsmplay -h. It has a built-in file browser that looks like this:
# zgsmplay /var/lib/asterisk/sounds/
Directory of /var/lib/asterisk/sounds
activated.gsm are-you-still-there2 away-naughty-girl.gs
dictate added-to.gsm arizona.gsm
call-fwd-no-ans.gsm digits added.gsm
Navigate with the arrow keys, and hit Enter to play a file, which looks like Figure 1.
Take the time to explore the Asterisk soundfiles because there are a lot of funny ones. Look for filenames with weasels, chickens, and monkeys. Hit Esc to close zgsmplay.
Interactive Voice Response
You might refer to the previous installments in this series to follow along (see Resources, below), as we are continuing to build on our existing configurations.
Interactive menus can get as elaborately nested as you like, and now we see why Asterisk calls them "contexts"because the key presses are contextual. You can use the same old "press 1, press 2" key presses over and over, as long as they are in different contexts.
At long last Alrac can give up her receptionist duties. She wasn't a very good one because she had no ability to transfer calls. But our existing [default] context routed all calls to her anyway:
exten => s,1,Dial(SIP/250,30)
exten => s,n,Voicemail(250)
exten => s,n,Hangup
So let's fix this and make a brand-new [default] context. By the way, there's nothing magical about the [default] context name. You might want to name it something descriptive, like [incoming]. Just remember to change all the references to it if you do. This example sets up a simple menu to route calls to Alrac, Stan, or Ollie. You'll need to record two new soundfiles to give callers instructions. (See Part 4 to learn how to record your own voicemail prompts.)
It's a good idea to store your custom soundfiles in a separate directory, like /var/lib/asterisk/sounds/local/. This example uses these custom soundfiles:
foo-main-greeting.gsm, "Thank you for calling Foo Industries. Please press 1 to speak to Alrac, press 2 for Stan, or press 3 for Ollie."
r-invalid-option.gsm, "I'm sorry, that is not a valid option. Please listen to the available options."
exten => s,1,Answer
exten => s,2,DigitTimeout,5
exten => s,3,ResponseTime,10
exten => s,4 Background(local/foo-main-greeting)
;send the caller back to the beginning
;if they enter an invalid option
exten => i,1,Playback(local/r-invalid-option)
exten => i,2,Goto(s,2)
;hangup if the timeouts are exceeded
exten => t,1,Hangup
What the heck is going on here? A whole lot in a few lines. DigitTimeout and ResponseTime set time limits for how long Asterisk will wait between key presses and total response time.
The Background command plays a soundfile, then stops playing the soundfile when it is interrupted by a key press from the caller.
The "t," or timeout extension is a special extension that tells Asterisk what to do when timeouts are exceeded.
The "i," or invalid extension handles incorrect input from callers.
In our next installment we'll set up a better custom soundfile recorder, and learn more ways to use Interactive Voice Response.
VoIPowering Your Office with Asterisk: SOHO VoIP; terminology explained
VoIPowering Your Office with Asterisk: SOHO VoIP part 2; connecting legacy PSTN lines to Asterisk, inbound calling
VoIPowering Your Office with Asterisk: SOHO VoIP, Part 3; setting up outbound calls safely
VoIPowering Your Office with Asterisk: SOHO VoIP, Part 4; setting up voicemail