Linux Blog

Add Voice to your Shell Scripts

Filed under: Shell Script Sundays — at 3:52 pm on Sunday, October 12, 2008

Text to speech has been around for a number of years. While you may not want to add text to speech to all of your shell scripts you may have a particular script that would be nice to get some audio feedback from. There are a couple of text-to-speech engines that run in the shell, but my favorite is flite. It is really simple to install and use and has a decent set of voices. You can add other voices or compile your own with FestVox.

Here is how to use flite from the shell to directly play the text:

[owen@TheLinuxBlog ~]$ flite -t "Thanks for reading The Linochs Blog"

Notice the misspelling of the word Linux. If flite doesn’t correctly output the words, you can sometimes use phonetics to get a better result.

You can also play text files by using the -f option.

[owen@TheLinuxBlog ~]$ flite -t "Thanks for reading The Linochs Blog"
flite: pcm_params.c:2333: sndrv_pcm_hw_params: Assertion `err >= 0' failed.

If you get a result like above don’t despair. You may be able to google around to fix the problem, or you could use a simple workaround. Try putting an output wave at the end of the command, playing the file and then removing the wave file when you are finished like so:

/usr/bin/flite -t "See you next week" /tmp/play.wav; play /tmp/play.wav; rm /tmp/play.wav

Here are all of flites options:

flite: a small simple speech synthesizer
version: flite-1.3-release October 2005
CMU Copyright 1999-2005, all rights reserved
usage: flite TEXT/FILE [WAVEFILE]
Converts text in TEXTFILE to a waveform in WAVEFILE
If text contains a space the it is treated as a literal
textstring and spoken, and not as a file name
if WAVEFILE is unspecified or “play” the result is
played on the current systems audio device. If WAVEFILE
is “none” the waveform is discarded (good for benchmarking)
Other options must appear before these options
–version Output flite version number
–help Output usage string
-o WAVEFILE Explicitly set output filename
-f TEXTFILE Explicitly set input filename
-t TEXT Explicitly set input textstring
-p PHONES Explicitly set input textstring and synthesize as phones
–set F=V Set feature (guesses type)
-s F=V Set feature (guesses type)
–seti F=V Set int feature
–setf F=V Set float feature
–sets F=V Set string feature
-b Benchmark mode
-l Loop endlessly
-pw Print words
-ps Print segments
-pr RelName Print relation RelName
-v Verbose mode

Random Man Pages:


Comment by Binny V A

October 16, 2008 @ 3:06 pm

I prefer using festival. Here is the command to convert text to speech using festival

Anyway, I’ll give flite a try.

Comment by

October 30, 2008 @ 12:04 am


How can you prefer something when you haven’t tried the alternative? Flite is based off of the festival engine I believe and stands for “Festival lite”

Comment by nee

January 28, 2009 @ 11:32 pm

Hi everybody,

I would like to know ” How to compile flite-1.3-release.tar on window”.
I saw this file that C language. It could run on linux but It can not run Flite on window.
Therefore, I want to get C soure code Flite in order to modify something to adapt my project.
How should I do?

Thank you

Comment by

January 29, 2009 @ 12:13 pm


Cygwin might help you compile if you install the development tools. Also there are a number of other compiles that may work, but you may have to do some porting to get it to work.

Comment by Dan

March 18, 2015 @ 1:59 am

Here is a neat use for it:

flite_time `date +%H:%M`

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>