Free Text-to-Speech


text to speech keyboard speech generating deviceImage via Wikipedia
text to speech keyboard

Text-to-speech is great for the lazy, visually impaired, or people with reading disabilities. I think I read much, but I also count myself to the lazy and I like it to be read to. I found how you can select any text, for example in a webpage or a PDF, and let it be spoken using free software. It is relatively easy to set this up and here I show how.


Introduction

I used to have this on my Mac, people even had this on the amiga, and I also know of some firefox add-ons that give this functionality, such as Text to Voice.

Is something like this possible for free, system-wide, on Linux or Windows? Short answer: Yes. Now I explain how with a simple trick you can hear any text that you select, in any program. I concentrate on installation on ubuntu, but similarly this should be possible on other linux distributions, on MacOS, and Windows.

There are several free software projects that produce speech synthesizers. Possibly the two best known free text-to-speech (TTS) systems are espeak and festival. Both come packaged in many linux distributions but can also be installed on other platforms, such as Mac OS or Windows.

TTS with Espeak in Ubuntu

Espeak is a speech synthesizer for English and many other languages. On ubuntu, installation could not be easier: use synaptic or type sudo apt-get install espeak.

Espeak reads text, for example, try: espeak -f sometextfile. You have options to adjust reading speed, pitch, and a choice of different voices in different languages (in ubuntu just look in /usr/share/espeak-data/voices/es-la). Try: echo "hola" | espeak -v es. You can also put these and other options directly into the files in espeak-data directory, thereby creating new voices.

Now how to read text that you select?

I found a nearly complete solution and here I am going to spell it out.

If you use Gnome as window manager, go to system->preferences->keyboard shortcuts
(if you use KDE or other managers, this should be similar), add a new shortcut.

name: read text
command: bash -c "xsel | espeak"

Then define a key combination. I defined windows button-R.

Now you can select text in any application press your keys and hear the text as it is spoken to you.

Refinement

This works already, but you can make some improvements.

I found that filtering out newline symbols was nicer to the ear, because the pauses at the end of each line make it sometimes hard to understand. The command to hear the text without newlines would then be (thanks!):

Change the command in the keyboard shortcuts to this:

bash -c "xsel | sed -e :a -e '$!N;s/\n/ /;ta' | espeak -s 180 -v en-us"

Of course you can put more elaborate filters instead of the sed command. For example you can substitute "i.e." for "this is." For theater plays you could use different voices for each characters.

I also put in some filters. For example I don't want to hear "i.e." spoken as "IdotEdot" but as "this is."

Here comes my filter file, which you can copy. I stored this file as /usr/share/espeak-data/espeak.sed

s/i\.e\./this is/g
s/e\.\g./for example/g
s/et al\./and others/g
s/\([A-Z]\)\([A-Z]\)/\1 \2/g

If you want to use these filters, your command would look like this:
command: bash -c "xsel | sed -e :a -e '$!N;s/\n/ /;ta' -f /usr/share/espeak-data/espeak.sed | espeak -s 180 -v en-us"

Finally I also defined a key combination, windows button-S to stop the reading.
name: stop text
command: pkill -9 espeak

Note that instead of espeak you can also use the festival speech synthesis system. Install typing sudo apt-get install festival. A simple test: echo hello | festival --tts. I needed to switch to ALSA output for it to work. See configuration options at the archlinux wiki.

Enjoy. Please tell me of any improvement you come up with. 

33 Responses to "Free Text-to-Speech"

Impressive tool. I discovered that Adobe reader would read text by selecting it and going to the tool menu.

waaooo ... good infoo

thanks for the info....i will try this...

thanks, great article!

There is good introduction about text to speech.I came to know about this for the first time.Now I would also like to try for Espeak and I will definitely download it.

Hey I did not know about Text to Speech and it is really good to know about it.Interesting introduction.I like that you have shared this new information with us.I also came to know about Espeak speech synthesizer.

sorry maybe this question is out of topic,,,
but can u tell me how to add your blog archive in tabbed menu???

Thx n sorry for my bad english...

I also like to use the Adobe reading feature although the voice is rather mechanical.

I never could get my text-to-speech program to work properly. It always messes up some words then I have to edit them.

nice.
and to noobs like me: just remember to install xsel. just spent quite a lot of time figuring that out.
thanks.

Since the development of Internet many things have change and it also brought newer applications in our life like this one...the free text-to-speech. It's truly convenient to use. Thanks for the info.

tanks for your informations

Yeah I agree, since the birth of Internet there are so many things that we can do. For me this tool is good for those people who has speech defect like me, as you mention above we're sharing same thought, I also want to read and read. This is such interesting topic. Thanks for sharing this post.

how to let festival speek in french please!!

I explain espeak in this post. For espeak, it would be for example like this:
echo "bonjour" | espeak -v fr

Thanks a lot but I want to add French language to Festival TTS if can help me please do it!!!

Festival supports English (British and American), Welsh, and Spanish. Voice packages exist for Castilian Spanish, Czech, Finnish, Hindi, Italian, Marathi, Polish, Russian and Telugu. There are other commercial voices, e.g. cepstral, where you can buy French voices.

thanks a lot but I want to add french language to festival TTS please if you have an idea help me!!

I mean that I want add french language using mbrola project, have you an idea how can I do it!
If you know other alternative to let festival speek french please help me!!

My purpose is to make festival TTS speeking in french using mbrola project, if you have an idea help me! If you have other alternative to let festival speek french please help me!!!!!!!!!

You have an idea how can I implement it please help me!!!

How can I implement it please!!

how can I implement it please!!

How can I implement it please!!!!!!!!!!!

how can I implement it please!

how can i implement it please!!

how can i implement it please!!

I dont know what to say. This blog is fantastic. Thats not really a really huge statement, but its all I could come up with after reading this. You know so much about this subject. So much so that you made me want to learn more about it. Your blog is my stepping stone, my friend. Thanks for the heads up on this subject.

 Reading this i finally took a break from my job. This post just gave me a few minutes of relax =] I tried to find a rss feed on your site so that i could subscribe for some more. Ill be sure to come here more often from now on =]

how to let festival speek in french please!!

Thanks for sharing, I agree, do you know how to add french language? PLZ

  Subscribe to replies to this post

 
This conversation is missing your voice. Your feedback is appreciated.
Post a Comment


You can use some HTML tags, such as <b>, <i>, <a>

If you see a message that says "your request could not be processed" press preview first and then post.
 
You can follow the discussion of this post by subscribing.


 
You are free to include information from this article on your own site if you provide a backlink. You can use the following markup:
<a href="http://www.myoutsourcedbrain.com/2010/06/free-text-to-speech.html">Free Text-to-Speech</a>