How to get your Pi to speak to you

For this tutorial you will need:

  • A set of speakers or headphones to plug in to your Pi

Here’s a cool way of getting your pi to speak to you!

1. Open LXTerminal

First open up LXTerminal on your desktop.


2. Install Espeak

Now you need to download and install Espeak, the program that transforms your text in to speech.

In LXTerminal, type the following command and press enter:

pi@raspberrypi ~ $ sudo apt-get install espeak

dont type – pi@raspberrypi ~ $ – just the stuff after it!!!!!

Here’s what the above does:

Sudo ( Super user do – give yourself special permission because you are installing software)
apt-get ( this is a program called Aptitude that goes and fetches most Linux software from the internet for you)
install (when we have got the software we want to install it)
espeak (The name of the software)

For those who are interested most Linux software is stored online repositories that you can access for FREE!

3. Plug in your speakers or headphones in to the Pi’s  Audio Port.


4. Get your Pi to speak to you!

In the LXTerminal window, type in the following command and press enter:

pi@raspberrypi ~ $ espeak "hello world"

If all went well your Pi should have said hello world!

Here’s what the code does:

espeak – Runs the espeak software
“hello world” – This tells the program what you want it to say, this is called a Command Line Parameter

5 – Optional: Get your Pi to speak to you using Python.

A. Open Python in the LXTerminal:
pi@raspberrypi ~ $ python

This should open up the python shell.

B. Then type in the following commands in to python.
>>>from subprocess import call

This goes and gets the call method from the subprocess module, because we need to use it.

C. Run the Espeak program with the “hello world” text like before.
>>>call(["espeak","hello world"])

If all has gone correctly python should have said hello world to you!

Python comes with loads of modules that do wonderful stuff, but if they were all loaded when you start python it would take a long time for python to start and things would get very,very messy behind the scenes. So sometimes you will need to import the module you want in order to get python do do stuff. You can either import the entire module by typing – import xxx, or you just import the little bit of the module you are using by typing – from xxx import yyy