Search:  
Gentoo Wiki

Speechd


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

Contents

Introduction

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.

Installation

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

Usage

Now, to test out this nifty little thing:

echo "I am leet" | festival --tts

Configuration

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

Mbrola

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

HTS

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
wget http://hts.sp.nitech.ac.jp/archives/1.1b/cstr_us_ked_timit_hts.tar.gz
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

Simply,

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

/usr/share/festival/voices/

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.

Speed

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)


Testing

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

Debugging

"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.

restarting

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

Miscellaneous

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,

alsamixer

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:

#!/bin/bash
#
# 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
 echo 'Note: must have ~/.asoundrc configured as show '
 echo 'in the example found in "man arecord"'
 echo
 echo 'usage: t2a [OPTIONS] <textfile>'
 echo
 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
 echo 'Created by Matt McCormick'
 echo '2007 December 8'
}
while [ "$1" != "" ] ; do
 case "$1" in
   -h | --help )
     usage
     exit 0
     ;;
   -g | --ogg )
     OGG_ENC=true
     shift
     ;;
   -m | --mp3 )
     MP3_ENC=true
     shift
     ;;
   -o | --output )
     shift
     OUTFILE="$1"
     shift
     ;;
   * )
     INFILE="$1"
     if [ ! -f "$INFILE" ] ; then
       echo "$INFILE does not exist!"
       exit 1
     fi
     shift
     ;;
   esac
done
[ -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" &
REC_PID=$!
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
   OUTFILE_OGG=${OUTFILE/%wav/ogg}
   oggenc -Q -b 64 "$OUTFILE" -o "$OUTFILE_OGG"
 fi
 if [ "$MP3_ENC" == "true" ] ; then
   OUTFILE_MP3=${OUTFILE/%wav/mp3}
   lame -h -b 64 "$OUTFILE" "$OUTFILE_MP3" &> /dev/null
 fi
 rm "$OUTFILE"
fi

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.

Gmail

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 libgmail.py version: 0.1.3.3 (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("USERNAME-HERE@gmail.com", "PASSWORD-HERE")
 ga.login()
 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
 d=feedparser.parse("https://USERNAME-HERE:PASSWORD-HERE@gmail.google.com/gmail/feed/atom")
 stdout.write(str(len(d['entries'])))

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 gmailcount.py. To make it executable, run chmod 755 gmailcount.py

Now, if we run this at the command line:

 hank@localhost .gmail-notify $ ./gmailcount.py
 1
 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

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

You have to replace PATH/TO with the path to the gmailcount.py 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 "http://www.gentoo-wiki.info/Speechd"

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