eSpeak is lightweight and portable, it is very well supported and has a stable release in the Raspian and Ubuntu repositories (no proprietary lock-ins or service charges). It provides a simple and straightforward command line interface that can be easily integrated into Python as well as other languages. It even allows us to record straight to a WAV sound file with a simple option in the command linel . Best of all it has a Stephen Hawking-like style that gave it a fitting dose of panache and smugness... it's also great fun finding out what it mispronounces!
There are a number of open-source methods and software solutions for giving your system text-to-speech (TTS) capabilities. Thee best solution we found was using eSpeak as it had a nice range of voices and was not too processor intensive (good for the Raspberry Pi!) eSpeak is known as, a formant synthesis TTS engine which computes the pronunciation and intonation rather than using cut up bits of recorded voice like other systems use. This makes it lightweight and portable. It is, very well supported and has a stable release in the Raspian and Ubuntu repositories (no proprietary lock-ins or service charges). It provides a simple and straightforward command line interface that can be easily integrated into Python as well as other languages. It even allows us to record straight to a WAV sound file with a simple option in the command linel . Best of all it has a Stephen Hawking-like style that gave it a fitting dose of panache and smugness... it's also great fun finding out what it mispronounces!
For getting started the best thing to do is to just try installing espeak and see if it works "out of the box". Don't forget to have an amplified speaker or headphones plugged in to your Raspberry Pi and switched on . For help in setting up audio or for debugging any audio problems you have please see this great post on Raspberry Pi Spy
To install eSpeak type on your command line:
$> sudo apt-get install espeak
This will install espeak and espeak-data packages. Then try issuing a command straight to espeak:
$> espeak "Hello, I'm sure we can be friends."
Small Tip: Be careful with punctuation - using an exclamation mark before the end quote (!") gets the bash shell all excited about special functions so if you want to leave on an exclamation mark, put a space between it and the end quote (! "), and of course watchout for quote marks within the string.
The first time eSpeak runs it will probably have a short delay before speaking which seems to disappear on subsequent executions. You will also probably get quite a long list of warnings about "ALSA lib", "server sockets" and the "jack server" - these seem pretty harmless and not to be worried about. The important thing is that it speaks to you! More details of TTS and working with eSpeak can be see here.
eSpeak has a very simple command line structure:
$> espeak [options] [string to say]
Running just ( $> espeak ) will allow you to type in things to say without having to run espeak each time - the lines are spoken when you press enter. To quit use Ctrl-C to break out of the program.
The options allow you to change the language, variation, pitch, speed, volume, stresses and many other parameters of the speech and even allow you to write out a WAV file (in which case it is not said out loud). For a list of all the options run the standard '-h' option ( $> espeak -h ) or look at the manual page ( $> man espeak ). For instance:
$> espeak -ven -s220 -p25 "Oh, you're playing with my voice..."
Sets the language (-v) to English (en), the speed (-s) to 220 words per minute (range of 80 to 450, default 175) and the pitch (-p) to 25 (range of 0 to 99, default 50).
Now that we can give a Raspberry Pi robot the power of speech what kind of things do you think it could be used for? May be it could let you know whenever you have a new email and read it out loud and I'm sure you can thinking of several other things. As a simple code example lets consider our PiBot's speech being triggered every time it bumps into something. Here we've added a hardware sensor that gets triggered every time it bumps into anything, from our PiBot python library we've exposed this event as a PiBot.isBumped function.
from espeak import espeak
if PiBot.isBumped(): # Check if PiBot has been bumped
responses = ['Ouch, that hurt!',
'Watch where you are going, you almost hurt me',
'Ouch, be careful']
speak = random.choice(responses) # Get a random response to speak back to the user
espeak.synth(speak) # Speak back to the user!