...making Linux just a little more fun!

<-- prev | next -->

Shelling your Linux box with Festival

By Maxin B. John

Do you want a bit more "humanized" version of your computer? If you are ready for this adventure, all that you need is a computer with Linux operating system and a little bit of time to download and install the required programs. Now let us have some fun with bash and Festival TTS (Text To Speech) software.

My setup

I am using a Pentium 4 (1.6 GHz) machine with 128 MB of RAM and Redhat Linux 9 installed. The system has an onboard soundcard, which is quite sufficient for this venture. If you want some privacy with your system, I would also recommend a pair of headphones.

Software installation

The software that we are going to use is the Festival speech synthesis system — a Text to Speech program developed by the University of Edinburgh. The power of shell scripting can harness the full potential of the Festival program. Festival comes bundled with Redhat 9 and Fedora distributions. If you don't have it installed, you can download it from http://www.cstr.ed.ac.uk/downloads/festival/1.95/ or install from its rpm package using the usual rpm command.

Let's begin

Just like every C language book begins, let us start with a "Hello World" program. For this type

echo  "Hello World"| festival --tts 

at the command prompt. If everything is working, we should hear "Hello World" through the speakers.

The "Salute" Program

Now let's write a script to play something like "Good morning Sir" whenever we log on to the system. The sound output will dynamically change based on the login time. The shell script goes like this:


dat=`date +%H`

if [ $dat -le $morning ] 
        echo "Good morning sir" |festival --tts

elif [ $dat -gt $morning ] && [ $dat -le $afternoon ]
        echo "Good afternoon sir"|festival --tts

elif [ $dat -gt $afternoon ] && [ $dat -le $evening ]
        echo "Good evening sir"|festival --tts

Save this file as salute.sh in your home directory, then edit .bash_profile in your home directory and add . ~/salute.sh to it. Now whenever you login to your system, you will hear the "sweet salute."

Create a "Virtual Personal Assistant" with cron

Festival can be used along with the cron to create a personal assistant who reminds you about your appointments. Cron is used to schedule programs in Linux. If it is not already running, start the cron deamon by running service crond start as root. Now create your sound alerts — put the following lines into tea.sh in your home directory:

echo  "Don't forget to drink tea at 6.30 "| festival --tts

Now schedule this as a job in the cron with specified date and time. To remind you of this every day at 6.30 P.M , create a file and name it test. In it insert the line given below

30 18 * * *  sh ~/tea.sh

and run the command

crontab test

to schedule the event. To check that the job is correctly scheduled, run crontab -l. The system will speak the message at the specified time. You could even program your parents PC to wish them happy birthday and surprise them.

Get really hot news from BBC World website

Curious to know what is happening around the world? You can create a News reader to fetch the hot news from the BBC world website and read it for you. For this purpose, we are going to use the RSS feed of that website.

Really Simple Syndication (RSS) is a technology for sharing information on the web. It simple and well-established XML format used to syndicate headlines. Once a website creates an RSS file they have created a means to allow others to retrieve their headlines. Popular news sites like Yahoo!, BBC News, The New York Times along with tens of thousands of personal blogs and independant media sites all publish RSS feeds that we can use.

This shell script will fetch the RSS feed from the BBC World website and then process its headlines and contents. The output is then piped to the Festival program so we can hear the hottest news happening around the world.

#Shell script to fetch and read the hottest news from BBC world using Festival
#Here we specify the url
#specify the proxyserver here, if you have one
headarg="-10"  # default is five headline, change it to increase the no of feeds
#specify the proxy with -x option in curl program, if you
#don't use one, then remove the '-x "$proxy"' part
curl --silent -x "$proxy" "$url" | grep -E '(title>|description>)' | \
  sed -n '4,$p' | \
  sed -e 's/<title>//' -e 's/<\/title>//' -e 's/<description>/   /' \
      -e 's/<\/description>//' | \
#Here we pump the output to Festival
   head $headarg | fmt|festival --tts
exit 0

Save the code as rss.sh and run it as

sh rss.sh

Make sure that you are connected to internet before running this code, since the curl program needs to contact the bbcworld website and fetch the contents.

The god of small things

Sometimes I wish I could hire somebody to read me books or boring man pages. Nowadays I don't read man pages — I just listen to them! For example, to hear the man page of cron:

man cron | festival --tts  

Curious to know the name of people logged on to your system?

 who | awk " print {$1};"| festival --tts

There are lots of things you can have read to you - give them a try!


The power of Festival combined with shell scripting is huge — the sky is the limit.

Further Reading

I haven't discussed the theory behind the text to speech as it is out of the scope of this article. If you are curious, visit http://fife.speech.cs.cmu.edu/festival/manual-1.4.1/festival_toc.html for further details.

To learn more about Shell scripting, check out:

Linux Shell Scripting with Bash by Ken O. Burtch
Wicked Cool Shell Scripts by Dave Taylor


[BIO] Maxin B. John works for HCL Infosystems Ltd, Pondicherry and is an MCA graduate from Govt. Engg. College, Thrissur. He likes to experiment with Python and Bash. He thanks his guru Mr. Pramode C.E for introducing him to the wonderful world of Linux.

Copyright © 2005, Maxin B. John. Released under the Open Publication license unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 114 of Linux Gazette, May 2005

<-- prev | next -->