Hack92.Teach Your Asterisk Box to Speak

Hack 92. Teach Your Asterisk Box to Speak

Sometimes you just don't want to get off the couch and walk to the caller ID display. Your Linux server understands and wants to help.

My first exposure to synthesized speech was on a Commodore 64; the speech demo took an eternity to load off a floppy diskette, and the speech sounded like an English as a Second Language student was speaking it directly into a pillow. Today, with DSP and decades of additional speech programming research in the bag, synthetic speech is much more passable, and folks are constantly coming up with novel uses for it.

In Detroit, I have a buddy whose Linux server used to announce logfile entries and tell him when the doors around his house were opened and closed. While this speaking server was mysteriously silenced right around the time he got married, I still love his hack. Adapting speech capability around Asterisk is a logical use for two of my favorite pieces of open source software: Asterisk and Festival, the University of Edinburgh's speech synthesizer. With a little bit of dial-plan configuration, your Linux Asterisk server will be announcing your incoming calls in no time (and announcing a whole bunch of other stuff, if you want).

Mac OS X users will find that Festival is similar in some ways to the Say command on OS X, though Festival provides much more functionality to Asterisk than Say does. For example, you cannot use Say to speak to callers, as you can with Festival.

First, you'll need a sound card installed and working in your Linux box. Most commercial distributions of Linux (Red Hat, Debian, etc.) make sound card configuration a straightforward affair. Next, get your hands on the Festival source code at http://www.cstr.ed.ac.uk/projects/festival/download.html. Find a link to download it, and save it from your browser, or use wget to grab it (and its supporting Speech Tools libraries):

 # wget  http://www.cstr.ed.ac.uk/downloads/festival/1.95/festival-1.95-beta. tar.gz  # wget  http://www.cstr.ed.ac.uk/downloads/festival/1.95/speech_tools- 1.2.95beta.tar.gz  # wget  http://www.cstr.ed.ac.uk/downloads/festival/1.95/festlex_CMU.tar.gz  # wget  http://www.cstr.ed.ac.uk/downloads/festival/1.95/festlex_POSLEX.tar.gz  # wget  http://www.cstr.ed.ac.uk/downloads/festival/1.95/festvox_kallpc_16k. tar.gz  

Once you've downloaded Festival, you should unpack, compile, and install it with these commands:

 # tar xvzf speech_tools-1.2.95-beta.tar.gz # tar xvzf festival-1.95-beta.tar.gz # cd speech_tools # ./configure # make; make install # tar xvzf festlex_CMU.tar.gz # tar xvzf festlex_POSLEX.tar.gz # tar xvzf festvox_kallpc16k.tar.gz # cd festival # patch -p1 </usr/src/asterisk/contrib/festival-1.4.3-diff # cd ../festival # ./configure # make; make install 

The make; make install commands take the longestupward of five minutes each on my trusty old garage-built Pentium III machine. Of course, if you've already compiled and installed Asterisk [Hack #41], installing Festival will seem fast.

While you're waiting for the compile to complete, let me give you a quick Festival crash course. Festival has an interactive mode, where you can issue speech commands, as well as an "execute and exit" mode, where you can pass instructions to it from the Unix shell. Simply executing festival in a shell will put you in interactive mode, where you can interact with the speech synthesizer:

 festival> (SayText  "Hello world .") festival> (tts  "text-file.txt ") 

The SayText command simply causes Festival to speak the quoted text using your PC's sound card, and the tts command speaks the contents of the text file indicated. By the way, if you'd like to quit interactive mode and return to the shell, hit Ctrl-D.

When you execute Festival from the command line, you've got some cool functionality at your disposal. Executing with --pipe causes Festival to take commands from standard input. Recent builds of Festival also include the text2wave application, which generates Wave-format sound files from text input.

7.6.1. The Hack

For Asterisk to support text-to-speech via Festival, you have two approaches. The first is to use Asterisk's built-in Festival( ) command, which is a standard part of the Asterisk distribution, when patched for Festival as described earlier. To get to this command, you might need to recompile Asterisk after the Festival patch has been applied. The Festival installation instructions provided earlier show how to apply this patch. In the Asterisk extensions.conf file, the Festival command simplifies the playing of synthetic speech for callers:

 exten => s,1,Answer exten => s,2,Festival('Hello caller. My name is Mr. Synthetic.') 

To greet a caller by name, use Asterisk's built-in caller ID variables:

 exten => s,1,Answer exten => s,2,Festival('Hello ${CALLERIDNAME}. My name is Mr. Synthetic.') 

The Festival command allows you to send speech to callers, but not to the sound card. To do that, you'll need to pump some output from Asterisk to the Festival application at the appropriate time in the dial plan. Using Asterisk's System() command, you can trigger all kinds of activity in the Unix shell from within Asteriskincluding, of course, Festival activity. Take a look at this Festival shell command, which simply speaks the quoted text through the PC's sound card:

 # echo "Hello world" | festival --tts 

This causes the text output of the echo command to flow to Festival's standard input. It is then spoken using the audio output of the sound card. Commands like this really give Asterisk some cool speech abilities. Say you wanted to have your Asterisk server announce the caller ID of each incoming call:

 exten => s,1,System(echo "You are receiving a call from {$CALLERIDNAME}" \  | festival -tts) exten => s,2,Dial({$DEFAULTPHONES}) 

7.6.2. Mac the Hack

If your Asterisk server runs on a Macintosh [Hack #93], you can do the caller ID announcements using the Mac Unix command, Say, instead of Festival. One of the coolest things about the Mac's built-in speech synthesis is its selection of different voice styles; males, females, whispers, and hysterical laughing all make Mac speech a lot of fun. In fact, you can use the Say command's -v option to use those different voices, depending on the variables of the call. Here, different voices are used depending on which phone is being dialed:

 exten => 10,1,System(say v Agnes Kelly, you have an incoming call.) exten => 10,2,Dial({$KELLYSPHONE}) exten => 20,1,System(say v Hysterical Jake, you have an incoming call.) exten => 20,2,Dial({$TEDSPHONE}) 

The preceding sample uses the Agnes voice to announce Kelly's calls and the Hysterical voice to announce Jake's calls.

VoIP Hacks
VoIP Hacks: Tips & Tools for Internet Telephony
ISBN: 0596101333
EAN: 2147483647
Year: 2005
Pages: 156

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net