Introduction: Text to Speech With Linux.

Ever wanted to get your computer to talk. This might be real important in an emergency if you can not talk. It is so easy to do this.

Update: Added a section to read a text file.

Note: There is a gui for Festival, but I have not found a use for it.

http://sourceforge.net/projects/carnival/files/

Step 1: Install Needed Software

You will need the speech synthesis and the gui prompt software. (This is for Debian based distros)

$ sudo apt-get update
$ sudo apt-get install festival zenity

Note: you need to have a working sound card and speakers of some kind obviously.

Step 2: Create the Batch File for Talking.

You need to use an editor such as gedit to create a file called talk.sh.

In gnome on the menu at Applications > Accessories > gedit Text Editor
or
use the command line

$ gedit ~/talk.sh &

talk.sh
[code]
###################################################################
#
# Talking script
#
#--------------------------
# get words to talk
szAnswer=$(zenity --entry --text "What do you want the computer to say?" )
#--------------------------
# Say words.
echo $szAnswer | festival --tts
#--------------------------
# done
[/code]

Save the file.

Make the file executable:

$ chmod +x talk.sh

Step 3: Create a Launcher

On the open desktop, right click on the desktop and choose: Create launcher

Call it "Talk" or whatever you want..
Choose your batch file. (talk.sh)
Add a comment if you want.
Then press OK.

Step 4: Test It.

Double click on the "Talk" launcher (also know as shortcut on mswindows machines)

You will get the prompt window,
Type in what you want to say and press enter.

You should now hear the computer talk.

Note: Sometimes using phonetics can help the distinctions of the words. For example use tehst for test.

Step 5: Reading a File Out Loud.

You need to use an editor such as gedit to create a file called talkfile.sh.

In gnome on the menu at Applications > Accessories > gedit Text Editor
or use the command line

$ gedit ~/talkfile.sh &

talkfile.sh
[code]
###################################################################
#
# Talking a filescript
#
#--------------------------
# get words to talk
szAnswer=$(zenity --entry --text "What file do you want to be read out loud?" )
#--------------------------
# Say words.
festival --tts  $szAnswer
#--------------------------
# done
[/code]

or a new version that uses a file selector instead.

[code]
###################################################################
#
# Talking a filescript
#
#--------------------------
# get words to talk
szAnswer=$(zenity --file-selection --title="Select a file to read outloud")
#------------------------
# Say words.
festival --tts  $szAnswer
#--------------------------
# done
[/code]

Save the file.

Make the file executable:

$ chmod +x talkfile.sh

Step 6: Set Up a Launcher Again.

On the open desktop, right click on the desktop and choose: Create launcher

Call it "Talk a file" or whatever you want..
Choose your batch file. (talkfile.sh)
Add a comment if you want.
Then press OK.

Step 7: Test It Out.

Double click on the "Read a text file out loud" launcher.

You will get the prompt window,
Type in what file you want to hear read out loud  and press enter.(be sure to have the correct path).

You should now hear the computer read the file out loud.

Note: Files with special characters could cause problems. You may need to edit accordingly.

Step 8: Epilogue.

Not only can you read a sentence out loud, should be able to read out loud a simple text file.
Have fun!

Bonus: If you have a server without a monitor which is commonly known as headless, you can either use the internal speaker or attached speakers  to speak out messages. Might be better than idiot lights and or a lcd that might eventually get ignored over time.

Server_status.sh (running in background).
[pseudocode]
...
...
if server overheating then
echo "Attention: server status message!. " | festival --tts
echo "Warning the server is overheating. Warning the server is overheating. " | festival --tts
echo "Warning the server is overheating. Warning the server is overheating. " | festival --tts
fi
...
...
[/pseudocode]

Step 9:

Yes, your linux computer can sing (sort of). If you are into musical notes and the like you should be able to modify the xml file to your needs. For now we will just use the scale as a starting poing.

You need to create an xml file called doremi.xml

doremi.xml:
[code]
<?xml version="1.0"?>
<!DOCTYPE SINGING PUBLIC "-//SINGING//DTD SINGING mark up//EN"
      "Singing.v0_1.dtd"
[]>
<SINGING BPM="30">
<PITCH NOTE="G3"><DURATION BEATS="0.3">doe</DURATION></PITCH>
<PITCH NOTE="A3"><DURATION BEATS="0.3">ray</DURATION></PITCH>
<PITCH NOTE="B3"><DURATION BEATS="0.3">me</DURATION></PITCH>
<PITCH NOTE="C4"><DURATION BEATS="0.3">fah</DURATION></PITCH>
<PITCH NOTE="D4"><DURATION BEATS="0.3">sew</DURATION></PITCH>
<PITCH NOTE="E4"><DURATION BEATS="0.3">lah</DURATION></PITCH>
<PITCH NOTE="F#4"><DURATION BEATS="0.3">tee</DURATION></PITCH>
<PITCH NOTE="G4"><DURATION BEATS="0.3">doe</DURATION></PITCH>
</SINGING>
[/code]

Once the file is created you can go into the interactive mode by just typing testival.

$ festival
Festival Speech Synthesis System 1.96:beta July 2004
Copyright (C) University of Edinburgh, 1996-2004. All rights reserved.
For details type `(festival_warranty)'
festival>  (tts "doremi.xml" 'singing)

Then you should hear the computer sing.

"<control> d" to exit.

You can construct multi-part songs by synthesizing each part and generating waveforms, them combining them. For example

text2wave -mode singing america1.xml -o america1.wav
text2wave -mode singing america2.xml -o america2.wav
text2wave -mode singing america3.xml -o america3.wav
text2wave -mode singing america4.xml -o america4.wav
ch_wave -o america.wav -pc longest america?.wav

The voice used to sing is the current voice. Note that the number of syllables in the words must match that at run time, which means thios doesn't always work cross dialect (UK voices sometimes wont work without tweaking.

Comments

About This Instructable

7,331views

9favorites

License:

Bio: computoman.blogspot.com Bytesize articles instead of a trilogy in one post.
More by Computothought:Coffeepot mealsEasy sun hatEasy cakes and pies.
Add instructable to: