Asterisk can perform text to speech using the Festival speech synthesis system. The command Festival() provides a convenient interface to Festival. There is a downside to this though. On a slow or busy system this can result in speech that is garbled. For example the Pentium 200 system I run Asterisk on at home drops most of the text that is sent to it and never completes a single word. Using the text2wave utility that comes with festival you can solve this problem. test2wave, as its name suggests, converts text into a wave file. It normally reads text from STDIN and writes wave audio to STDOUT. A few command line options make this process simpler. For example this command will convert a text file into a wave file Asterisk can handle "text2wave -f 8000 -scale 5 -o speech.wav text.txt". The "-scale 5" option increases the volume of the resulting audio and might need to be adjusted on your system. The resulting wave files which can then be placed in the Asterisk sound directory for immediate playback at any time. For added space savings the wave file could be converted to a gsm file using the SoX utility and the command "sox file.wav file.gsm". Another option is to create a script that performs this task at run time, like festival-script.pl. This requires that Festival and the Perl AGI interface be installed. I have modified that script to be more configurable and to cache the wave files it creates. My version is named festival.pl and can also be called via a symbolic link as cache-festival.pl. Both work by creating files based on the MD5 sum of the text to be spoken. If called as festival.pl it creates the files temp_[MD5].txt and temp_[MD5].wav in the directory set at the top of the script. The files will be removed after the wave file is played. Should Asterisk or the script crash before the files are removed they are easy to identify and clean up later. If called as cache-festival.pl it creates the files cache_[MD5].txt and cache_[MD5].wav in the directory set at the top of the script. These files are never removed. The text file is left so that the contents of the wave files can be easily identified later. In either case if the wave file already exists the creation process is skipped and the existing wave file is played. There are three potential problems with this script. The first is if two different text strings have the same MD5 sum. While this is exceptionally rare it is a possibility one should be aware of. The second is if the script is called twice with the same text close enough together that they interfere with each other. This could be solved by adding some sort of locking mechanism. On a seldom used Asterisk system, like mine, this is not a problem. The third is if the caller enters any digits while the wave file is being played. Playback will be stopped and the digits will be lost. If you want to Asterisk to capture the digits you must generate the wave file separately and then play it back within the dialplan. To install the script download it and copy it to the Asterisk AGI directory, normally "/var/lib/asterisk/agi-bin", as festival.pl. Make any necessary customizations to the variables at the top of the file. Create a symbolic link for the caching version by executing "ln -s festival.pl cache-festival.pl" in the AGI directory. Make sure the execute flag is set by executing "chmod +x festival.pl" in the AGI directory. Finally create the directory to store the temporary and cached wave files, this defaults to "/var/lib/asterisk/sounds/festival/". Make sure Asterisk can write to and read from this directory. Some systems run Asterisk as a non-root user for security purposes. Utilizing this script is as simple as adding the following to an extension "AGI(cache-festival.pl,'Welcome to Asterisk')". The script can be found on my SDF Asterisk page.