Set up wit.ai text-to-speech so your ESP32 can talk

Get a free wit.ai token, install the WitAITTS library and set the ESP32 options you need so your project can speak any text aloud.

Julian ReedElectronics restorer and tinkerer
4 min read

A small ESP32 board wired to an I2S amplifier and a speaker on a workbench
Photo by ThisIsEngineering / Pexels
Skill
Beginner
Service
wit.ai free tier, no credit card
Voices
23, multilingual
Tools
Arduino IDE

In about an hour you can have an ESP32 project ready to speak whatever text you give it, in a natural-sounding voice. You will set up a free wit.ai account, copy the access token your code needs and prepare the Arduino IDE with the right library and memory setting.

How your ESP32 will speak

You can give a microcontroller a voice in two ways.

The first way is offline. You store prerecorded words on the board and match them to incoming text. The vocabulary is limited to what fits in RAM and PSRAM, and the voice usually sounds robotic.

The second way is online, and it is the one used here. The ESP32 formats your text as a request and sends it over an encrypted HTTPS connection to a cloud service's API. The service turns the text into speech with its own neural network and sends back audio. The ESP32 decodes that audio and streams it to an amplifier and speaker. This lets you type almost anything, in any language, and hear it spoken back naturally.

Neural network text-to-speech has dominated since 2016, and it needs far more computing power than a microcontroller has. Sending the work to the cloud is what makes it possible on an ESP32.

Why wit.ai

wit.ai is a cloud text-to-speech service from Meta. Its free tier costs nothing and asks for no credit card. It offers 23 voices with multilingual support and works through a plain HTTP GET request. It also has a dedicated ESP32 library, which keeps the programming straightforward.

OpenAI TTS works with the same hardware hookup. It is a paid service that costs a fraction of a cent per request.

What you will need

  • Seeeduino XIAO ESP32S3
  • MAX98357A I2S audio amplifier
  • Speaker
  • Computer with the Arduino IDE installed
  • A Wi-Fi network for the ESP32
  • A Meta account (Facebook or Instagram) to log in to wit.ai

Step by step

  1. Log in to wit.ai. Go to wit.ai and sign in with your Meta account.
  2. Create an app. On the main screen, click the button to create a new app. Name it, choose your language and leave it private if you prefer. Click Create.
  3. Open the settings. Open your new app, and under Management, go to Settings.
  4. Copy the right token. You will see a Server Access Token and a Client Access Token. You need the Server Access Token. Click it to copy it to your clipboard.
  5. Store the token safely. Paste it somewhere secure, because your code will need it.
  6. Install the library. In the Arduino IDE, open the Library Manager, search for "WitAITTS" (by Jobit Joseph, made for using wit.ai with the ESP32) and install it along with any dependencies it asks for.
  7. Turn on PSRAM. Go to Tools, find the PSRAM entry and change it from Disabled to OPI PSRAM. The library needs the extra memory for its audio buffers.
  8. Connect the audio hardware. Wire the MAX98357A amplifier to the XIAO ESP32S3 and the speaker to the amplifier. The ESP32 decodes the audio and the amplifier drives the speaker.

Guard your token

Treat the Server Access Token like a password. Do not publish it or include it in code you share. If it is ever exposed, you can replace it from the wit.ai console.

Leave PSRAM on

Keep the OPI PSRAM setting enabled if you later switch to OpenAI TTS. Both setups need the extra memory.

Other voices worth knowing

Once you have one service working, you might want to compare others that the ESP32 can use:

  • Google Cloud Text-to-Speech offers many languages and neural voices through a REST API, with a generous free tier. Authentication takes more work than a simple API key.
  • Amazon Polly returns MP3, Ogg or PCM audio and supports several speech engines. It needs an AWS account and signed requests.
  • Microsoft Azure AI Speech has a REST API, many neural voices, SSML controls for fine-tuning pronunciation and several output formats.
  • ElevenLabs has some of the most realistic voices available and supports streaming playback. Larger projects need a paid plan.
  • Talkie is a library that runs entirely on the microcontroller. Vocabulary and voice quality are limited, but it has no API cost and needs no Wi-Fi.

A little background

The robotic voice from older toys comes from formant synthesis. It uses mathematical models of the vocal tract and a rule engine that turns phonemes into formant frequencies. It needs little storage, runs without a network and fits on a microcontroller. The trade-offs are an unnatural voice and trouble with unfamiliar words.

Concatenative synthesis followed. It joins diphones and triphones recorded by voice actors and sounds very realistic, but its databases are far too large for a microcontroller.

Neural systems work in three stages. First, a front end normalizes the text and converts letters into phonemes. Next, those phonemes become a mel spectrogram, built frame by frame. Finally, a vocoder turns the spectrogram into audio waveforms for your amplifier and speaker.

Filed underTechnologyElectronicsBeginnerLearning
Portrait of Julian Reed

Written by

Julian Reed

A vintage electronics restorer and hobbyist tinkerer who walks readers through soldering basics, retro console repairs, and fun weekend gadget builds.

Previous articleStart resistance training safely and build functional strengthNext articleKeep the horizon level in your photos while you shoot

You may also like

0 comments

    Join the conversation

    Be kind and be specific. Comments are moderated before they appear.