Google Text to Speech provides excellent speech quality. A limitation is that the Pi needs to be online to use it (which mine always is, so it’s not really a drawback).
First, the ALSA sound driver needs to be enabled. It may not be enabled by default, as it’s an experimental driver.
sudo apt-get update sudo apt-get upgrade sudo apt-get install alsa-utils sudo modprobe snd_bcm2835 |
Also install mplayer, if you haven’t done so already:
sudo apt-get install mplayer |
Add the following line to /etc/mplayer/mplayer.conf:
nolirc=yes
Since your speakers are probably connected to the headphones jack socket you may want to force the output to it:
amixer cset numid=3 1 |
The 1 refers to the headphones, whereas 0 is auto and 2 is HDMI.
A useful script to control the sound volume can be found here: http://www.dronkert.net/rpi/vol.html We’ll set it to max:
vol 100 |
Next we’ll create a simple shell script to make our call to Google Text to Speech and pass the audio result to mplayer, named ‘say’.
say:
#!/bin/sh IFS=+ sudo /usr/bin/mplayer -ao alsa -really-quiet -noconsolecontrols "http://translate.google.com/translate_tts?tl=en&q=$*" |
Now the Raspberry Pi can say whatever needs to bee said:
say "Lights on" say "Hello. Camera is running and you are being recorded. I can see you're really upset about this." |
One thought on “Google Text to Speech on Raspberry Pi”
Comments are closed.