Sound is an important tool in our robotic toolkit, but you will want to do more than just play music. Let's allow our robot to speak. You're going to start by enabling Espeak, an open source application that provides us with a computer voice. Espeak is an open source voice generation application. To get this free functionality, download the Espeak library by typing sudo apt-get install espeak
on the prompt. The download may take a while, but the prompt will reappear when it is complete. Now, let's see if Raspberry Pi has a voice. Type the espeak "hello"
command. The speaker should emit a computer-voiced hello. If it does not, check the speakers and volume level.
Now that we have a computer voice, you may want to customize it. Espeak offers a fairly complete set of customization features, including a large number of languages, voices, and other options. To access these, you can type in the options on the command-line prompt. For example, type in espeak -v+f3 "hello"
and you should hear a female voice. You can add a Scottish accent by typing espeak –ven-sc+f3 "hello"
. Once you have selected the kind of voice you'd like for your projects, you can make it the default setting so that you don't always have to include it in the command line.
To create the default settings, go to the default file definition for espeak
, which is in the /usr/lib/arm-linux-gnueabihf/espeak-data/voices
directory. You should see something like as follows:
The default file is the one that Espeak uses to choose a voice. To get your desired voice, say one with a female tone, you need to copy a file into the default file. The file, that is, the female tone, is in the !v
directory. Type !v
whenever you want to specify this directory. We need to type the character because the
!
character is a special character in Linux, and if we want to use it as a regular old character, we need to put a character before it. Before starting the process, copy the current default into a file named
default.old
, so it can be retrieved later if needed. The next step is to copy the f3
voice as your default file. Type the sudo cp ./!v/f3 default
command. If you open this file, it will look as follows:
This has all the settings for your female voice. Now you can simply type espeak
and the desired text. You will now get your female computer voice.
Now your project can speak. Simply type espeak
followed by the text you want to speak in quotes and out comes your speech. If you want to read an entire text file, you can do that as well using the –f
option and then typing the name of the file. Try this by using your editor to create a text file called speak
; then type the espeak -f speak.txt
command.
There are lots of choices with respect to the voices you might use with espeak
. Feel free to play around and choose your favorite. Then, edit the default file to set it to that voice. However, don't expect that you'll get the kind of voices that you hear from computers in the movies; those are actors and not computers. Although one day we will hopefully reach a stage where computers will sound a lot more like real people.
18.223.134.29