Using Festival For IVR Menus

If you can't find suitable IVR sounds and don't want to record your own IVR messages, or you just like the thought of Clango (www.dieselsweeties.com) answering your phone, you might want to take a look at Festival. Alternately, if you want to actually put the I in IVR, by generating voice responses on the fly, Festival may also be for you. You can install it on CentOS with:

     su
     yum install festival

Once you have Festival installed, you can create IVR messages by simply typing the text of each message into a text file. Note that the Festival command that converts text into sound ignores case but respects punctuation. If you have long text files to convert, punctuation becomes important as you don't want what sounds like audible run-on speech.

The Festival command that converts text files to speech is called text2wave. Generating speach is as simple as typing the text2wave command along with the input, text file name, and the output, sound file name. But, beware that, by default, text2wave creates sound files with bit rates that Asterisk does not tolerate. You need to declare the bit rate as "8000" via the "-F" switch. Consequently, the syntax for the sound file generation is:

     text2wave -F 8000 -o ivr-menu-1.wav ivr-menu-1.txt

Asterisk will convert the generated ".wav" file using whatever codec a caller employs. If you're into pre-generating all of the available codecs, text2wave has a "-otype" switch. The syntax is:

     text2wave -F 8000 -o ivr-menu-1.wav -otype alaw ivr-menu-1.txt

As for generating speech on the fly, Asterisk has a direct link to Festival, through the Festival application. You can include a call to Festival to generate a speech clip, in the definition of an extension, and Asterisk will play the clip to the user. This requires that the Festival service be running before Asterisk is started.

Another way to generate speech on the fly is to call text2wave directly via the System application. This skips the need for the Festival service but requires an external, temporary file to pass the generated speech clip to Asterisk. You'd do it something like this:

     exten => s,1,System(echo 'Hello' | text2wave -F 8000 -o /tmp/festival.wav)
     exten => s,n,Background(/tmp/festival);

Using this scheme, we can also pass the argument to use a different voice:

     exten => s,1,System(echo 'Hello' | text2wave -F 8000 -o /tmp/festival.wav \
                                                  -eval "(voice_us1_mbrola)")