Home » Technology » Introducing Flite: A Voice Synthesis System That Really Works With Asterisk@Home

The Most Versatile VoIP Provider: FREE PORTING

Introducing Flite: A Voice Synthesis System That Really Works With Asterisk@Home

One of the coolest features of Asterisk@Home 1.5 was the Festival voice synthesis module which allowed the creation of data-driven, text-to-speech telephony applications with minimal programming. Festival could actually "speak" information from a MySQL database to folks calling in with a Plain Old Telephone. When Asterisk® 1.2 and Asterisk@Home 2.x were released, everything changed at least on older systems with slower processors and less than several gigabytes of memory. What had been almost instantaneous voice messages in AAH 1.5 turned into 7-10 second periods of silence between each phrase being read to a caller. The former 10-second weather report sample application turned into a 70-second nailbiter. Painful doesn't begin to describe it. Worthless pretty much sums it up. It was so bad, in fact, that we've kept an Asterisk@Home 1.5 system chugging away just because the voice synthesizer worked so well. Pat West tipped us off last week that there was a "solution" but it didn't quite work with the last few month's of Asterisk@Home 2.x releases. So we put on our facilitator cap and went looking for a complete solution that easily could be integrated into Asterisk@Home ... even by Newbies.

And today our tip of the hat goes to Francois Aucamp from South Africa who has single-handedly reengineered Carnegie Mellon University's open source speech synthesis engine (Flite) to work with Asterisk@Home and restored voice synthesis to its rightful place as an indispensable component in the Asterisk@Home bundle. We'll show you how to install the necessary components in less than 15 minutes, and your Asterisk system will once again be speaking to callers whenever you need it to. This works with Asterisk@Home 2.x versions and Asterisk 1.2x. Earlier versions use the older Asterisk API. See the comments for more details. And, in a future column after our Big Move to Charleston (T minus two weeks and counting), we'll actually build a sample app for everyone to use in rolling your own future text-to-speech implementations. But, first, let's put a system in place that actually works again with Asterisk@Home.

One nice feature of Flite is that you can add other (better) synthesized voices down the road if you really want or need a first-class system. For home or small business use, the voice that comes with Flite is more than adequate. If you use this in business applications, we hope you'll consider making a modest donation to Francois Aucamp. He literally put this together in a couple of days for us. As with so many open source, university-inspired projects, Flite was a terrific idea. It's just that the Carnegie Mellon folks apparently lost interest at about the 90% completed mark, and never quite got things wrapped up for end-user implementation. Francois not only added the missing 10%, but he also single-handedly wrote the Asterisk interface to make it all work seamlessly from within the Asterisk dialplan without reliance upon external AGI scripts. As my old judge friend GBT used to say, "he put it down where the goats could get it." Now, with a single line of code, you can have Asterisk talking away. Here's the dialplan syntax: Flite("Thank you for reading Nerd Vittles. Have a nice day. Goodbye.") It doesn't get much simpler than that.

Downloading and Installing the Components. As mentioned above, there really are two pieces to the puzzle in order to use the Flite speech synthesis engine in your dialplan. First, you need to download and install Flite. And then you need to download and install the Asterisk application module, app_flite. Be advised that the Carnegie Mellon version of Flite will not work in your Asterisk dialplan. You'll need the modified version below which creates Flite as shared objects (aka dynamic libraries) rather than as a static library which would have made it resource hungry, the same problem now rearing its ugly head with Festival. The other advantage of the dynamic library approach is that the Flite library routines now can be called within Asterisk without physically loading Flite as an independent application which also reduces system overhead and load times. For the less technical, text-to-voice synthesis now works again without lengthy periods of silence between phrases and sentences.

To begin the download and installation process, log into your new Asterisk@Home 2.x server as root. Incidentally, this should work on any version up to and including 2.8! Then issue the following commands in order:

cd /root
wget http://nerdvittles.com/aah2/flite-1.3-1.aah.i386.rpm
rpm -ihv flite-1.3-1.aah.i386.rpm
wget http://nerdvittles.com/aah2/app_flite-0.3-1.aah.i386.rpm
rpm -ihv app_flite-0.3-1.aah.i386.rpm
amportal stop
amportal start

Testing Flite. Once you complete the installation process above, load the Asterisk Command Line Interface (CLI) while still logged in as root and be sure that the Flite application is loaded:

asterisk -r
show application flite
quit

You should get a response from Asterisk that looks something like the following:

-= Info about application 'Flite' =-

[Synopsis]
Say text to the user, using Flite

[Description]
Flite(text[|intkeys]): This will invoke the Flite TTS engine,
send a text string, get back the resulting waveform and play it to
the user, allowing any given interrupt keys to immediately terminate
and return.

Modifying the Weather AGI Script to Use Flite. A better test of how well Flite works can be demonstrated by making a slight change in the default AAH Weather Script to use Flite instead of Festival. Here's how. While still logged in as root, make a backup copy of the existing weather script:

cd /var/lib/asterisk/agi-bin
cp festival-weather-script.pl festival-weather-script.pl.bak

Now edit the original script (nano -w festival-weather-script.pl) and move the cursor down to line 23 in the script which looks like this:

my $execf=$t2wp."text2wave $sounddir/say-text-$hash.txt -F 8000 -o $wavefile";

Press Ctrl-K to delete the line, then press the Enter key, move up to the blank line, and insert the following new line:

my $execf=$t2wp."flite $sounddir/say-text-$hash.txt $wavefile";

Save your change to the file: Ctrl-X, y, then press the Enter key. Pick up a phone on your system now and dial *61 for the new weather report using Flite.

Integrating Flite and app_flite Into Your Dialplan. Now that you've seen the Perl way of doing things with Flite, let's do things the easy way. We'll make a quick change to extensions_custom.conf to complete our testing. While still logged in as root, do the following:

cd /etc/asterisk
nano -w extensions_custom.conf

Now use the down cursor to move down to the line which begins exten => *65,1,Answer and make the following changes and additions:

;exten => *65,1,Answer
;exten => *65,2,AGI(festival-script.pl|Your phone number is ${CALLERIDNUM}.)
;exten => *65,3,Hangup

exten => *65,1,Answer
exten => *65,2,Flite("Your phone number is ${CALLERIDNUM}. Have a nice day! Good bye.")
exten => *65,3,Hangup

Save your changes to the file: Ctrl-X, y, then press the Enter key. Restart Asterisk: amportal restart. Load the CLI: asterisk -r. Then pick up a phone on your system and dial *65 for the Flite rendition of your current phone number.

Housekeeping 101. Temporary files in /tmp get cleaned up by Linux housekeeping automatically. Temporary files stored elsewhere don't. The weather script is a good example of how not to write a script on a busy system because it places all of the temporary sound files for each reading of the weather report in /var/lib/asterisk/sounds/tts. So, from time to time, make a mental note to remove all of these files with a command like this:

rm -f /var/lib/asterisk/sounds/tts/*

Where To Go From Here. Finally, it's worth noting that Flite can also read text files. The syntax for your AGI script should look like this: flite -f filename.txt -o filename.wav. That pretty much covers everything you need to know to get started. For those that want to dig deeper, here's a link to the official Carnegie Mellon Flite 1.3 documentation which we've converted to HTML for ease of use. There's also a PDF version available. And the Texinfo version is available for nerd use only. As people add new voices, we'll let you know in the Comments to this post. In the meantime, enjoy!


Hosting Provider Special. Just an FYI that the Nerd Vittles hosting provider, BlueHost, has continued their limited time special on hosting services. For $6.95 a month, you can host up to 6 domains with 15GB of disk storage and 400GB of monthly bandwidth. It doesn't get any better than that, and their hosting services are flawless! We oughta know. We've tried the best of them. If you've never tried a web hosting provider, there's never been a better time. Just use this link, and we'll all be happy.


Nerd Vittles Fan Club Map. Thanks for visiting! We hope you'll take a second and add yourself to our Frappr World Map compliments of Google. In making your entry, you can choose an icon: guy, gal, nerd, or geek. For those that don't know the difference in the last two, here's the best definition we've found: "a nerd is very similar to a geek, but with more RAM and a faster modem." We're always looking for the best BBQ joints on the planet. So, if you know of one, add it to the map while you're visiting as well. The little bug in the map display last week that wiped out everyone in the U.S. and Canada has been fixed. We're all back!

Want More Projects? For a complete catalog of all our previous Asterisk projects, click here. For the most recent articles, click here and just scroll down the page.

Headline News for the Busy Executive and the Lazy Loafer. Get your Headline News the easy way: Planet Asterisk, Planet Gadget, Planet Mac, and Planet Daily. Quick read, no fluff.

Got a PDA or Web-Enabled Smartphone? Check out our new PDAweather.org site and get the latest weather updates and forecasts from the National Weather Service perfectly formatted for quick download and display on your favorite web-enabled PDA, cellphone, or Internet Tablet. And, of course, it's all FREE!


Some Recent Nerd Vittles Articles of Interest...


54 Comments

  1. Same as Wolf, has anyone got this working on 1.4.x or know of a good alternative solution besides Festival?

    I’m getting "loader.c: Module ‘app_flite.so’ did not register itself during load" as an error following the instructions above.

    Thanks.

    [WM: You might try sending the developer a note and then post his response. Yet another reason not to jump too quickly to Asterisk 1.4.]

  2. Is there a way to use loquendo voices with asterisk step-by-step to be disponible to us!

    I’m searching a long time about it and no have sucess yet.

    Please, if someone know the way post here please.

    Thanks a lot!

Comments are closed.