|Image 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.
IntroductionI 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 UbuntuEspeak 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
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
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.
RefinementThis 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
s/et al\./and others/g
If you want to use these filters, your command would look like this:
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
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. [ Read more... ]