Skip to content

Text to speech: from Tacotron to Grad-TTS

Text-to-speech acoustic models turn text into a mel spectrogram. Follow the line from attention decoders (Tacotron 2, Transformer TTS) to duration-based parallel models (FastSpeech 1 and 2) and generative ones (Glow-TTS, Grad-TTS).

Advanced ~18 min11 steps

What runs in CodeSplash

You will be able to

  • Describe the two stages of classic TTS and what passes between them
  • Explain the stop token and the attention failures of autoregressive TTS
  • Build a length regulator and explain what FastSpeech 2's variance adaptor adds
  • Explain why one text has many valid renditions, and how flows and diffusion model that

Read first

01

Two stages

Read

Classic text to speechText to speechTurning text into speech, often in two stages: an acoustic model predicts a mel spectrogram, then a vocoder makes the waveform. splits the job. An acoustic model turns text, usually converted to phonemes, into a mel spectrogram. A vocoder turns the mel spectrogram into a waveform (the vocoder lesson). The mel spectrogram in the middle is a contract: both stages must use the same settings.

Splitting helps diagnosis. If the words are wrong or garbled, look at the acoustic model and its alignment; if the words are right but the sound buzzes, look at the vocoder.

02

Tacotron 2: attention writes frames

Read

Tacotron 2 encodes the characters, then a recurrent decoder writes mel frames one at a time, attending to the text to decide which character it is saying. Each frame also predicts a stop tokenStop token (TTS)A per-frame prediction that the utterance ends here, in autoregressive TTS. Without it the decoder doesn't know when to stop.: the probability that the utterance ends there. Training adds a mel error and a stop error; on the reference's toy numbers that loss is 0.0298. A WaveNet vocoder rendered the mels.

Attention is the weak point. When it slips, the voice skips words, repeats them or mumbles, and a missed stop token lets it babble on.

Reference · AUD018 · Explained hereTacotron 2A supervised text-to-speech system combining an attention-based recurrent mel-spectrogram predictor with a separately trained waveform vocoder.
03

Transformer TTS

Read

Transformer TTS replaces the recurrent layers with Transformer blocks: self-attention over the text in the encoder, and over earlier frames in the decoder, with cross-attention between them. Training runs in parallel over all frames thanks to teacher forcing. Generation is still autoregressive: one frame after another, so it is slow and can still lose its alignment.

The reference's example uses an L1 mel error plus a stop error: 0.116. Don't confuse it with the duration-based models below, which also use Transformer blocks but generate in parallel.

Reference · AUD019 · Explained hereTransformer TTSA supervised speech synthesis architecture replacing recurrent sequence modeling with attention-based Transformer components. The original design predicts acoustic frames autoregressively;
04

FastSpeech: say how long, then decode at once

Read

FastSpeech drops attention at generation time. A duration predictorDuration predictorPredicts how many frames each phoneme lasts. A length regulator repeats each phoneme state that often, so decoding runs in parallel. guesses how many frames each phoneme lasts, and a length regulator repeats each phoneme's vector that many times. The decoder then produces every frame at once:

Python
import numpy as np
states = np.array([[1.0, 0.0], [0.0, 1.0], [0.5, 0.5]])  # one vector per phoneme
durations = np.array([2, 1, 3])                          # frames per phoneme
frames = np.repeat(states, durations, axis=0)            # the length regulator
print(frames.shape, frames[:, 0])
R
states <- rbind(c(1, 0), c(0, 1), c(0.5, 0.5))            # one vector per phoneme
durations <- c(2, 1, 3)                                    # frames per phoneme
frames <- states[rep(seq_len(nrow(states)), times = durations), ]  # the length regulator
print(dim(frames)); print(frames[, 1])

Three phonemes become six frames. Original FastSpeech learned durations from a teacher Tacotron's attention and trained on that teacher's spectrograms.

Reference · AUD020 · Explained hereFastSpeechA supervised nonautoregressive TTS model using predicted phoneme durations and a length regulator to expand text representations into acoustic time.
05

One text, many voices

Predict

Predict first

The same sentence can be spoken with many pitch contours and rhythms. A model trained only to minimize the squared error of mel frames sees all of them. What does it tend to produce?

Lively, varied speechFlat, averaged-sounding speechSpeech in a random voice
Reveal

Flat, averaged-sounding speech. The squared error is smallest at the mean of all renditions, and the mean of many pitch contours is a dull one. TTS models fix this by conditioning on more information (FastSpeech 2) or by modeling the distribution (Glow-TTS, Grad-TTS).

06

FastSpeech 2: pitch and energy

Read

FastSpeech 2 adds a variance adaptorVariance adaptorAdds predicted duration, pitch and energy to phoneme states before decoding (FastSpeech 2), so one text can be spoken different ways.: besides duration, it predicts pitch and energy for each phoneme and adds them to the phoneme vectors before decoding. In training it uses the true values, from a forced aligner and pitch tracking; at generation, its own predictions, which you can also edit to change the prosodyProsodyThe rhythm, stress, pitch and loudness pattern of speech. The same words can be said with very different prosody..

It trains on real recordings instead of a teacher's output. Its loss sums mel, duration, pitch and energy terms; on the reference's toy numbers, 1.339.

Reference · AUD021 · Explained hereFastSpeech 2A nonautoregressive supervised TTS model that adds explicit duration, pitch, and energy conditioning while learning directly from target acoustic data.
07

Glow-TTS: a flow with a found alignment

Read

Glow-TTS models the mel spectrogram with a normalizing flowNormalizing flowA stack of invertible layers that turns each row into normal noise, so noise run backwards gives new rows and likelihoods are exact., so it gets an exact likelihood by the change of variables:

log⁡p(M∣c)=log⁡pZ(fθ(M);c)+log⁡∣det⁡Jfθ(M)∣.\log p(M \mid c) = \log p_Z\bigl(f_\theta(M); c\bigr) + \log \bigl|\det J_{f_\theta}(M)\bigr|.

Which frames belong to which phoneme? Monotonic alignment searchMonotonic alignment searchFinds the best left-to-right match of text tokens to spectrogram frames by dynamic programming, with no outside aligner. finds the best left-to-right match by dynamic programming during training, so no outside aligner or teacher is needed. The reference's one-number example of the flow's log density gives −0.546.

Reference · AUD022 · Explained hereGlow-TTSA supervised text-to-spectrogram generator using an invertible flow and monotonic alignment search. It combines likelihood-based acoustic modeling with automatically selected monotone text–frame alignments, enabling…

Coupling layers and the change of variables, in two dimensions.

DExplorable · Normalizing flows: change of variables

Why does a normalizing flow need the log-determinant of its Jacobian?

Does the flow's density, as computed here, integrate to 1?

How sure?
3
0.50

How much each layer stretches: s(y) = α·tanh(u·y + v).

1.00

How much each layer bends: t(y) = β·sin(w·y) + c·y.

0.50
−0.50
Simulating…

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

08

Grad-TTS: diffusion for the spectrogram

Read

Grad-TTS generates the mel spectrogram with a diffusion modelDiffusion modelLearns to reverse a gradual noising process, then generates by starting from pure noise and denoising in steps.. A text encoder and duration model give a rough, phoneme-aligned average; a score network then refines noise into a detailed spectrogram over several steps, conditioned on the text. More steps give finer detail and take longer.

Training matches the network's output to a known target for each noise level; the reference's surrogate of that error is 0.0051. Grad-TTS shows that the generator families from the deep-learning tracks drop straight into the acoustic-model slot.

Reference · AUD023 · Explained hereGrad-TTSA supervised TTS system generating mel spectrograms through a text-conditioned diffusion process. A text encoder, duration/alignment mechanism, and score-based decoder separate linguistic conditioning from iterative…

The noising and sampling loop on a simple one-dimensional target.

DExplorable · Diffusion: noise schedule, sampler steps, guidance

How does a diffusion model turn noise back into data, and what do the schedule, the steps and guidance change?

With this sampler and number of steps, will the samples match the data?

How sure?

β schedule

250

The forward process at this step: how much signal is left.

Sampler

DDPM adds fresh noise every step; DDIM is deterministic.

50
0.0

0 = unconditional, 1 = plain conditional, above 1 = guided.

Class to guide toward

400
  • Noised samples
  • Exact q(xₜ)
  • Samples
  • Data

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

09

Where it stands in CodeSplash

Read
EntryIn CodeSplash
Tacotron 2 (AUD018)Explained here
Transformer TTS (AUD019)Explained here
FastSpeech (AUD020)Explained here
FastSpeech 2 (AUD021)Explained here
Glow-TTS (AUD022)Explained here
Grad-TTS (AUD023)Explained here

CodeSplash doesn't synthesize speech, and no method is planned. The reference programs are component checks, verified in Python and R: loss terms and the length regulator, not trained voices.

10

Check: acoustic models

Checkpoint

Check yourself

What does Tacotron 2's stop token do?

Show the answer

Answer: b

An autoregressive decoder has no fixed output length. Without a working stop prediction it runs on.

Check yourself

A Tacotron-style voice sometimes skips a word or repeats one. Where do you look first?

Show the answer

Answer: a

Skips and repeats are alignment failures: attention jumped over or back across the text. Buzzing sound, by contrast, points at the vocoder.

Check yourself

Transformer TTS trains in parallel. Why is generation still slow?

Show the answer

Answer: b

Teacher forcing parallelizes training; generation stays autoregressive.

Check yourself

A length regulator gets four phonemes with predicted durations 3, 1, 4 and 1 frames. How many frames does the decoder see?

Show the answer

Answer: 9

3+1+4+1=93 + 1 + 4 + 1 = 9: each phoneme's vector is repeated its duration's number of times.

Check yourself

Where did the original FastSpeech get its training durations, and what did FastSpeech 2 change?

Show the answer

Answer: b

Learning from the teacher limited FastSpeech to the teacher's quality. FastSpeech 2 learns from the data directly and adds pitch and energy.

Check yourself

What problem does FastSpeech 2's variance adaptor address?

Show the answer

Answer: b

Given pitch and energy, the remaining choices are fewer, so the decoder no longer averages over very different renditions.

Check yourself

How does Glow-TTS learn which frames belong to which phoneme?

Show the answer

Answer: c

The search keeps alignment monotonic, which rules out the skips and repeats attention can make.

Check yourself

What does Glow-TTS's flow give that a plain squared-error decoder doesn't?

Show the answer

Answer: a

The change of variables gives an exact log-likelihood; sampling the latent gives different renditions of one text.

Check yourself

What is the main cost of Grad-TTS's diffusion decoder compared with FastSpeech?

Show the answer

Answer: b

Diffusion trades speed for detail: more steps, finer spectrograms, longer generation.

Check yourself

In a two-stage TTS system, which part does Grad-TTS replace?

Show the answer

Answer: b

Grad-TTS generates mel spectrograms; a separate vocoder still makes the waveform.

11

Recap

Recap
  • Classic TTS: an acoustic model writes a mel spectrogram, a vocoder makes the waveform.
  • Tacotron 2 and Transformer TTS write frames one by one with attention and a stop token; alignment can slip.
  • FastSpeech predicts durations and decodes in parallel; FastSpeech 2 adds pitch and energy.
  • Glow-TTS (flow plus alignment search) and Grad-TTS (diffusion) model many renditions. All are explained here.

Concepts in this lesson