TTS Architectures

Two seconds of speech once took Tacotron 2 and WaveNet 48,160 steps, one after another. VITS makes the same two seconds in one parallel pass.

Pick a system and press Speak. Watch how the text becomes frames and the frames become sound. Then we build each part from zero: the frontend, the mel, attention, the vocoder, durations, sampling, and codec tokens.

You need a little Python and the idea that sound is a list of numbers. We build the rest from zero.

Numbers come from the papers: Tacotron 2 (Shen et al., 2018), FastSpeech 2 (Ren et al., 2021), HiFi-GAN (Kong et al., 2020), VITS (Kim et al., 2021) and VALL-E (Wang et al., 2023). Links are in the field guide.

Speak one sentence four ways

2 s

Step counts use each paper's settings: Tacotron 2 makes 80 mel frames per second and its WaveNet makes 24,000 samples per second, one at a time; VALL-E makes 75 first-codebook tokens per second, then 7 parallel passes. The animation speed is illustrative.

Chapter 0

Why Speaking Is Hard for a Machine

Count how much sound one short sentence needs, and find the three problems every TTS system must solve

Type "the cat sat on the mat." That is 22 characters. A person says it in about two seconds. At a sample rate of 22,050 numbers per second, those two seconds are 44,100 numbers. A text-to-speech (TTS) system is a program that turns the 22 characters into the 44,100 numbers.

Three problems sit inside that job.

  1. The rate gap. Text is short and audio is long. Each character must become about 2,000 numbers.
  2. Alignment. Which sound goes with which letter, and for how long? A vowel can last four times as long as the consonant beside it. A pause has no letter at all.
  3. One-to-many. One sentence has many correct readings: fast or slow, rising or falling. There is no single right waveform to copy.

Measure the rate gap

Each bar counts one kind of unit on a log scale, so each grid line is ten times the last. Drag the length of speech.

2 s

Mel frames and samples use the LJSpeech setup (22,050 Hz, hop 256). The speaking rates of 11 characters and 10 phonemes per second are illustrative.

The gap is about three powers of ten. No single layer bridges it well. So the field splits the job into stages and adds a middle picture of sound, the mel spectrogram. Every system in this lesson is a different answer to the three problems.

The road

  1. Two stages and the mel: frame rate, hop size and the tensor shapes.
  2. The text frontend: from "$2.50" to phonemes.
  3. Tacotron 2 and attention: the diagonal, and how it breaks.
  4. The vocoder: from 256 samples per frame to a waveform, and why GANs won.
  5. FastSpeech 2 and durations: alignment stated, not guessed.
  6. The one-to-many problem: why averaging makes speech flat.
  7. VITS, end to end: alignment search and sampling in one model.
  8. Codec-token TTS: VALL-E speaks in tokens and clones a voice from 3 seconds.
  9. The field guide: numbers, code and links.
Which of these is NOT one of the three core problems of TTS?

Chapter 1

Two Stages and the Mel Spectrogram

Split text-to-audio at the mel, and compute how many frames and samples each stage makes

The classic design has two stages. The acoustic model turns phonemes into a mel spectrogram. The vocoder turns the mel spectrogram into audio samples. The mel is the meeting point.

A mel spectrogram is a grid: one column per short slice of time, one row per frequency band. Each column is a mel frame. Tacotron 2, FastSpeech 2 and HiFi-GAN all use 80 bands. The frames overlap. The step from one frame to the next is the hop size, counted in samples.

How many frames does one second of speech make? Call the sample rate s, in samples per second. Call the hop size h, in samples. Call the frame rate f, in frames per second.

Say it aloud

f equals s divided by h.

f
f the frame rate: mel frames per second of audio.
s
s the sample rate: audio numbers per second, such as 22,050.
h
h the hop size: samples between the starts of two frames, such as 256.
/
divided by how many hops fit in one second.
In plain words

Take one second of samples, s of them. Step through them h samples at a time. Each step starts a new frame, so you get f frames.

With numbers

LJSpeech setup: s = 22,050 and h = 256, so f = 86.1 frames per second, one every 11.6 ms. Tacotron 2: s = 24,000 and a 12.5 ms hop, so h = 300 and f = 80.

Follow the shapes down the pipeline

Each box shows the tensor that leaves a stage. Pick a setup and a length, and watch one mel frame open into its samples.

2 s

Sample rates and hops come from the FastSpeech 2 and Tacotron 2 papers. The 10 phonemes per second is illustrative.

Why split here? The acoustic model works at 86 steps per second and decides what to say and how. The vocoder works at 22,050 steps per second and decides how it sounds. A good vocoder works for many acoustic models.

The failure: a mismatched hop

Symptom: the voice sounds sped up, slowed down or garbled. Measure: compare the hop and sample rate in the acoustic model's config with the vocoder's. Fix: train both on mels made with the same settings. A vocoder trained on hop 256 reads hop 300 frames at the wrong speed.

Audio is 16,000 samples per second and the hop is 200 samples. How many mel frames does one second make?

Chapter 2

The Text Frontend

Turn messy text into words a person would say, then into the sounds those words make

Your TTS reads a receipt: "Dr. Smith paid $2.50." If it reads the symbols as written, it says "D R dot Smith paid dollar two point five oh." The voice can be perfect and the speech still wrong. The text frontend is the code that runs before any neural network and fixes this. It has two jobs.

  1. Normalization writes every number, date, unit and short form as spoken words. "$2.50" becomes "two dollars and fifty cents".
  2. Grapheme-to-phoneme (G2P) turns letters into phonemes, the smallest sounds of a language. "smith" becomes S M IH TH.

Run the frontend on hard inputs

Pick an input. The rows show the raw text, the spoken words, then the phonemes. Words that changed light up.

Phonemes are ARPAbet symbols, the set the CMU Pronouncing Dictionary uses, with stress marks left out. The rules are a toy, not a real frontend.

Why phonemes and not letters? English spelling is irregular. "Through", "though" and "tough" share four letters and end in three different sounds. A model fed letters must learn those rules from data, and it fails on rare names.

Fed phonemes, it can spend its capacity on rhythm and voice. FastSpeech 2 and VITS take phonemes from a G2P tool. Tacotron 2 takes raw characters and learns spelling from 24.6 hours of one speaker.

Some words need context. "Read" is R IY D in "I read it now" and R EH D in "I read it yesterday". "St." is "Saint" before a name and "Street" after one. A homograph is a word with one spelling and two pronunciations, and the frontend must guess from the sentence around it.

The failure: a wrong expansion

Symptom: clean audio that says the wrong words, such as "three slash four" for a date. Measure: run a test list of numbers, dates and short forms and compare the words with a human reading. Fix: add a rule or a context model for that class, then rerun the list.

Why do most TTS systems turn text into phonemes before the acoustic model?

Chapter 3

Tacotron 2 and the Attention Diagonal

Let attention decide which input to voice at each frame, and see how it skips and repeats

Tacotron 2 is a sequence-to-sequence model, built like a translation model. An encoder reads the characters and gives one vector per character. A decoder writes the mel one frame at a time, and each frame depends on the one before it. That makes it autoregressive.

At every frame the decoder must pick which characters it is voicing now. It does this with attention. Call the encoder vector for input j hj. At output frame i, attention gives each input a weight αij. The weights are positive and add to 1. The decoder reads one blend of the inputs, the context vector ci.

Say it aloud

c-i equals the sum over j of alpha-i-j times h-j.

ci
c-i the context vector the decoder reads at output frame i.
Σj
the sum over j add one term for each input character j.
αij
alpha-i-j the attention weight: how much frame i looks at input j. The weights for one frame add to 1.
hj
h-j the encoder vector for input j, 512 numbers in Tacotron 2.
In plain words

For frame i, scale each encoder vector h-j by its weight alpha-i-j. Add the scaled vectors. The sum c-i says what to voice now.

With numbers

With made-up numbers, one feature of three inputs: h = 1.0, 4.0, −2.0 and weights 0.1, 0.7, 0.2. Then c = 0.1 + 2.8 − 0.4 = 2.5. The frame mostly voices input 2.

Speech moves left to right. So if you plot the weights, inputs on one axis and frames on the other, a healthy model draws a clean diagonal. Tacotron 2 uses location-sensitive attention: it also sees where it looked before, which pushes it to keep moving forward.

Break the diagonal

Bright cells are high attention. Drag stability down and press New run to see the decoder stall and jump.

0.95

An illustrative toy: each frame the focus moves forward, stalls or jumps at random. Real failures come from the learned weights.

The decoder also decides when to stop. A small output, the stop token, gives the chance that speech is over. Generation ends at the first frame where it passes 0.5. On real data Tacotron 2 scored a mean opinion score of 4.53 against 4.58 for the recordings (Table 1 of the paper).

The failure: skips, repeats and babble

Symptom: a word said twice, a word missing, or noise after the sentence ends. Measure: plot the attention map and look for flat runs, gaps and a smeared tail. Fix: location-aware attention helps; the full fix is to remove learned attention at inference, which Chapter 5 does.

Why does a healthy Tacotron 2 attention map look like a diagonal?

Chapter 4

The Vocoder

Stretch each mel frame into hundreds of samples, and see why a parallel GAN beat a sample-by-sample model

The acoustic model hands over 86 mel frames per second. The speaker needs 22,050 samples per second. The vocoder fills the gap: every frame must become exactly one hop of samples.

Call the number of mel frames T. Call the hop size h. Call the number of output samples N.

Say it aloud

N equals T times h.

N
N the number of audio samples the vocoder writes.
T
T the number of mel frames it reads.
h
h the hop size: samples per frame, 256 here.
×
times each frame owns h samples.
In plain words

Give every mel frame its own block of h samples. Count the blocks, T of them. The vocoder must fill N samples.

With numbers

T = 100 frames and h = 256 give N = 25,600 samples, or 1.16 s at 22,050 Hz. HiFi-GAN stretches time in four layers by 8, 8, 2 and 2, and 8 × 8 × 2 × 2 = 256 = h.

The first neural vocoder, WaveNet, writes one sample at a time, each from the samples before it. Quality is high, but N samples need N steps in a row. HiFi-GAN writes all N at once. A transposed convolution is a layer that stretches a sequence in time, and four of them grow the mel to full length. A GAN trains the generator against critics that try to tell its audio from real audio, so it learns to sound crisp.

Race two vocoders

Top: one frame grows through four upsampling layers. Bottom: the time each vocoder needs, on a log scale. Drag the clip length.

1 s

Speeds from HiFi-GAN Table 1, on one V100 GPU at 22.05 kHz: WaveNet (MoL) makes 0.07 kHz, HiFi-GAN V1 makes 3,701 kHz. The layer factors 8, 8, 2, 2 are from the released V1 config.

The table in the HiFi-GAN paper gives HiFi-GAN V1 a mean opinion score of 4.36, WaveNet 4.02, and the recordings 4.45. It was faster and better at once. That is why parallel vocoders took over.

The failure: metallic buzz

Symptom: a buzzy, metallic voice from a vocoder that sounded clean in tests. Measure: feed it the acoustic model's predicted mels and compare with real mels. Fix: fine-tune the vocoder on predicted mels, as Tacotron 2 did for its WaveNet.

Why did GAN vocoders like HiFi-GAN replace WaveNet in production?

Chapter 5

FastSpeech 2: State the Durations

Predict how many frames each phoneme lasts, copy it that many times, and make every frame at once

Tacotron 2 found the alignment one frame at a time. FastSpeech 2 states it up front. A duration predictor reads each phoneme and says how many mel frames it lasts. A length regulator copies each phoneme's vector that many times. A non-autoregressive decoder then writes every frame in one parallel pass.

Call the predicted duration of phoneme i di, in frames. Call the total number of frames T.

Say it aloud

T equals the sum over i of d-i.

T
T the number of mel frames in the output.
Σi
the sum over i add one term for each phoneme i.
di
d-i the duration of phoneme i: a whole number of frames, at least 1.
In plain words

Copy phoneme i's vector d-i times. Lay the copies end to end. The row has T frames, so the decoder knows the length before it starts.

With numbers

With made-up durations for "cat": K 5, AE 12, T 4. Then T = 21 frames, or 244 ms at 11.6 ms per frame.

Speed is now one knob. Multiply every duration by a scale α and round. At α = 0.8, "cat" becomes 4, 10 and 3 frames: 17 frames, 197 ms. At α = 1.5 it becomes 8, 18 and 6: 32 frames, 372 ms.

Expand phonemes into frames

Each phoneme's colour block is its run of copies. Drag the duration scale to slow down or speed up the word.

1.00

The durations 5, 12 and 4 are illustrative. Frame length is 11.6 ms, from hop 256 at 22,050 Hz.

Where do training durations come from? FastSpeech took them from a teacher Tacotron model. FastSpeech 2 uses the Montreal Forced Aligner, a tool that finds where each phoneme starts and ends in a recording. Its variance adaptor also predicts pitch and energy per frame. Training took 17 hours against 53 for FastSpeech, and both generate about 48 times faster than an autoregressive Transformer TTS (Table 2).

The failure: robotic rhythm

Symptom: every word clear, but the rhythm feels mechanical. Measure: compare predicted durations with the aligner's durations on held-out speech. Fix: better aligner labels, and pitch and energy predictors, as FastSpeech 2 added. No skips or repeats can happen, because every phoneme gets at least one frame.

How does FastSpeech 2 avoid the skip and repeat failures of Tacotron 2?

Chapter 6

The One-to-Many Problem

See why a model trained to minimise error predicts the average reading, and why the average sounds flat

Say "you're coming?" twice. Once the pitch rises at the end, as a question. Once it falls, as surprise. Both are correct. A dataset holds many such readings of similar text, each with its own prosody: the pitch, rhythm and stress of speech.

Now train with mean squared error (MSE), the average of the squared gaps between prediction and target. Call the K correct readings of one point in the sentence y1 to yK. The single prediction that gives the lowest MSE is ŷ.

Say it aloud

y-hat equals one over K, times the sum over k of y-k.

ŷ
y-hat the prediction with the lowest squared error.
1/K
one over K divide by the number of correct readings.
Σk
the sum over k add one term for each reading k.
yk
y-k the pitch of reading k at this point, in hertz.
In plain words

Add up the pitch of every correct reading y-k. Divide by K. The squared-error winner y-hat is the plain average.

With numbers

With made-up pitches: a rising reading goes 200, 220, 240, 260 Hz and a falling one goes 260, 240, 220, 200 Hz. The average is 230 Hz at every point: a flat line. Its MSE is 500, half that of guessing either real reading.

Average the readings, or sample one

Faint lines are correct readings. Pick what the model outputs. Press Resample to draw a new reading.

Illustrative contours: half rise, half fall, each with its own random wiggle.

The cure is to make the model generative: let it draw one reading from the spread of correct readings. Each method adds randomness in its own way. A VAE samples a hidden code. A normalizing flow turns simple noise into a detailed sample. Diffusion removes noise step by step. Each output commits to one lively reading.

The failure: flat, tired speech

Symptom: clear words with a monotone melody. Measure: compare the spread of pitch across many outputs with the spread in real speech. Fix: add a source of randomness, or feed the true pitch in training as FastSpeech 2 does.

Why does a TTS model trained only with mean squared error sound flat?

Chapter 7

VITS: Alignment Search and Sampling in One Model

Find the best monotonic alignment with a small table, then generate a waveform straight from text

VITS goes from phonemes straight to a waveform, with no separate vocoder. Four parts do the work:

  1. A VAE encodes real audio into a hidden code z in training.
  2. A normalizing flow links z to the text, so the model can sample z from text alone.
  3. A stochastic duration predictor samples durations, so the rhythm varies.
  4. A GAN decoder turns z into samples, as HiFi-GAN does.

Where do durations come from without an aligner? VITS finds them itself with monotonic alignment search (MAS), taken from Glow-TTS. Build a table with phonemes down the side and frames along the top. Call the score that frame j belongs to phoneme i L[i, j]. Call the best total score of any path that ends at that cell Q[i, j]. A path may only stay on its phoneme or move down one.

Say it aloud

Q of i, j equals L of i, j, plus the max of Q of i minus 1, j minus 1, and Q of i, j minus 1.

Q[i, j]
Q of i, j the best total score of a path that puts frame j on phoneme i.
L[i, j]
L of i, j the log-likelihood that frame j belongs to phoneme i. Higher is better; it is never above 0 here.
max
the max of keep the larger of the two ways in.
Q[i−1, j−1]
Q of i minus 1, j minus 1 the path moved on from the previous phoneme.
Q[i, j−1]
Q of i, j minus 1 the path stayed on the same phoneme.
In plain words

Fill the table one frame column at a time. For each cell, take the better of "stay" and "move on", and add the cell's own score L. Then walk back from the last cell to read the path.

With numbers

With the made-up table in the device: Q[0, 1] = −1 + −1 = −2, and Q[1, 2] = −1 + max(−2, −4) = −3. The best path ends at −6 and gives each of the 3 phonemes 2 frames.

Run monotonic alignment search

Each cell shows L on top and Q below once filled. Press Step to fill one cell, or Run to finish and trace the path.

The scores are a toy. The fill and backtrack follow the MAS pseudocode in the VITS paper, Appendix A.

The path gives each phoneme its frame count, and those counts train the duration predictor. On LJSpeech, VITS scored a mean opinion score of 4.43, against 4.46 for the recordings and 4.25 for Tacotron 2 with a fine-tuned HiFi-GAN (Table 1). It generated audio 67 times faster than real time on one V100 (Table 4).

The failure: mumbled words

Symptom: a word blurs into its neighbour. Measure: plot the MAS path for that clip and look for a phoneme with one frame. Fix: check the frontend's phonemes first; a wrong phoneme cannot align well.

In the MAS table, which two cells can lead into cell Q[i, j]?

Chapter 8

Codec-Token TTS and Voice Cloning

Turn audio into tokens, let a language model continue a 3-second prompt, and count the tokens it writes

A neural audio codec compresses audio into a grid of small integers. VALL-E uses EnCodec at 24 kHz. It makes 75 frames per second. Each frame has 8 tokens, one from each of 8 codebooks of 1,024 entries. The first codebook carries the coarse sound; each later one fixes what the earlier ones missed.

Call the codec frame rate r, in frames per second. Call the number of codebooks q. Call the length of the audio t, in seconds. Call the number of tokens n.

Say it aloud

n equals r times q times t.

n
n the number of codec tokens for the clip.
r
r the codec frame rate: 75 frames per second for EnCodec at 24 kHz.
q
q the number of codebooks: 8 in VALL-E.
t
t the length of the audio in seconds.
In plain words

Count the frames, r for each of the t seconds. Give every frame q tokens. Multiply to get n.

With numbers

A 3-second prompt: n = 75 × 8 × 3 = 1,800 tokens. Each token picks 1 of 1,024 entries, which is 10 bits, so the rate is 75 × 8 × 10 = 6,000 bits per second.

VALL-E splits generation in two. An autoregressive (AR) Transformer writes the first-codebook tokens one at a time, from the phonemes and the prompt's tokens. A non-autoregressive (NAR) Transformer then fills codebooks 2 to 8, one whole row per pass. The codec's decoder turns the grid back into a waveform.

Continue a voice prompt in tokens

Pink columns are the 3-second prompt from the target speaker. Press Generate and watch row 1 grow token by token, then rows 2 to 8 fill a row at a time.

4 s

The codec settings and the AR then NAR split are from the VALL-E paper; the grid draws one column for every 5 codec frames.

Why does the voice match? The language model continues the prompt's tokens, and those tokens carry the speaker's timbre and the room. Trained on 60,000 hours of LibriLight, VALL-E cut word error rate from 7.7 to 5.9 and raised speaker similarity from 0.337 to 0.580 against YourTTS (Table 2). Diffusion and flow-matching models such as Voicebox take another route to the same goal: they denoise a mel or a latent instead of writing tokens.

The failure: the LM loses its place

Symptom: a cloned voice that repeats a word or trails off, as Tacotron 2 did. Measure: transcribe the output with an ASR model and compute word error rate. Fix: sample several outputs and keep the one with the lowest error.

VALL-E generates 4 seconds of speech. How many steps does its autoregressive stage take?

Chapter 9

The Field Guide

Keep the numbers, the checklist and the core code in one place

A TTS system cleans text into phonemes, decides how long each phoneme lasts, samples one lively reading, and writes samples. The systems differ in how they align and how many steps they take in order.

SystemAlignmentSteps in order for 2 sVarietyReported MOS
Tacotron 2 + WaveNetlearned attention160 frames, then 48,000 sampleslittle4.53 (recordings 4.58)
FastSpeech 2 + vocoderdurations from MFA1 pass, then 1 passpitch and energy inputs3.83 (Tacotron 2: 3.70)
HiFi-GAN V1 (vocoder)none needed1 passnone4.36 (recordings 4.45)
VITSMAS in training1 passflow and stochastic durations4.43 (recordings 4.46)
VALL-Eimplicit in the LM150 tokens, then 7 passessampling; 3 s cloningSMOS 4.38 (YourTTS 3.45)

Each MOS comes from its own paper's listening test, so compare within a row, not across rows. FastSpeech 2 rated all systems through the same Parallel WaveGAN vocoder, which is why its numbers sit lower.

Checklist

  1. Run a test list of numbers, dates and short forms through the frontend.
  2. Check that the acoustic model and vocoder share sample rate, hop and mel bands.
  3. Plot alignments for a few clips: look for flat runs and gaps.
  4. Measure the pitch spread of outputs against real speech.
  5. Transcribe outputs with ASR and track word error rate.

The core, as code

pythonimport numpy as np

def length_regulate(h, d, alpha=1.0):        # h: [P, D] phoneme vectors, d: [P] frames
    d = np.maximum(1, np.round(alpha * np.asarray(d))).astype(int)
    return np.repeat(h, d, axis=0)              # [T, D], T = d.sum()

def mas(L):                                        # L: [P, T] log-likelihoods
    P, T = L.shape; Q = np.full((P, T), -np.inf)
    for j in range(T):
        for i in range(max(0, P + j - T), min(P, j + 1)):
            if j == 0: Q[i, j] = L[i, j]; continue
            move = Q[i - 1, j - 1] if i else -np.inf
            Q[i, j] = L[i, j] + max(move, Q[i, j - 1])
    path, i = [0] * T, P - 1
    for j in range(T - 1, -1, -1):
        path[j] = i
        if i and (i == j or Q[i, j - 1] < Q[i - 1, j - 1]): i -= 1
    return np.bincount(path, minlength=P)      # durations per phoneme

frames_per_s = 22050 / 256                          # f = s / h = 86.1
codec_tokens = 75 * 8 * 3                           # n = r * q * t = 1800

Keep going

Sources

The takeaway. TTS moved from guessing the alignment one frame at a time to stating it, and from writing samples one at a time to writing them all at once. Sampling, not averaging, is what makes the voice sound alive.

Now press Present or Teach and explain the pipeline from memory: frontend, mel, alignment, vocoder, sampling. Then go back to the hero and speak the sentence four ways. Say which chapter explains each step count.

TTS Architectures
Back to Gleams