The first 90 percent of the task takes 90 percent of the time, and the last 10 percent of the task takes the other 90 percent of the time.
The toughest part of writing this book was not finding things to write about, but rather deciding what we would not be able to write about. Now that we’ve covered the basics, you are ready to be told the truth: we have not taught you anywhere near all that there is to know about Asterisk.
Now please understand, this is not because we didn’t want to give you our very best; it’s merely because Asterisk is, well, limitless (or so we believe).
In this chapter, we want to give you a taste of some of the wonders Asterisk holds in store for you. Nearly every section in this chapter could become a book in itself (and they will become books, if Asterisk succeeds in the way we think it is going to).
Festival is a popular open source text-to-speech engine. The basic premise of using Festival with Asterisk is that your dialplan can pass a body of text to Festival, which will then “speak” the text to the caller. Probably the most obvious use for Festival would be to have it read your email to you when you are on the road.[147]
There are currently two ways to use Festival with Asterisk. The first (and easiest) method—without having to patch and recompile Festival—is to add the following text to Festival’s configuration file (festival.scm, usually located in /etc/ or /usr/share/festival/):
(define (tts_textasterisk string mode) "(tts_textasterisk STRING MODE) Apply tts to STRING. This function is specifically designed for use in server mode so a single function call may synthesize the string. This function name may be added to the server safe functions." (let ((wholeutt (utt.synth (eval (list 'Utterance 'Text string))))) (utt.wave.resample wholeutt 8000) (utt.wave.rescale wholeutt 5) (utt.send.wave.client wholeutt)))
You may place this text anywhere in the file, as long as it is not between any other parentheses.
The second (and more traditional) way is to compile Festival with an Asterisk-specific patch (located in the contrib/ directory of the Asterisk source).
Information on both of these methods is contained in the README.festival file, located in the contrib/ directory of the Asterisk source.
For either method, you’ll need to modify the Festival access list in the festival.scm file. Simply search for the word “localhost” and replace it with the fully qualified domain name of your server.
Both of these methods set up Festival to be able to correctly
communicate with Asterisk. After setting up Festival, you should start
the Festival server. You can then call the Festival()
application from within your dialplan.
The Asterisk configuration file that deals with Festival is aptly called festival.conf. Inside this file, you specify the hostname and port of your Festival server, as well some settings for the caching of Festival speech. For most installations (if you’re going to run Festival on your Asterisk server), the defaults will work just fine.
To start the Festival server for debugging purposes, simply run festival
with the --server
argument, like this:
[root@asterisk ~]# festival --server
Once you’re sure that the Festival server is running and not rejecting your connections, you can start Festival by typing:
[root@asterisk ~]# festival_server 2>&1 >/dev/null &
Now that Festival is configured and the Festival server is started, let’s call it from within a simple dialplan:
exten => 123,1,Answer() exten => 123,2,Festival(Asterisk and Festival are working together)
Tip
You should always call the Answer()
application before calling Festival()
, to ensure that a channel
is established.
As Asterisk connects to Festival, you should see output like this in the terminal where you started the Festival server:
[root@asterisk ~]# festival --server
server Sun May 1 18:38:51 2005 : Festival server started on port 1314
client(1) Sun May 1 18:39:20 2005 : accepted from asterisk.localdomain
client(1) Sun May 1 18:39:21 2005 : disconnected
If you see output like the following, it means you didn’t add the host to the access list in festival.scm:
[root@asterisk ~]# festival --server
server Sun May 1 18:30:52 2005 : Festival server started on port 1314
client(1) Sun May 1 18:32:32 2005 : rejected from asterisk.localdomain not
in access list
[147] Probably the coolest use of Festival is in Simon Ditner’s ZoIP, a port of the famous Zork game to a fully speech-enabled engine running on Asterisk (ZoIP also uses Sphinx, which we will not be covering in this book). We’re going to have to come up with a new kind of name for this sort of thing. It’s not a video game, since there is no screen, so do we need to call these audio games? Regardless, check it out at http://www.zoip.org.
Get Asterisk: The Future of Telephony, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.