Gentoo Wiki


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc



Want something nifty? Try this. This article covers the installation and usage of speechd and festival. This software allows you to echo text into a special device node in /dev to make your computer say things.


This first step will install the necessary system daemons that allow your PC to speak. As always, you need to be root to install software, so:

emerge speechd festival
/etc/init.d/speechd start

Some folks out there may want speechd to auto-start at boot so they can echo fortunes and such at boot time. If this applies to you then do the following:

rc-update add speechd default

If you want to use /dev/speech as a regular user, don't forget to add your user to the group 'speech':

gpasswd -a <user> speech


Now, to test out this nifty little thing:

echo "I am leet" | festival --tts


For a little background, the above is a really disgusting-sounding male voice. Anyone who wants their girlfriend speaking from Gentoo should perform the following steps:

Installing Extra Voices


Festival will need to be recompiled with the mbrola USE flag enabled in order for these voices to be recognized.


This is a male, more natural-sounding voice. It shows a segmentation fault error message, but plays anyway.

Code: Installs HTS voice
mkdir /root/speech
cd /root/speech
tar zxvf cstr_us_ked_timit_hts.tar.gz
mkdir -p /usr/share/festival/voices/us
mv lib/voices/us/cstr_us_ked_timit_hts /usr/share/festival/voices/us/

If you see the this sort of error (after the giant segmentation fault message) when you try to use the voice:

Cannot open file /tmp/est_13432_00000/utt.wav as tokenstream 
Wave load: can't open file "/tmp/est_13432_00000/utt.wav" 
Cannot load wavefile: /tmp/est_13432_00000/utt.wav


emerge sox
and try again.

Other "CMU" and "CSTR" HTS voices work also, but /etc/festival/siteinit.scm may need to be created, and contain something like the following:

File: /etc/festival/siteinit.scm
; Set voice.  Needs to be done here, to fix an error message:
; "SIOD ERROR: unbound variable : f2b_f0_lr_start"
(set! voice_default 'voice_cmu_us_slt_arctic_hts)

; Slow the HTS speech down.
(set! hts_duration_stretch 0.1)

; Set volume.
(set! default_after_synth_hooks
    (list (lambda (utt) (utt.wave.rescale utt 2.0 t))))

Choosing a Different Voice

Your Voice Options

You can find the voices available at


A nice one is cmu_us_slt_arctic_hts.

User Change

Each user can also override these settings via ~/.festivalrc.

File: ~/.festivalrc

To increase the speech volume:

(set! default_after_synth_hooks
 (list (lambda (utt) (utt.wave.rescale utt 1.6 t))))

To set the default voice (doesn't work with festival-1.4.3-r3):

(set! voice_default 'voice_us1_mbrola)

Global change

Or you can put

 (set! voice_default 'voice_us1_mbrola)

in /etc/festival/siteinit.scm to affect all users.


File: ~/.festivalrc
; multiplicative factors for voices

; To slow down the HTS voices slightly:
(set! hts_duration_stretch 0.1)

; Slow the standard voices down
(Parameter.set 'Duration_Stretch 2.5)

Festival Server

The port and access list for festival is specified in /etc/festival/server.scm. You may need to explicitly add your local host's name to the list.

Use alsa output method

To use festival while playing music, i found a way to let it use alsa. Add this to ~/.festivalrc:

File: ~/.festivalrc
(Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")
(Parameter.set 'Audio_Method 'Audio_Command)


Now to test this hot broad out:

echo "I'm this annoying little blonde speaking from a Gentoo Box" | festival --tts

Restart festival to apply the newly-selected voice and test it:

/etc/init.d/festival restart
echo "Hello World" > /dev/speech


"not in access list"

If /var/log/festival.log contains "not in access list", then add your custom hostname to the access list in /etc/festival/server.scm and restart the servers:

Code: Restarts festival and speechd
/etc/init.d/festival restart

"ESD: error writing - Bad file descriptor"

See the section on adding alsa playback.


If the speech gets into a mess, this script will stop and restart the servers:

Code: Kills and restarts speech servers
/etc/init.d/speechd stop /etc/init.d/festival stop killall festival /etc/init.d/speechd zap /etc/init.d/festival zap killall -9 festival /etc/init.d/speechd start

Festival FAQ


Convert text file to audio file

There is a script located at /usr/share/doc/festival-1.95_beta-r4/examples/text2wave that can convert text files to .wav audio files.

However, this script may not work if we use a non-standard voice and ALSA. First we need to edited the following two files like so:

File: ~/.asoundrc
pcm.copy {
 type plug
   slave {
     pcm hw
  route_policy copy
File: ~/.festivalrc
(Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")
(Parameter.set 'Audio_Method 'Audio_Command)
(Parameter.set 'Audio_Required_Rate 44100)
(set! voice_default 'voice_cmu_us_slt_arctic_hts)

Next, enter the mixer,


Press F4 to get into the Capture settings. Make sure the Capture volume is up with the up/down arrow keys. Start with something around 50%. Adjust down if there is distortion and up it is too soft. Select Mix Mono with the space bar as the capture input.

Now we can use the following script to translate plain text to audio files:

# t2a
function usage
 echo "convert a text file to audio with festival and alsa"
 echo "optionally encode to .mp3 with lame or .ogg with oggenc"
 echo 'Note: must have ~/.asoundrc configured as show '
 echo 'in the example found in "man arecord"'
 echo 'usage: t2a [OPTIONS] <textfile>'
 echo 'Options:'
 echo '  -h | --help               this help message'
 echo '  -g | --ogg                encode to OGG Vorbis'
 echo '  -m | --mp3                encode to MP3'
 echo '  -o | --output <outfile>   change the output filename'
 echo '                            defaults to `basename <textfile>`.[wav,ogg,mp3]'
 echo 'Created by Matt McCormick'
 echo '2007 December 8'
while [ "$1" != "" ] ; do
 case "$1" in
   -h | --help )
     exit 0
   -g | --ogg )
   -m | --mp3 )
   -o | --output )
   * )
     if [ ! -f "$INFILE" ] ; then
       echo "$INFILE does not exist!"
       exit 1
[ -z "${OUTFILE:-}" ] && OUTFILE=${INFILE/%txt/wav}
[ "${OUTFILE%wav}" == "$OUTFILE" ] && OUTFILE="${OUTFILE}.wav"
arecord -q -t wav -c 1 -f s16 -r 44100 -D copy "$OUTFILE" &
trap "kill $REC_PID" ERR
festival --tts "$INFILE" &> /dev/null
kill $REC_PID
if [ "$OGG_ENC" == "true" ] || [ "$MP3_ENC" == "true" ] ; then
 if [ "$OGG_ENC" == "true" ] ; then
   oggenc -Q -b 64 "$OUTFILE" -o "$OUTFILE_OGG"
 if [ "$MP3_ENC" == "true" ] ; then
   lame -h -b 64 "$OUTFILE" "$OUTFILE_MP3" &> /dev/null
 rm "$OUTFILE"

This method will be slower than the text2wave script, since is requires output of the speech in real time. But, it works :-)

Clipboard Contents

Added by RFC_1149 @ FreeNode

I've written a small bash script to speak the contents of the clipboard, pastespeak.


Added by Erik Gregg, 1/3/05, Corrected by Erdem 15/01/06:

The above can be used to integrate things like GMail speech notification on login. I successfully implemented this on my system by doing to following.

We only need version: (XX January 2006), and this is the only component of it we need. Libgmail is masked so we need to unmask it by adding it to /etc/portage/package.keywords

net-libs/libgmail ~x86

And then we install libgmail as usual:

emerge libgmail

Now, we can write a script to check our gmail account:

 #!/usr/bin/env python
 import libgmail
 ga = libgmail.GmailAccount("", "PASSWORD-HERE")
 print ga.getUnreadMsgCount()

If the above script doesn't work here's another one that uses feedparser rather than libgmail.(emerge feedparser if you haven't done it already)

 #!/usr/bin/env python
 import feedparser
 from sys import stdout

You can copy/paste this script if you like - replacing the USERNAME-HERE and PASSWORD-HERE with your information of course. I have this file on my personal computer, and am not concerned with someone else stealing my password, but think before you save your password in cleartext in a file. If you are OK with this, save this file as To make it executable, run chmod 755

Now, if we run this at the command line:

 hank@localhost .gmail-notify $ ./
 hank@localhost .gmail-notify $

As you can see, we get a single integer output corresponding to the number of new messages in the inbox of our account.

So, since we can do this, we can write a helper script to implement speech. I called mine /bin/loginmessage

 # GMail Notifier Login Script
 # Written by Erik Gregg, corrected by ICC Trancelis
 # 01/03/05
 # Notifies the user of GMail
 # Needs festival, (Written by Erik Gregg), and
 # Run Script that outputs number of Threads in Inbox, Store in $number.
 # Case that there is 1 new message.
 if [ $number = 1 ]
   echo "There is $number new message in your G Mail." | festival --tts
 # Case that there are many new messages.
 if [ $number -gt 1 ]
   echo "There are $number new messages in your G Mail." | festival --tts
 # Case that there are no new messages.
 if [ $number = 0 ]
   echo "You have no new G mail." | festival --tts

You have to replace PATH/TO with the path to the file you just created. Now, chmod 755 the new file, and run it. If everything is set up right, you should hear festival telling you the amount of new messages in your inbox. Good Luck!

Retrieved from ""

Last modified: Fri, 05 Sep 2008 02:51:00 +0000 Hits: 45,759