Asterisk festival installation

How to install Festival for Asterisk usage

Festival is a text-to-speech application that is callable from within Asterisk. Voice is rather rough, but usable.

The current version of Festival as of this page update is 1.95beta.
Festival can be downloaded from

There are a few ways to Setup Festival with Asterisk:
  • The first one is to use a standard installation of Festival and modify the festival configuration file. (Easiest way)
  • The second one is to patch the source-code to add a special asterisk command.
  • The third one is the use an external perl script to call Festival.

The first method is probably the easiest, as it doesn't involve installing Asterisk perl library or having to recompile Festival, but it's up to you which method you choose.

Method 1 : To Use a standard Festival Installation by only modifying the Festival configuration file

Step 1: Install Festival from the RPM or DEB or source tarball.

Step 2: Find the file festival.scm (should be in /etc, may also be hidden in /usr/share/festival, /usr/lib/festival or /usr/local/lib/festival) and add this command to it:

;; Enable access to localhost (needed by debian users)
(set! server_access_list '("localhost\\.localdomain" "localhost"))

;; set italian voice (comment the following 2 lines to use british_american)
(set! voice_default 'voice_pc_diphone)

;;; Command for Asterisk begin

(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)))

;;; Command for Asterisk end

Place this chunk anywhere within that file, except between other parentheses. ;-)
Then restart the Festival server.

This code should work both with Festival 1.95 and the older 1.4.3, which is still shipped with many Linux distributions.

Debian Sarge - Festival Deb - Festival Access List - You may have to modify your Festival configuration with the following changes in order for this to work using Debian Sarge with the Festival deb package. (contributed by dsfr, aka Chris Hozian):

(set! server_access_list '("localhost\\.localdomain" "localhost"))

;;This will add both localhost.localdomain and localhost to the access list. You should use the init script provided by the Festival deb in order to start Festival correctly to function with Asterisk.

alternative you can make sure that localhost is the first entry on /etc/hosts i.e localhost localhost.localdomain pbx pbx.mydomain

The option usecache=yes caused asterisk to crash on Debian with stock festival packages. Festival log showed an accepted connection, and then an immediate disconnect. After asterisk would sound "very funny" eventually resulting in a system crash. These same symptoms have been reported in the comments below. Changing usecache to no solved this issue. Asterisk had full read write permissions on the cache directory, and was infact writing data there.

Method 2 : Install Festival From Source with patching of the source-code

Using this method, the Festival source code requires a simple patch that is available in the standard /usr/src/asterisk distribution/cvs , See Asterisk CVS.

Downloading Festival

First you need to download the various source tar.gz files for Festival ...

What to download: check the readme files at the site for specific files associated with different countries. Be careful to watch the licensing, not every language file is allowed for commercial use.
For US/English, start with:
  • festival-1.4.3-release.tar.gz
  • festlex_CMU.tar.gz
  • festlex_POSLEX.tar.gz
  • festvox_kallpc16k.tar.gz
  • speech_tools-1.2.3-release.tar.gz

Installation steps:

cd /usr/src ; assumes the downloaded files are located here
tar xvzf speech_tools-1.2.3-release.tar.gz
cd speech_tools

cd ..

tar xvzf festival-1.4.3-release.tar.gz
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 (or wherever the patch is on your sys)

Note: an anonymous user has mentioned the they had to run the above 'patch' command BEFORE cd'n into the festival directory with Festival version 1.95beta.

Note: If compiling using gcc>2.95? you may need to use this patch

Starting Festival

Debian (Sarge) users only have to edit /etc/init.d/festival and comment out
the line which reads "exit 0". Then run "/etc/init.d/festival start" to start the

Note: The festival startup script can be run from the command line but it requires your path statement to include the location of the festival/bin directory, regardless from where you start it. To run festival from a system startup script, please review carefully the /usr/src/festival/bin/festival_server script and modify as needed.

export PATH=$PATH:/usr/src/festival/bin

  • To start festival: /usr/src/festival/bin/festival_server
  • Alternative manual start: /usr/src/festival/bin/festival --server

Note: regardless of where you are in your system when you issue the above command, that startup script will detect your exact location and write a festival_server.log file (and pid files) in that location.
The log file is useful for error messages, therefore pay attention to exactly which directory you happen to be in when you issue the above command. (Or, modify the startup script accordingly.)

Method 3 The Alternative approach using a Perl Script

by Donny Kavanagh (as posted on asterisk-users in Oct 2004)
I�m not sure if this is a bug, or if I�m doing something wrong but I followed the instructions on the wiki for festival, I installed 1.4.3 applied two patches, one for it not compiling on fedora core2 (newer gcc) as well as one patch to make it work with cmd Festival. This seemed to work well however, it only works when called via the zaptel card. When I call via sip, I would see the Festival cmd execute on the cli, but I heard nothing, and the sip call hung up.

I ended up writing an agi myself which I believe will run on an unpatched copy of festival. It also works fine on both versions I have on my system 1.4.3 as well as 1.95beta.

Note that this AGI scsript requires the Asterisk perl library. You do not need to start the Festival server for this to work!

Here's an example snippet for your extensions.conf:

exten => 1234,1,Answer
exten => 1234,2,AGI(|Welcome to the wonderful world of Asterisk! Your phone number is ${CALLERIDNUM}.)
exten => 1234,3,Hangup (to be placed into /var/lib/asterisk/agi-bin/)

  1. !/usr/bin/perl

  1. make a tts dir inside your sounds dir (as specified below)
  2. adjust the t2wp variable to point to your festival bin directory

use Asterisk::AGI;
use File::Basename;
use Digest::MD5 qw(md5_hex);

$AGI = new Asterisk::AGI;

my %input = $AGI->ReadParse();
my ($text)=@ARGV;
my $hash = md5_hex($text);
my $sounddir = "/var/lib/asterisk/sounds/tts";
my $wavefile = "$sounddir/"."tts-$hash.wav";
my $t2wp= "/root/";

unless (-f $wavefile) {
open(fileOUT, ">$sounddir"."/say-text-$hash.txt");
print fileOUT "$text";

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

Thanks to Donny for his script above, but I had to make some changes to make it work on my system with festival v1.4.2 (Fedora Core 2). (Update: redirect text2wave output): (to be placed into /var/lib/asterisk/agi-bin/)

  1. !/usr/bin/perl

  1. make a tts dir inside your sounds dir (as specified below)
  2. adjust the t2wp variable to point to your festival bin directory

use Asterisk::AGI;
use File::Basename;
use Digest::MD5 qw(md5_hex);

$AGI = new Asterisk::AGI;

my %input = $AGI->ReadParse();
my ($text)=@ARGV;
my $hash = md5_hex($text);
my $sounddir = "/var/lib/asterisk/sounds/tts";
my $wavefile = "$sounddir/"."tts-$hash.wav";
my $t2wp= "/usr/bin/";

unless (-f $wavefile) {
open(fileOUT, ">$sounddir"."/say-text-$hash.txt");
print fileOUT "$text";
my $execf=$t2wp."text2wave -F 8000 -o $wavefile $sounddir/say-text-$hash.txt > /dev/null";


Setting Up the Asterisk configuration files

Edit the /etc/asterisk/festival.conf file and ensure the following statements are uncommented (these are used by asterisk):

festivalcommand=(tts_textasterisk "%s" 'file)(quit)\n

The default value for cachedir depends on your distribution. Make sure that the directory exists and is writeable by Asterisk. Since this is only a performance cache, you can use /tmp as long as festival isn't reading back any privleged information.

Edit the extensions.conf file and include the following within your dial plan (for testing purposes):
; testing festival (text-to-speech app)
exten => 555,1,Answer
exten => 555,2,Festival(mary had a little lamb) ; do NOT use quotes around the string! if you use commas, you will have to escape them with a "\" (backslash).
exten => 555,3,Hangup

  • Restart asterisk
Note: asterisk has to be started "after" festival.


  • When a call is made to extension 555 (assuming you followed the above completely) and no voice is heard, check the contents of the festival_server.log file (wherever it is located on your system).
If you see a message such as:
client(1) : rejected from not in access list
then edit the festival/bin/festival_server startup script to include that FQDM in the line with "localhost.*".

  • If the festival_server.log contains an entry like:
client(1) : accepted from
after a place a call to extension 555, then asterisk is making the call to festival.

  • From the asterisk CLI interface, a properly executed and functional call to festival will look like this:

  -- Executing Answer("SIP/3000-46a1", "") in new stack
  -- Executing Festival("SIP/3000-46a1", "mary had a litte lamb") in new stack
  == Parsing '/etc/asterisk/festival.conf': Found
  WARNING[1209269552]: File app_festival.c, Line 304 (festival_exec): Text passed to  festival server : mary had a little lamb
  WARNING[1209269552]: File app_festival.c, Line 381 (festival_exec): Passing text to  festival...
  WARNING[1209269552]: File app_festival.c, Line 400 (festival_exec): Passing data to channel...
  WARNING[1209269552]: File app_festival.c, Line 410 (festival_exec): Festival WV command
  WARNING[1209269552]: File rtp.c, Line 374 (ast_rtp_read): RTP Read error: Resource temporarily unavailable
  WARNING[1209269552]: File app_festival.c, Line 202 (send_waveform_to_channel): Last frame
    -- Executing Hangup("SIP/3000-46a1", "") in new stack

For German voices in Festival see

If you use German voices (The IMS Uni-Stuttgart version) and want to use the PHPAGI text2wav call, make sure the first line in $FESTIVAL_ROOT/lib/ims_german_opensource.scm is commented out like this:

/*(format t "German Festival 1.2-os (1.4.1)
: Release August 2000\n")*/

If you don't do this, the generated WAV files will contain this header before the RIFF tag, rendering them useless.

For a Dutch installation manual see

See also

Created by: oej, Last modification: Wed 02 of May, 2012 (07:55 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+