Free How much of your firm runs on you? Take the 2-minute Key Man Score.
Lesson reading
0%

Lesson 16 / Unit 5: Waveform Synthesis

Neural Vocoders

96.4% of our synthesis time went to a stage we never trained: the HiFi-GAN vocoder. What it does with 80 numbers per frame, and how fast it runs on 4 CPU cores.

In the recorded CPU comparison, HiFi-GAN took 96.4% of synthesis time. The acoustic model took the rest. Inspect the waveform stage before trying to make the text encoder faster.

Waveform Synthesis

A neural vocoder is the network that turns a mel spectrogram into a waveform. The acoustic model says how much energy each frequency band carries in each frame; the vocoder produces the samples.

That is a large expansion. Our vocoder takes 80 numbers per frame and emits 256 audio samples for each one, at 22,050 samples a second. And the 80 numbers are incomplete: a mel spectrogram keeps magnitude and throws away phase, the timing relationship between frequency components. Why TTS needs a vocoder shows what is lost. The vocoder has to generate a waveform whose spectrum matches the mel, with phase that holds together from one frame to the next.

Classical signal processing can estimate phase iteratively. Neural vocoders learn it from data instead, which is why they need training on a lot of audio and why they are reused so widely.

HiFi-GAN Architecture

HiFi-GAN is a generative adversarial network: a generator that upsamples mel frames into a waveform, trained against discriminators that try to tell its output from real audio.

NVIDIA’s NeMo documentation summarises the design as “one generator and two discriminators (multi-scale and multi-period)”. The generator upsamples with transposed convolutions, each followed by a multi-receptive field fusion module that looks at the signal at several scales at once. The multi-period discriminator looks at the audio folded at several fixed periods, which matches the HiFi-GAN paper’s central argument: speech is made of periodic signals, so modelling periodic patterns is what lifts sample quality.

The paper reports generating 22.05 kHz audio 168 times faster than real time on a V100 GPU, and a lightweight variant at 13.4 times faster than real time on CPU. Those are the authors’ numbers on their hardware. Ours follow.

Vocoder Timing

On our container, the vocoder alone ran at a real-time factor of 0.19 to 0.27 on a 7.55-second LJSpeech clip, so roughly 4 to 5 times faster than real time. The 0.27 was the first run, with cold caches.

Real-time factor is synthesis time divided by audio duration: below 1 is faster than real time. We timed the two stages separately in compare_piper, our Piper comparison run, which is the source of the 3.6% and 96.4% split. The timing brackets the vocoder call like this:

m = model.infer(ids)[0] * c["stats"]["mel_std"] + c["stats"]["mel_mean"]
t1 = time.time()
wav = voc.decode_batch(m.T.unsqueeze(0)).squeeze().numpy()
t2 = time.time()

The first row comes from four vocoder runs on that one clip: copy synthesis plus the three mismatch variants from the next lesson. The other two rows are three probe sentences, two timed passes each after a warm-up pass:

System, 4 CPU coresReal-time factorShare of synthesis time
HiFi-GAN alone, one 7.55 s clip0.19 to 0.27all of it
Tiny model (step 1,650) + HiFi-GAN0.24acoustic 3.6%, vocoder 96.4%
Piper, VITS end-to-end0.052one network, no separate vocoder

Our acoustic model is 3.6% of synthesis time. Making it twice as fast would save under 2% of the total. Every real speed-up in this system lives in the vocoder.

The Piper row is the reason end-to-end TTS gets its own page. It produces a waveform directly and ran about 4.6 times faster than our cascade on the same probes.

Pretrained Weights

Because a compatible public HiFi-GAN checkpoint already exists, letting this course focus its training work on the acoustic model: copy synthesis through it lands 12.3 dB from the original by log-spectral distance. We used speechbrain/tts-hifigan-ljspeech, Apache-2.0, trained on the same dataset.

The test that it fits is copy synthesis: take a real clip, compute its mel with the vocoder’s own recipe, and vocode it. No acoustic model is involved, so the result isolates waveform reconstruction. It is a reference, not a strict bound on every predicted mel or listening score. On LJ001-0009, copy synthesis came out at a log-spectral distance of 12.3 dB from the original. That is one clip and not a perceptual score. Press play and compare.

LJ001-0009, original

The recording, 7.55 s.

Copy synthesis

Same clip, converted to its mel with the vocoder’s recipe, then vocoded by HiFi-GAN. On this clip, a log-spectral distance of 12.3 dB from the original.

The catch is the recipe. The vocoder expects mels computed the way it was trained, and some deviations matter far more than others. Its recipe: 22,050 Hz, n_fft 1024, hop 256, 80 bins from 0 to 8,000 Hz, Slaney mel scale and norm, natural-log compression. Our tiny model exists to predict exactly that. Mel recipe mismatch measures what happens when one setting is off.

Sizing a vocoder

Time your acoustic model and vocoder separately on your own hardware before optimising either. Multiply the combined real-time factor by the audio minutes you expect to serve, and you have the compute you are paying for; cost and deployment turns that into a per-minute figure.

Common questions

What does a neural vocoder do in TTS?

It turns a mel spectrogram into a waveform. The mel spectrogram keeps how much energy sits in each frequency band per frame and throws away phase, so the vocoder has to generate the actual samples, 256 of them per frame at the LJSpeech settings, consistent with the spectrum it was given.

How fast is HiFi-GAN on a CPU?

On a 4-core cloud container with no GPU, the pretrained LJSpeech HiFi-GAN from SpeechBrain ran at a real-time factor of 0.19 to 0.27 across four runs on one 7.55-second clip (copy synthesis and three mismatched mel recipes), roughly 4 to 5 times faster than real time. The HiFi-GAN paper reports 13.4 times faster than real time on CPU for its lightweight variant.

Can I reuse a pretrained vocoder with my own acoustic model?

Yes, if your acoustic model predicts exactly the mel recipe the vocoder was trained on: sample rate, FFT size, hop, number of mel bins, frequency range, mel scale, normalisation and log compression. That is what we did with our tiny model. A single mismatch in that recipe can wreck the output.

We do this work for teams shipping voice agents: Self-Hosted Voice Agent .

Edit this lesson on GitHub ↗

Discussion

Questions, corrections and war stories welcome. Sign in with GitHub to comment.

Free guide

Be The 10x Entrepreneur

Get the firm out of your head.

  • 8 chapters
  • 7 worksheets
  • 30 day plan