How does a TTS model control emotion, speed, and style from a text prompt?

Authors
How does a TTS model control emotion, speed, and style from a text prompt?

A TTS model controls emotion, speed, and style from a text prompt by reading a plain description of how the voice must sound, turning it into numbers, and using those numbers to guide every piece of sound it creates.

In this blog, we will learn about how a TTS model controls emotion, speed, and style from a text prompt. We will also see why one sentence can be spoken in many ways, the two inputs such a model takes, how sound is turned into tokens, how the model learns to connect descriptions with voices, how the description guides each step of generation, and where this works well and where it fails.

We will cover the following:

  • The problem with a fixed-voice TTS model
  • The two inputs: the transcript and the description
  • How sound becomes tokens
  • How the model learns what a description means
  • How the model reads the description
  • How the model reads the transcript
  • How the model generates speech step by step
  • How speed is controlled
  • How emotion is controlled
  • How style is controlled
  • Where it works well and where it fails

I am Amit Shekhar, Founder @ Outcome School, I have taught and mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.

I teach AI and Machine Learning at Outcome School.

Let's get started.

The problem with a fixed-voice TTS model

TTS stands for Text-to-Speech. A TTS model takes written text and speaks it out loud.

Let's say we give a TTS model this sentence:

"I cannot believe we won the match."

A person can say this sentence in many ways:

  • Happy and loud, because the team won.
  • Slow and shocked, because nobody expected it.
  • Soft and whispering, because the person is in a library.

The words are the same. Only the way of speaking changes.

Many older TTS models speak every sentence in one fixed way. They have no way to know whether we want the happy version or the shocked version. If we want a different voice, we need to train a different model, or pick from a small list of fixed speakers.

So, how can we tell the model how to speak? The answer is: we tell it in plain words, the same way we would tell a voice actor.

"A young woman speaks very fast in a happy and excited voice."

Here comes the text prompt into the picture. This plain description of the voice is the text prompt, and many papers also call it the style prompt or the description.

The two inputs: the transcript and the description

A TTS model that follows a text prompt takes two separate pieces of text.

  • The transcript: the words that must be spoken. For example, "I cannot believe we won the match."
  • The description: how those words must be spoken. For example, "A man speaks slowly in a sad, low voice, in a quiet room."

Let me tabulate the differences between the two inputs for your better understanding.

InputWhat it decidesIs it spoken out loud?Example
TranscriptThe wordsYes"I cannot believe we won."
DescriptionEmotion, speed, styleNo"A man speaks slowly and sadly."

The model must keep these two apart. It must speak the transcript, and it must never speak the description. The description only shapes the voice.

Before jumping into how the model uses the description, we must know how a model can create sound at all.

How sound becomes tokens

An LLM (Large Language Model) writes text one token at a time. A token is a small piece of text, like a word or a part of a word.

Many modern TTS models work in the same way. The main difference is that they write sound tokens instead of text tokens.

So, the next big question is: how can sound become tokens?

Here comes the audio codec into the picture. An audio codec is a model that does two jobs:

  • Encode: It takes a tiny slice of sound, much shorter than one second, and turns it into a small set of numbers called audio tokens.
  • Decode: It takes audio tokens and turns them back into sound.

Let's see the flow in a diagram:

   Sound wave of a person speaking
                 ↓
       Audio codec (encode)
                 ↓
   Audio tokens: 412, 87, 903, 15, ...
                 ↓
       Audio codec (decode)
                 ↓
   Sound wave that sounds almost the same

Here, we can see that once sound becomes tokens, a TTS model can predict sound tokens one after another, just like an LLM predicts text tokens. At the end, the codec turns those tokens back into sound that we can hear.

Planning your move into AI?

No matter which tech domain you work in today, with your effort, you can transition to these roles:

  • AI Engineer
  • Forward Deployed Engineer
  • AI Agent Engineer
  • Harness Engineer
  • Voice AI Engineer
  • AI Architect
  • LLM Engineer
  • LLM Inference Engineer
  • Gen AI Engineer
  • MLOps Engineer
  • ML Engineer
  • Deep Learning Engineer

Our AI and Machine Learning Program at Outcome School takes you there.

Now, let's understand how it learns what a description means.

How the model learns what a description means

A model learns only from examples. To learn what "a man speaks slowly in a sad voice" sounds like, it needs thousands of recordings, and each recording needs a description written next to it.

The problem is that real speech datasets have the recording and the transcript, but almost never a description of the voice. Writing descriptions by hand for tens of thousands of hours of speech is too slow and too costly.

So, here comes automatic labelling to the rescue: we create the descriptions automatically. This is the method used by Parler-TTS, an open-source TTS model from Hugging Face. It is based on a research paper by Dan Lyth (Stability AI) and Simon King (University of Edinburgh).

Step 1: Measure simple facts from each recording using tools.

  • Speaking rate: how many speech sounds are spoken per second.
  • Pitch: how high or low the voice is, and how much it goes up and down, flat or lively.
  • Noise: how much background noise is present.
  • Reverberation: how much echo there is, like in a big hall.
  • Gender and accent: whether the voice is male or female, and which accent it has.

Step 2: Turn each number into a word bucket. In the paper, each measurement is split into seven buckets, and each bucket gets a short phrase such as "very slowly", "fairly slowly", "quite fast", or "very fast".

Step 3: Give these words to an LLM and ask it to write a natural sentence.

Let's say for one recording the labels are: female, fast, high pitch, very clear, close to the microphone. The LLM writes:

"A woman speaks quickly in a high-pitched voice. The recording is very clear and sounds close up."

Now, every recording has three things: the sound, the transcript, and a description. This is the training data.

During training, the model sees the description and the transcript, and it learns to predict the real audio tokens of that recording. After seeing this again and again, it learns that "quickly" goes with speech that has many sounds per second, and "high-pitched" goes with a high voice.

How the model reads the description

A model cannot understand words directly. It understands only numbers. So, the description must first become numbers.

For this, the model uses a text encoder. A text encoder is a model that reads a sentence and turns each token into a list of numbers that captures its meaning. In Parler-TTS, this text encoder is Flan-T5, a language model from Google, and it is kept frozen, which means it is not changed during training.

The best part of using a trained text encoder is that it already knows that "quickly" and "fast" mean almost the same thing. So, the TTS model can often follow a description even when it uses words that were not exactly in the training data.

Now, the main part of the model is the decoder. The decoder is the part that predicts audio tokens one by one. It needs to look at the description at every step.

It does this using cross attention. Cross attention means: while the decoder is deciding the next audio token, it looks back at the numbers of the description and picks the parts that matter right now.

Let's take an example. Suppose the description is "A man speaks slowly in a sad, low voice." When the decoder is choosing the next sound token, cross attention lets it focus on "slowly", "sad", and "low". These words make the decoder choose a token for a long, low, soft sound.

To learn Cross Attention, the Encoder-Decoder Architecture, and Embeddings in depth, we can check out our AI and Machine Learning Program at Outcome School.

How the model reads the transcript

The transcript takes a different path. In Parler-TTS, the transcript is not passed through the text encoder. Its tokens are turned into numbers by a lookup table, called an embedding layer, and these numbers are placed at the start of the decoder's input.

Means, the decoder sees the transcript as the beginning of its own sequence, and then it continues that sequence with audio tokens.

Let me put the two paths together.

InputPath into the modelHow the decoder uses it
DescriptionText encoder (Flan-T5)Looks at it at every step (cross attention)
TranscriptEmbedding layerPlaced at the start of its own sequence

This separation, together with training on real recordings, is the reason the model speaks the transcript and does not speak the description.

A quick note for you

No matter which tech domain you work in, get familiar with these topics:

  • LLM
  • RAG
  • MCP
  • Agent
  • Fine-tuning
  • Quantization

We put it all together in one video:

AI Engineering Explained: LLM, RAG, MCP, Agent, Fine-Tuning, and Quantization

No need to stop reading - bookmark it and watch later when you get time. Future you will thank you.

Now, let's get back to the topic.

How the model generates speech step by step

Now, let's see the full journey with an example.

  • Transcript: "I cannot believe we won."
  • Description: "A woman speaks fast in a happy, excited voice."
 Description: "A woman speaks    Transcript: "I cannot
  fast, happy, excited"           believe we won."
           ↓                              ↓
 Text encoder (Flan-T5)           Embedding layer
           ↓                              ↓
 Description as numbers           Start of the sequence
           ↓                              ↓
 +----------------------------------------------------+
 |                      Decoder                       |
 |  predicts audio token 1, then 2, then 3, ...       |
 |  looks at the description at every step            |
 +----------------------------------------------------+
                          ↓
            Audio tokens: 412, 87, 903, ...
                          ↓
                 Audio codec (decode)
                          ↓
          A happy, fast, female voice saying
              "I cannot believe we won."

Step 1: The text encoder turns the description into numbers.

Step 2: The embedding layer turns the transcript into numbers, and they are placed at the start of the decoder's sequence.

Step 3: The decoder predicts the first audio token. It looks at the transcript to know which sound comes first, and it looks at the description to know how that sound must be spoken.

Step 4: The decoder adds that token to the sequence and predicts the next one. It repeats this again and again.

Step 5: When all the words are spoken, the decoder predicts a special "stop" token.

Step 6: The audio codec turns all the audio tokens into a sound wave.

Now, let's see how this one idea controls speed, emotion, and style.

How speed is controlled

Each audio token stands for a fixed, tiny slice of time. So, the number of audio tokens decides how long the speech lasts.

Let's say, just for the sake of understanding, that each audio token covers 0.01 seconds of sound, and we have the sentence "I cannot believe we won."

  • Spoken fast in 1.5 seconds, it needs 150 tokens.
  • Spoken slowly in 3 seconds, it needs 300 tokens.

The model is not given a number like "use 300 tokens". Instead, during training it has seen many recordings labelled "very slowly", and in those recordings each word stretches across many tokens. So, when the description says "very slowly", the model keeps each sound for more tokens, leaves longer pauses between words, and predicts the "stop" token later.

Means, speed is controlled by how long the model stays on each sound before it moves forward.

Stay updated: Subscribe to our newsletter to get our latest AI and Machine Learning blogs straight to your inbox.

How emotion is controlled

Emotion in speech usually shows up as a mix of small changes:

  • Happy: higher pitch, more ups and downs, a bit faster.
  • Sad: lower pitch, flatter tone, slower, softer.
  • Angry: louder, sharper, more force on some words.
  • Whispering: almost no voice, mostly breath.

The model does not have a separate "emotion switch". It learns these patterns from training recordings whose descriptions mention the emotion. Emotion labels can come from people who listen and tag the recordings, or from datasets where actors read lines in a given emotion.

Let's say we keep the transcript "I cannot believe we won." and change only the description:

  • "A woman speaks in a cheerful, excited voice." gives a high, lively, quick line.
  • "A woman speaks in a sad, quiet voice." gives a low, slow, soft line.

When the description says "a sad, quiet voice", cross attention makes the decoder choose each new token from the sounds it has learned for sad speech. This is how the same transcript comes out cheerful in one run and sad in the next.

Note: A model can follow only the emotions that it has seen enough of during training. If the training data has very less angry speech, the word "angry" in the description will have a weak effect.

We have a detailed blog on how a voice agent matches its tone and emotion to the user that explains how an agent decides which emotion to ask for.

How style is controlled

Style is everything else about the voice and the recording. For example:

  • Who is speaking: a man or a woman, a young or an old voice, an accent.
  • Pitch: a deep voice or a high voice.
  • Recording quality: very clear or noisy, like an old phone call.
  • Room: a small quiet room or a big hall with echo.
  • Manner: calm like a news reader, or lively like a storyteller.

All of these work in the same way as speed and emotion. When a quality is written into the training descriptions, the model learns it, and we can ask for it in plain words.

For example, the description "A man with a deep voice speaks in a calm, slow way. The recording is very clear." asks for a style, a speed, and a quality, all in one sentence.

Parler-TTS also allows the description to name one of the speakers from its training data, for example "Jon speaks calmly." This helps us keep the voice more consistent across runs.

Note: Newer LLM-based TTS models also accept an "instructions" field, such as "Speak like a friendly customer support agent." Here, the instruction is usually placed in the same input sequence as the transcript, but the idea is the same: the instruction guides every audio token the model predicts.

If we want to go deep into Multimodal Generative Models and how to Design a Real-Time Voice AI Agent from the ground up, we have a complete program on it - check out our AI and Machine Learning Program at Outcome School.

Where it works well and where it fails

Now, let's see where this approach works well and where it fails.

Where it works well:

  • Asking for broad things like "fast", "slow", "high pitch", "clear recording", or "noisy".
  • Creating many different voices without recording a new speaker for each one.
  • Building audiobooks, games, and assistants where the tone must change from line to line.

Where it fails:

  • Rare requests: If a style was rare in training, like "sarcastic" or "speaks like a pirate", the model often ignores it or gets it only partly right.
  • Exact control: "Speak at exactly 150 words per minute" does not work well, because the model learned buckets like "fast", not exact numbers. This is why many TTS products also offer a separate speed setting outside the prompt.
  • Mixed signals: If the transcript is sad but the description says happy, the voice and the words do not match, and the result sounds unnatural.
  • Same prompt, different voice: Each run can produce a slightly different voice, because the model picks tokens with some randomness. Naming a known speaker helps with this.
  • Control inside a sentence: It is hard to say "whisper only the last word" with one description for the whole sentence.

We have a detailed blog on how SSML gives exact control over pauses, speed, and pitch that covers this end to end.

Now we must have understood how a TTS model controls emotion, speed, and style from a text prompt, how it learns from automatically written descriptions, and where it works well and where it fails.

Frequently Asked Questions

Does a TTS model speak the description out loud?

No. The description only shapes the voice, and the model never speaks it. In Parler-TTS, the description goes through a text encoder and the decoder looks at it at every step with cross attention, while the transcript is placed at the start of the decoder's own sequence. This separation, together with training on real recordings, makes the model speak only the transcript.

Can a text prompt set an exact speaking speed?

No. A request like "Speak at exactly 150 words per minute" does not work well, because the model learned word buckets like "fast" or "very slowly", not exact numbers. Speed comes from how long the model stays on each sound. This is why many TTS products also offer a separate speed setting outside the prompt.

Why does the same text prompt give a slightly different voice each time?

Because the model picks each audio token with some randomness, so each run can produce a slightly different voice. Parler-TTS allows the description to name one of the speakers from its training data, for example "Jon speaks calmly." Naming a known speaker like this helps keep the voice more consistent across runs.

Can a TTS model follow words that were not in its training descriptions?

Often, yes. A trained text encoder already knows that words like "quickly" and "fast" mean almost the same thing, so the model can often follow a description that uses new words. But if a style was rare in training, like "sarcastic" or "speaks like a pirate", the model often ignores it or gets it only partly right.

That's it for now.

Thanks

Amit Shekhar
Founder @ Outcome School

You can connect with me on:

Follow Outcome School on:

Read all of our high-quality blogs here.