How it works
Speech synthesis, known as TTS (text-to-speech), does the reverse of speech recognition: it takes text in and produces audio of a voice speaking.
Modern systems usually follow these steps:
- Text analysis: the system understands numbers, acronyms, dates and punctuation. "R$ 10" becomes "ten reais".
- Pronunciation: words are converted into sounds, phonemes, respecting the language and accent.
- Intonation: the model sets the rhythm, pauses and melody of the sentence.
- Audio generation: a neural network produces the final sound wave.
In the past speech was assembled by stitching together recordings, and the result sounded robotic. Today, neural networks generate much more natural voices, and some services can create a voice from just a few audio samples.
Quality varies by language. Brazilian Portuguese voices exist in several services, but it's worth listening to examples before choosing.
Practical example
A person who produces content wants to turn their articles into audio for people who prefer to listen. They send the text to a TTS service and publish the file alongside the article.
Another example: a company has an AI attendant on the phone. The flow is this:
- The customer speaks.
- Speech recognition turns the audio into text.
- The AI agent decides the response.
- Speech synthesis reads the response out loud.
In code, a call to a service usually has this format:
{
"texto": "Seu pedido saiu para entrega.",
"idioma": "pt-BR",
"voz": "NOME_DA_VOZ"
}The actual fields depend on the provider, so follow its documentation.
What it's for
Speech synthesis is used to give voice to written systems.
Common uses:
- Accessibility: screen readers for people with visual impairments.
- Voice assistants and phone support.
- Narration of videos, courses and audiobooks.
- Automatic alerts, such as warnings and notifications.
- Language apps, to hear pronunciation.
There are important caveats. Cloning a person's voice requires their consent, and synthetic voice should be identified as such when it could deceive the listener. Scams with fake voice exist, so be wary of urgent requests by audio.
To choose a service, test the same text in two or three voices and ask people from your audience for feedback.