Pages

Friday, November 18, 2022

Talkie part 1: the ESP32 Speech Synthesiser

For an index to all my stories click this text.

Speech synthesises has come a long way. If you have a Google Home or Alexa you know how well it sounds when the device talks to you. 

Back in the old days speech synthesises was Magic. I had a glimpse on it on an Apple II computer. I never used it myself. I had a Commodore 64 and the speech software was not widespread in the Netherlands. There was a speech add-on board for the Commodore 64 but it was as expensive as the computer itself: meaning around 500 euro.

Back in those days a computer with speech synthesises sounded like a computer that talked. Maybe you remember some video's in which professor Stephen Hawking gave a talk about the universe. He had a speech synthesizer that spoke as a computer voice.

Someone has ported such a system to the ESP32 and it is called Talkie. Talkie is a software implementation of the Texas Instruments speech synthesis architecture (Linear Predictive Coding) from the late 1970s / early 1980s, as used on several popular applications. It was used by Texas Instruments, Acorn computers, Atari arcade games, Apple ][ and the IBM PS/2 Speech adapter (information from its website).

Talkie has a rather limited vocabulary. It is however enough to make some fun projects with it. And that is exactly what I wanted to do. So lets have a look at it.

Hardware.

To get speech synthesises working on the ESP32 we have to add some additional hardware. The ESP32 can not supply enough power from its IO pins to attach a speaker directly. So we have 2 possibillities.

First we can attach a speaker with a build in amplifier. These are the same speakers you would attach to your computer or Raspberry. I have a few sets of them some powered by a dedicated power supply and some can be powered by a USB power supply or even a power bank.

The second method is to connect an amplifier to the ESP32 and attach a speaker to that amplifier. I have bought some small amplifiers from my chinese suppliers which are very cheap. They are called GF1002. It is a stereo amplifier that supplies about 3 watt per channel and works from a 5 volt power supply. So we can feed it from an USB power supply. It has a volume knob with an on/of function and is breadboard friendly. Just solder some headers and you are ready to go. Ideal for this kind of work and enough volume to hear the speech across a room.

So an ESP32 an amplifier and a speaker is basically all we need. Add a button with a resistor and it is all we need for the first project I am presenting here: a talking clock.

Breadboard setup

As you will know by now the ESP32 does not fit nicely on a breadboard. Therefore I use two breadboards like described here: https://lucstechblog.blogspot.com/2018/08/breadboard-hack-for-esp32-and-esp8266.html



The amplifier needs more current then the ESP32 can deliver, so I added a USB connector for an external power supply. When the programming is done I use a USB power plug or powerbank with two USB connections. The first connection goes to the ESP32 and the second to the amplifier.

If you do not have a USB breadboard connector just use an old USB cable an strip the wires. Just be carefull with the polarity as you might be in for a surprise: https://lucstechblog.blogspot.com/2016/12/check-check-and-doublecheck.html

Next to the USB connector there is a button with a pull-up resistor connected to pin 13 of the ESP32.

Pin 25 (D25) of the ESP32 is connected to the left input of the amplifier and the speaker is connected to the left output of the amplifier. So I am just using one in- and output of the amplifier.

Thats all.

Talkie Software

Talkie software as stated is an implementation of Texas Instruments speech synthesis adapted for the Arduino series and ported to the ESP32. The original Arduino version can be found here: https://github.com/going-digital/Talkie

We are going to use the ESP32 version which can be found here: https://github.com/bobh/ESP32Talkie

Talkie comes with over 1000 words of speech which you can find in the included examples. Enough for some hours of fun and to make some serious projects.



Installing Talkie is simple as with all libraries. Just download the Zip file from the link shown above and open the Sketch tab in the Arduino IDE. Choose Include Library and Add .Zip Library.

After installing the library in the File menu under Examples scroll down till you find the Talkie entry and have a look at the examples. All the words you can use are in the example files. It is a bit of a search for the right words but thats part of the fun.

Talkie uses the ESP-32's build-in Dac and therefore sends its speech out on pin D25

Talkie first test

As a first test I collected several words from the demonstration files and combined them in a new program.

The program is simple. It puts the ESP32's build-in led On and after a second Off. Each time it says the words "The light is on" and then "The light is off".

#include <Arduino.h>

#include <Talkie.h>

Talkie voice;

const uint8_t spON[]    PROGMEM = {0x65, 0x4A, 0xEA, 0x3A, 0x5C, 0xB2, 0xCE, 0x6E, 0x57, 0xA7, 0x48, 0xE6, 0xD2, 0x5D, 0xBB, 0xEC, 0x62, 0x17, 0xBB, 0xDE, 0x7D, 0x9F, 0xDA, 0x5C, 0x5C, 0x7A, 0xAA, 0xB5, 0x6E, 0xCB, 0xD0, 0x0E, 0xAD, 0x6E, 0xAF, 0xEE, 0xF9, 0x88, 0x67, 0xBC, 0xDC, 0x3D, 0xAC, 0x60, 0xB8, 0x45, 0xF3, 0xB7, 0xBF, 0xC3, 0xDD, 0xA2, 0xBB, 0xAB, 0xCD, 0x89, 0x8F, 0x7F, 0xFE, 0x1F};
const uint8_t spOFF[]   PROGMEM = {0x6B,0x4A,0xE2,0xBA,0x8D,0xBC,0xED,0x66,0xD7,0xBB,0x9E,0xC3,0x98,0x93,0xB9,0x18,0xB2,0xDE,0x7D,0x73,0x67,0x88,0xDD,0xC5,0xF6,0x59,0x15,0x55,0x44,0x56,0x71,0x6B,0x06,0x74,0x53,0xA6,0x01,0x0D,0x68,0x80,0x03,0x1C,0xF8,0x7F};
const uint8_t spLIGHT[] PROGMEM = {0x61,0x69,0xC0,0x2B,0x82,0xB3,0xA5,0x79,0x01,0x9A,0x52,0x71,0x57,0xC7,0x31,0x0C,0x5C,0x5D,0xC1,0x59,0x6F,0x7B,0x9A,0xC6,0x3B,0xCB,0xA5,0xCB,0xA9,0xAA,0x6D,0x6B,0xB3,0xCD,0xA7,0x6C,0x29,0xB4,0x34,0x56,0xAF,0xBA,0x0F,0x23,0x93,0x5C,0x32,0xC7,0xB6,0xF6,0x46,0xA4,0x39,0xB3,0xF3,0x86,0x40,0x11,0xCA,0x5D,0x44,0x36,0x00,0x80,0x02,0x96,0x2A,0x35,0xC0,0xB6,0x97,0x0C,0xE8,0xF9,0x04,0x01,0xC5,0x19,0xFC,0x3F};
const uint8_t spTHE[]   PROGMEM = {0x08,0x20,0xBA,0x0D,0x03,0x69,0xDF,0xA8,0xCD,0x85,0x3B,0xD7,0x79,0xF4,0x59,0xB7,0xA9,0xFA,0xA2,0xD5,0x27,0xD9,0x6E,0x11,0x8B,0xC6,0x90,0xB4,0x47,0xA8,0x6D,0xFA,0x7F};
const uint8_t spIS[]    PROGMEM = {0xA3,0xED,0xC6,0x30,0x3D,0x57,0xAD,0x7E,0xA8,0x42,0xA9,0x5C,0xB5,0xFA,0xA9,0x8A,0xB8,0x62,0xF3,0xEA,0x86,0x48,0xE6,0x8A,0x57,0xAB,0xEB,0x22,0x58,0x23,0x5E,0xAF,0xAE,0xCA,0x64,0xF5,0x7C,0x3C,0xBA,0xCA,0x93,0xD5,0xE3,0x76,0xEB,0x3B,0x4E,0x55,0xB3,0x4D,0x65,0xB8,0x58,0x5D,0xDD,0x72,0x97,0xE9,0x1B,0x55,0x27,0x4D,0xD3,0xE6,0x85,0xD5,0x4D,0x3D,0x6B,0xF9,0x5F,0x50,0x1B,0x26,0x27,0x0A,0xF8,0xAD,0x54,0x01,0xBF,0xBA,0x0B,0xE0,0xA7,0xF4,0xFF,0x07};

void setup() 
{
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() 
{
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  voice.say(spTHE);
  voice.say(spLIGHT);
  voice.say(spIS);
  voice.say(spON);
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  voice.say(spTHE);
  voice.say(spLIGHT);
  voice.say(spIS);
  voice.say(spOFF);
  delay(1000);
}

As you can see the program is simple. It starts with including the Talkie library. Next a few words are defined.

In the setup() the ESP32's build-in led is defined.

The loop() sets the led ON, speaks the words "The light is on", waits a second and puts the led off and speaks the words "The light is off"

Nothing to complicated but enough to get you started.

Expanding

As said before just look in the example files to all the words and combine them in a new program that can say the phrases you want.

The above example is the base to get you going. Two more stories coming up. The first will show how to build a talking clock and the second shows how to build a talking thermometer.

Start with this and have fun.

Luc Volders