Skip to main content

We have ways of making your Pi talk

Would you like your Pi to speak to you? This project shows how to use espeak and a Node-RED function to make your Pi speak your thoughts. Or an input. Or whatever you tell it to.

Parts list

Qty Product Part number
1 OKdo Raspberry Pi 4 B Starter Kit 4 GB 202-0644
1 Travel speaker (e.g.https://www.ebay.co.uk/i/174388957610)

Converting text to speech can be done with eSpeak - a compact open source software speech synthesizer. This project shows how to incorporate it into a Node-RED flow.

Many thanks to @Ceejay for the help on this.

BE AWARE - The latest version of Raspbian (as at 12 Jan 2021) means that espeak does not work in Node-RED IF you are also using an HDMI cable for a monitor etc. It has something to do with using sudo and Pulse - see https://raspberrypi.stackexchange.com/questions/40236/no-sound-when-using-sudo-in-raspbian 

A work around is to set up the Pi using a monitor, and then enable SSH, and then turn off the power, unplug the monitor, reboot and SSH in from another computer. Many thanks to @Ceejay and @jpwsutton for debugging help!

Preliminaries

1) Install the latest Raspberry Pi operating system on to your Pi

Details here: https://www.raspberrypi.org/software/ (For this project I am using a Raspberry Pi 4 and Raspbian Pi OS (32 bit) 2020-08-20). Follow the onscreen instructions to update and complete the set-up.

2) Install Node-RED

Note: DO NOT USE THE 'RECOMMENDED PROGRAMS' link on the Pi menu, instead go to the "Running on a Pi" section at https://nodered.org/docs/getting-started/raspberrypi and follow the instructions there - use the code:

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

And say "Yes" to installing the Pi Nodes.

Wait a long time

Once it is installed run the code:

sudo systemctl enable nodered.service

This will make Node-RED automatically start every time the Pi boots up.

You can then go to a browser and type in localhost:1880 to access Node-RED

3) Install e-speak on to the Pi

In a terminal, type

sudo apt-get install espeak

Set the audio output to headphones

sudo apt-get install espeak

Then select: 1 System Options, S2 Audio, Select Headphones, OK and Finish.

Write the Node-RED flow

Connect an inject node to an exec node.

Screenshot_2020-11-17_at_13.24_.20__61fb071e3115d3d5b9abd00cb57de27893a2eab6.png

or you can copy and paste the Node-RED flow below:

[{"id":"905cdbc0.6ae2","type":"inject","z":"99722a53.c60bb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"\"test lots of words here\"","payloadType":"str","x":170,"y":160,"wires":[["9f52749a.629bf8"]]},{"id":"9f52749a.629bf8","type":"exec","z":"99722a53.c60bb","command":"espeak","addpay":true,"append":"--stdout | aplay","useSpawn":"false","timer":"","oldrc":false,"name":"","x":360,"y":160,"wires":[[],[],[]]}]

The string you want the Pi to speak must be in quotation marks in the inject node msg.payload

In the exec node:

Command: espeak

+Append:

msg Payload (tick)

--stdout | aplay

Output: when the command is complete - exec mode

Deploy and click the inject node. If the words are coming out of your monitor (via HDMI) you may need to right click on the speaker on the menu bar, and select "analog" to force the sound to the audio jack. Also, note to self: make sure speaker is plugged in to Pi and turned on.

Whatever payload is fed in to that exec node, with quote marks, will be spoken.

I am an inventor, engineer, writer and presenter. Other stuff: Royal Academy of Engineering Visiting Professor of Engineering: Creativity and Communication at Brunel University London; Fellow of the Institution of Mechanical Engineers and have a PhD in bubbles; Judge on BBC Robot Wars.
DesignSpark Electrical Logolinkedin