Search

Search papers and lessons

Natural TTS Synthesis by Conditioning WaveNet on Mel Spectrogram Predictions

Jonathan Shen, Ruoming Pang, Ron J. Weiss et al. · 2017

Tacotron 2 turns text into speech with two neural networks: one predicts a mel spectrogram from characters, and a WaveNet turns that spectrogram into audio, scoring close to human speech.

On this page

  • Colour = topic mix
  • Architectures
  • Calculus
  • Discrete math
  • Linear algebra
  • Neural network basics
  • Signal processing
  • ReadReady to readNot yet

TL;DR

Tacotron 2 is a text-to-speech system built entirely from neural networks trained on pairs of text and recorded speech. Its first network reads characters and predicts a mel spectrogram, a compact picture of the sound with one column every 12.5 milliseconds. Its second network, a modified WaveNet, turns that picture into a waveform. Human raters scored its speech 4.53 out of 5, close to the 4.58 they gave recorded human speech.

Builds on: WaveNet, Encoder-Decoder Architecture, Attention Mechanism, Mel Spectrogram, Teacher Forcing · Leads to: HiFi-GAN: Generative Adversarial Networks for Efficient and High Fidelity Speech

Why it mattered

Before this paper, the most natural-sounding systems, WaveNet among them, needed hand-built inputs: linguistic features, pronunciation lexicons and phoneme durations, all produced by a text-analysis pipeline that took a lot of expertise to build. Tacotron 2 showed that one trained system could replace that pipeline and still produce speech that listeners rated close to a human speaker. Its two-stage shape, a sequence model that predicts a spectrogram followed by a neural vocoder, is the one many later neural speech systems follow.

The evaluation is the reason to take the claim seriously. Raters scored the system on a 1 to 5 scale, at least eight ratings per sample, on 100 test sentences. The result, 4.526 with a 95 percent interval of plus or minus 0.066, sits next to 4.582 for the ground truth recordings.

The problem

Speech synthesis had improved in three steps, and each left a gap.

Concatenative synthesis stitches short pre-recorded pieces of speech together. It sounded natural in its own recordings, but the joins between pieces produced audible artifacts. Statistical parametric synthesis generates smooth trajectories of speech features and passes them to a vocoder, a component that turns those features into a waveform. It avoids the joins, but the output often sounds muffled.

WaveNet, a network that generates raw audio one sample at a time, produces much better sound. But its inputs, linguistic features and a predicted fundamental frequency with phoneme durations, need an elaborate front end to produce.

Tacotron removed the front end. It is a sequence-to-sequence model that maps characters to magnitude spectrograms. Its own vocoder was Griffin-Lim, an iterative algorithm that estimates the phase missing from a magnitude spectrogram so the signal can be rebuilt with an inverse Fourier transform. Griffin-Lim leaves characteristic artifacts, so the sound quality was limited by the vocoder. Tacotron 2 keeps the text-to-spectrogram model and replaces the vocoder with a WaveNet.

How it works

The walkthrough follows one second of speech through the pipeline. The numbers are the paper's settings: 24 kHz audio, frames every 12.5 ms, and 80 mel channels.

flowchart LR
  T["Characters"] --> E["Embedding and convolutions"]
  E --> B["Bidirectional LSTM encoder"]
  B --> A["Attention"]
  A --> D["Decoder LSTM with pre-net"]
  D --> M["Mel frame"]
  M --> P["Post-net residual"]
  P --> W["WaveNet vocoder"]
  W --> S["16-bit waveform"]
  1. Read the text. The input is spelled out in words, so "16" becomes "sixteen". Each character is mapped to a learned 512-number vector, then passed through three convolutional layers that look at five characters at a time. The result is a short sequence of feature vectors, one per character, that now also carries information about nearby letters.

  2. Encode the sequence. A bidirectional LSTM reads the feature sequence forwards and backwards and gives each character a summary of its surroundings. Check: each character's output depends on both its left and right context, which matters because pronunciation depends on what comes next.

  3. Decode one frame at a time. The decoder is autoregressive: it produces one mel frame, then uses that frame as input for the next. Before it sees the previous frame, that frame goes through a small pre-net, which the paper calls an information bottleneck that makes attention learnable.

  4. Attend to the text. At each decoder step, attention produces a weighted summary of the encoder's outputs. The weights depend on the decoder's state and on the attention weights from earlier steps, which keeps the model moving forward through the text. Check: the cumulative weights push attention forward through the text, which guards against the repeated and skipped words that attention models often produce.

  5. Emit the frame and a stop signal. The decoder output is projected to one frame of 80 mel values. A separate sigmoid output estimates the probability that speech has ended, and generation stops at the first frame where that probability exceeds 0.5. Check: the model decides its own length instead of using a fixed duration.

  6. Refine the frames. A five-layer post-net predicts a residual that is added to the whole predicted spectrogram. Check: the post-net sees past and future frames together, which the decoder cannot do while it is still generating.

  7. Vocode. WaveNet is conditioned on the mel frames. Each frame covers 12.5 ms, which is 300 audio samples at 24 kHz, so one second of audio is 80 frames and 24,000 samples. WaveNet produces each sample from the frame that covers it and the samples before it. Check: 80 frames times 300 samples per frame is 24,000 samples, one second.

The math

Here yt\mathbf{y}_t is the true mel frame at time tt, y^t\hat{\mathbf{y}}_t is the predicted frame and TT is the number of frames in the utterance. Each frame has 8080 mel channels.

Definition: Mel spectrogram target

A mel spectrogram is a matrix whose columns are frames of log-compressed mel-band magnitudes. Each frame is taken from a 50 millisecond window with a 12.5 millisecond hop, weighted by a Hann window. The mel filterbank covers 125 Hz to 7.6 kHz with 80 channels, and magnitudes are clipped at a minimum of 0.01 before the logarithm.

Step 3 in symbols: the autoregressive decoder

The decoder predicts each frame from the frame before it and the attention context ct\mathbf{c}_t produced at step 4:

y^t=fdec(PreNet(y^t−1),ct)\hat{\mathbf{y}}_t = f_{\text{dec}}\big(\mathrm{PreNet}(\hat{\mathbf{y}}_{t-1}), \mathbf{c}_t\big)

During training the true previous frame yt−1\mathbf{y}_{t-1} replaces y^t−1\hat{\mathbf{y}}_{t-1}. That substitution is teacher forcing, and it is why the paper discusses a gap between training and generation.

Step 4 in symbols: location-sensitive attention

The attention weights αt,j\alpha_{t,j} say how much output step tt looks at encoder position jj. The paper adds the cumulative weights from earlier steps as a location feature, so the score for position jj depends on where attention has already been:

αt,j=exp⁡(et,j)∑kexp⁡(et,k),ct=∑jαt,j hj\alpha_{t,j} = \frac{\exp(e_{t,j})}{\sum_{k} \exp(e_{t,k})}, \qquad \mathbf{c}_t = \sum_{j} \alpha_{t,j}\, \mathbf{h}_j

Here hj\mathbf{h}_j is the encoder output at position jj and et,je_{t,j} is the score. The denominator is the softmax over all positions, so the weights are positive and sum to one.

Step 5 in symbols: the stop probability

A sigmoid output ptp_t estimates whether the utterance has ended at frame tt. Generation stops at the first tt where pt>0.5p_t \gt 0.5.

Step 6 in symbols: the training loss

The paper sums the mean squared error before and after the post-net, so both the raw and the refined frames are pushed towards the target:

L=∑t=1T∥y^tpre−yt∥2+∑t=1T∥y^tpost−yt∥2\mathcal{L} = \sum_{t=1}^{T} \lVert \hat{\mathbf{y}}^{\text{pre}}_t - \mathbf{y}_t \rVert^2 + \sum_{t=1}^{T} \lVert \hat{\mathbf{y}}^{\text{post}}_t - \mathbf{y}_t \rVert^2

The post-net output is y^tpost=y^tpre+rt\hat{\mathbf{y}}^{\text{post}}_t = \hat{\mathbf{y}}^{\text{pre}}_t + \mathbf{r}_t, where rt\mathbf{r}_t is the residual the post-net predicts.

Step 7 in symbols: the WaveNet vocoder

The waveform is modelled one sample xnx_n at a time, conditioned on the mel frame m⌊n/300⌋\mathbf{m}_{\lfloor n / 300 \rfloor} that covers it. The network has 30 dilated convolution layers in three cycles, so the dilation of layer kk is 2k mod 102^{k \bmod 10} for k=0,…,29k = 0, \ldots, 29. Each sample has a distribution from a mixture of ten logistic components rather than a softmax over buckets. The loss is the negative log-likelihood of the true sample:

Lvoc=−∑nlog⁡p(xn∣x<n,m⌊n/300⌋)\mathcal{L}_{\text{voc}} = -\sum_{n} \log p\big(x_n \mid x_{\lt n}, \mathbf{m}_{\lfloor n / 300 \rfloor}\big)

Here ⌊n/300⌋\lfloor n / 300 \rfloor is the frame index, since 300 samples fall in each 12.5 millisecond frame at 24 kHz.

Example
Tiny: the frame and sample arithmetic
  1. One frame covers 12.5 ms. Convert to seconds: 0.0125 s.
  2. At 24,000 samples per second, a frame covers 0.0125 times 24,000 = 300 samples.
  3. One second of speech has 1 divided by 0.0125 = 80 frames.
  4. Check: 80 frames times 300 samples is 24,000 samples, which is one second of audio at 24 kHz.

Try it: how many frames and samples does 3 seconds of speech need? Answer: 240 frames and 72,000 samples, because 3 divided by 0.0125 is 240 and 240 times 300 is 72,000.

Example
Standard: one decoder step with attention weights

Take three encoder positions with scores e=(1.0,0.0,−1.0)e = (1.0, 0.0, -1.0) at one decoder step.

  1. Exponentiate each score: e1.0≈2.718e^{1.0} \approx 2.718, e0.0=1e^{0.0} = 1, e−1.0≈0.368e^{-1.0} \approx 0.368.
  2. Sum them: 2.718+1+0.368≈4.0862.718 + 1 + 0.368 \approx 4.086.
  3. Divide each by the sum: weights ≈0.665\approx 0.665, 0.2450.245 and 0.0900.090.
  4. Check: 0.665+0.245+0.090=1.0000.665 + 0.245 + 0.090 = 1.000, so the weights form a valid mix.
  5. Mix three encoder vectors h1=2\mathbf{h}_1 = 2, h2=4\mathbf{h}_2 = 4 and h3=8\mathbf{h}_3 = 8 (one number each for illustration). The context is 0.665×2+0.245×4+0.090×8≈3.030.665 \times 2 + 0.245 \times 4 + 0.090 \times 8 \approx 3.03.

Interpretation: the context is pulled towards the position with the highest score, but it still carries information from all three. This is what lets the decoder read the whole sentence at each step.

Example
Realistic: a 2 second utterance and its vocoder input

A 2 second sentence at 24 kHz is 48,000 samples. The mel spectrogram has 2/0.0125=1602 / 0.0125 = 160 frames of 80 values each, which is 160×80=12,800160 \times 80 = 12,800 numbers. The waveform has 48,000 samples, so the spectrogram is about 27 percent of the waveform's size. The vocoder therefore does most of the work, turning 12,800 numbers into 48,000 samples while keeping timing and pitch.

Try it: the paper's WaveNet scales the waveform targets by 127.5 before training, so an amplitude of 1.0 becomes 127.5. Given a sample at 0.5, what does it become? Answer: 0.5×127.5=63.750.5 \times 127.5 = 63.75.

Results

  • Human ratings (Table 1, MOS on 100 test sentences). Parametric 3.492, Tacotron with Griffin-Lim 4.001, concatenative 4.166, WaveNet with linguistic features 4.341, Tacotron 2 4.526 and ground truth 4.582. The Tacotron 2 interval overlaps the ground truth interval, so the paper calls the two comparable.
  • Side by side against the recordings. Raters preferred the ground truth by a small margin, with a mean of minus 0.270 on a scale from minus 3 to 3. The comments point to occasional mispronunciation as the main reason.
  • Custom and out-of-domain sets. On a separate 100-sentence test set the system scored 4.354. On 37 news headlines it scored 4.148, against 4.137 for WaveNet with linguistic features, a tie within the error bars. Raters said the neural system sounded more natural but sometimes mispronounced names.
  • Error analysis. In a manual count, 6 sentences had mispronunciations, 1 had a skipped word, none had repeated words, and 23 had unnatural prosody. End-point prediction failed once, on the longest input.
  • Predicted or ground truth features (Table 2). Training and synthesis on predicted features gives 4.526; ground truth for both gives 4.522. Training on ground truth but synthesising from predicted features gives 4.362, which the authors attribute to predicted spectrograms being smoother than real ones.
  • Mel versus linear spectrograms (Table 3). Linear spectrograms with Griffin-Lim give 3.944, linear with WaveNet 4.510, and mel with WaveNet 4.526. The WaveNet vocoder matters more than the spectrogram type.
  • Post-net (Section 3.3.3). Without the post-net the score is 4.429; with it, 4.526.
  • Smaller WaveNet (Table 4). The 30-layer baseline with a 255.8 ms receptive field scores 4.526; a 12-layer model with a 10.5 ms receptive field scores 4.481, a difference inside the intervals. Removing dilation drops the receptive field to 2.5 ms and the score to 3.930.

Limits, from the paper's own analysis. The training data is 24.6 hours from one female speaker, so the results are for one voice. Prosody remains a weak point, and the system depends on training data that covers the text it will read. The authors also note that predicted spectrograms are smoother than real ones, which costs quality.

Reading guide

Check yourself

QuestionRecall: why does the model predict a mel spectrogram instead of raw waveform samples?Show answer

A spectrogram frame is smoother than samples and is invariant to phase within the frame, so a squared error loss suits it. It is also much smaller: 80 numbers per 12.5 ms frame, against 300 samples in the same time. That makes the prediction problem easier for the first network, and the WaveNet fills in the fine detail.

QuestionComputation: how many mel frames and waveform samples does 3 seconds of speech at 24 kHz need?Show answer

Frames: 3 divided by 0.0125 is 240. Samples: 3 times 24,000 is 72,000. Check: 240 frames times 300 samples per frame is 72,000.

QuestionWhy: why does the decoder pass each predicted frame through a pre-net with a bottleneck, and why is dropout kept on at inference?Show answer

The paper says the pre-net acting as an information bottleneck was essential for learning attention, so the decoder cannot simply copy its previous output. Dropout with probability 0.5 is applied only inside the pre-net at inference time, which adds variation so that the same text can be spoken in slightly different ways.

QuestionApplied: a team wants a faster vocoder. The 12-layer model scores 4.481 and the 30-layer baseline scores 4.526. Is the trade-off worth it?Show answer

The gap is small compared with the intervals, which are plus or minus 0.059 and 0.066, so the two models are not clearly different in listener ratings. The 12-layer model uses fewer layers and a much smaller receptive field. The team should test on its own voice and text, because the paper's data is one speaker and read sentences.

Sources

  • Shen, J., Pang, R., Weiss, R. J., et al. (2017). Natural TTS Synthesis by Conditioning WaveNet on Mel Spectrogram Predictions. arXiv: 1712.05884
  • DOI: 10.48550/arXiv.1712.05884

Read the full paper

Jonathan Shen, Ruoming Pang, Ron J. Weiss et al., 2017. arXiv:1712.05884