TL;DR
HiFi-GAN is a neural vocoder: it takes a mel-spectrogram, a compact picture of how loud each frequency is over time, and produces the raw waveform that a speaker would play. It is trained as a generative adversarial network, with two kinds of discriminator that each look for a different structure in the audio. Its largest version scores 4.36 on a 5-point listening test against 4.45 for real recordings, and it runs about 168 times faster than real time on one GPU.
Builds on: Generative Adversarial Network, Feature Matching Loss, Dilated Convolution · Leads to: later text-to-speech systems that use GAN vocoders as their final stage
Why it mattered
Modern text-to-speech systems work in two stages. The first turns text into a mel-spectrogram. The second, the vocoder, turns that spectrogram into a waveform of tens of thousands of samples per second. The second stage decides how natural the voice sounds and how much computing a voice assistant or a car needs to speak.
Before this paper, the best vocoders were slow or large. WaveNet was accurate but generated one sample per forward pass. Flow models such as WaveGlow ran in parallel but used large networks. Fast GAN vocoders such as MelGAN were small but left a clear quality gap. HiFi-GAN closed most of that gap while keeping the speed of a GAN, and its open-source code made it easy for others to reuse.
The problem
Raw audio at 22,050 samples per second is a very long sequence, and a single second of speech has 22,050 values that must all be right. Three ways of generating it each had a cost. Autoregressive models such as WaveNet produce one sample at a time, so the time grows with the length of the output. Flow models generate in parallel but need many layers to reach good quality. GAN vocoders are parallel and small, but the authors found they did not reach the quality of WaveNet or flows.
The authors observe that speech is a sum of sinusoids with different periods. The structure that makes a voice sound like a voice repeats with those periods, but earlier GAN discriminators, including the multi-scale ones borrowed from MelGAN, looked at consecutive samples and did not target that repeating structure directly. The paper's central claim is that modelling the periodic patterns is what raises sample quality.
How it works
The walkthrough follows the order the pipeline runs during training and generation.
- Input: a mel-spectrogram. The conditioning input has 80 frequency bands. The analysis window is 1024 samples long and the hop between frames is 256 samples. Tiny instance: one second of 22,050-sample audio becomes frames. Check: the number of frames is set by the hop, not by the window.
- Upsample in the generator. A stack of transposed convolutions raises the time resolution step by step until the output length matches the waveform. Each input frame has to become one hop of 256 output samples. Check: the output length is 86 times 256, about 22,000 samples for the example second.
- Mix several receptive fields. After each upsampling layer, a multi-receptive-field fusion module runs several residual blocks in parallel. Each block has a different kernel size and dilation, so one block sees short patterns and another sees patterns several times longer. The module adds their outputs. Check: the sum has the same shape as any one block's output, so the fusion adds no extra length.
- Judge with the multi-period discriminator. The waveform is reshaped into a grid whose width is the period , for in 2, 3, 5, 7 and 11. A 2D convolution then looks down each column, so each sub-discriminator sees every -th sample. Check: with period 3, a sample at time 0 and a sample at time 3 land in the same column.
- Judge with the multi-scale discriminator. The raw waveform and two smoothed, downsampled versions each go to their own sub-discriminator. This catches structure that is spread over longer time spans. Check: the three scales see the same audio at 1, one half and one quarter of the time resolution.
- Train with three losses. The adversarial loss pushes the generator to fool the discriminators. A mel-spectrogram loss compares the spectrum of the generated and real audio. A feature-matching loss compares the discriminators' intermediate activations. Check: the mel loss is weighted 45 and feature matching 2, so the spectral term carries most of the weight in the generator's objective.
flowchart LR A[Mel-spectrogram, 80 bands] --> B[Transposed convolutions] B --> C[Multi-receptive-field fusion] C --> D[Waveform at 22.05 kHz] D --> E[Multi-period discriminator] D --> F[Multi-scale discriminator] E --> G[Adversarial and feature-matching losses] F --> G D --> H[Mel loss against the real audio]
The math
Let be the real waveform, the mel-spectrogram condition, and the generated waveform. Let be a discriminator, and let be the function that turns a waveform into its mel-spectrogram. The paper uses least-squares GAN losses, which replace the logarithms of the original GAN objective with squared errors. See Least Squares GAN for why this keeps gradients alive.
Step 6 in symbols: the adversarial losses
The discriminator is pushed to output 1 on real audio and 0 on generated audio, . The generator is pushed to make the discriminator output 1 on its own samples, .
Step 6 in symbols: the mel loss
The mel loss is the sum of absolute differences between the two spectrograms, the L1 distance, . It compares the frequency content of the two signals, so it is most sensitive to the spectral envelope the ear hears.
Step 6 in symbols: the feature-matching loss
For a discriminator with layers, let be the features at layer and the number of features there. The feature-matching loss is . It asks the generator to match the discriminator's internal view of real audio.
The total objective
The generator minimises , summed over all sub-discriminators , with and . Each discriminator minimises its own adversarial loss, .
Worked examples
Suppose the discriminator gives real audio the score and the generated audio the score .
- Discriminator loss: .
- Generator adversarial loss: .
- Interpretation: the discriminator is doing well, since its loss is small. The generator has a large adversarial loss and gets a strong push to make its output look more real.
Use a toy spectrogram with two values. The real spectrum is and the generated one is .
- Absolute differences: and .
- Mel loss: .
- Weighted mel term: .
- Interpretation: even a small spectral error becomes a large number once it is multiplied by 45. The spectral term is therefore the largest part of the generator's loss in this example, so the generator is strongly pulled toward the right spectrum.
The largest model, V1, is reported at 167.86 times faster than real time on one V100 GPU, and the smallest, V3, at 13.44 times faster than real time on a laptop CPU.
- Time for one second of audio on V1 on the GPU: seconds, about 6 milliseconds.
- Time for ten seconds of audio on V3 on the CPU: seconds.
- Interpretation: both are far faster than real time, so a voice assistant can start speaking before the first sentence is finished. The CPU figure is the one that matters for on-device use, because it needs no GPU.
- Try it: a 20-second reply is generated by V3 on the CPU. How long does the vocoder take? Answer: seconds.
Results
Quality is measured with a mean opinion score (MOS) on a 5-point scale, collected from crowd raters with 95% confidence intervals. The main test uses 50 utterances from LJSpeech, a single-speaker dataset of about 13,100 clips and roughly 24 hours. The baselines use their publicly released pretrained weights.
| Model | MOS (95% CI) | Speed on GPU (times real time) | Parameters (millions) |
|---|---|---|---|
| Ground truth | 4.45 (±0.06) | n/a | n/a |
| WaveNet (MoL) | 4.02 (±0.08) | about 0.003 | 24.73 |
| WaveGlow | 3.81 (±0.08) | about 22.75 | 87.73 |
| MelGAN | 3.79 (±0.09) | about 645.73 | 4.26 |
| HiFi-GAN V1 | 4.36 (±0.07) | about 167.86 | 13.92 |
| HiFi-GAN V2 | 4.23 (±0.07) | about 764.80 | 0.92 |
| HiFi-GAN V3 | 4.05 (±0.08) | about 1,186.80 | 1.46 |
What the numbers mean:
- Quality: V1 is within 0.09 MOS of the real recordings. V3 scores 4.05, just above WaveNet's 4.02, and is far faster.
- Efficiency: V2 uses 0.92 million parameters and V3 1.46 million, against 87.73 million for WaveGlow.
- Ablations: removing the multi-period discriminator causes a significant drop in perceptual quality, and removing the multi-scale discriminator causes a smaller but noticeable one. Adding the multi-period discriminator to MelGAN raises its MOS by 0.47. Using periods that are powers of 2 instead of primes costs 0.20 MOS.
- Unseen speakers: the paper also tests generality on the multi-speaker VCTK dataset, where nine speakers were excluded from training and the baselines were retrained on the same data settings.
Limits. The main quality test is on one speaker, and the MOS sample is 50 utterances, so the confidence intervals are not small. The speed numbers depend on hardware and are measured in 32-bit floating point with no further optimisation, and the CPU figure is from a laptop. The ablations use the smallest generator, V3, so they show the effect of each component on that model, not on V1. The paper claims that the small models are comparable to WaveNet in quality, a claim that rests on the MOS test above.
Reading guide
- Section 1, Introduction. Read with WaveNet: A Generative Model for Raw Audio and Generative Adversarial Network open. The introduction explains the two-stage text-to-speech setting in plain words.
- Section 2.2, Generator. Needs Transposed Convolution, Dilated Convolution and Residual Connection. Figure 1 is the block diagram to read beside the MRF paragraph.
- Section 2.3, Discriminator. Needs Weight Normalization for the normalisation. The multi-period and multi-scale ideas are the paper's core; read the reshaping step slowly.
- Section 2.4, Training losses. Needs Least Squares GAN for the adversarial loss, Feature Matching Loss for the feature term, and Mel Spectrogram for the spectral loss.
- Section 3, Experiments. Needs AdamW Optimizer for the optimiser settings. The dataset description is a useful reminder of how small the single-speaker test is.
- Section 4, Results. Table 1 and Table 2 are the main evidence; read the captions before the numbers.
Check yourself
QuestionRecall: what is a mel-spectrogram input to HiFi-GAN, and why is the hop size important?Show answer
It is a compact picture of the frequency content over time, here with 80 bands, computed with windows of 1024 samples and a hop of 256 samples. The hop sets how many frames a second of audio produces, and the generator's upsampling must multiply that frame count back up to the full sample rate, so each frame becomes 256 samples.
QuestionA discriminator gives real audio 0.8 and generated audio 0.5. Compute the discriminator's loss on this pair using the least-squares form.Show answer
The loss is .
QuestionWhy does the multi-period discriminator reshape the waveform into a grid instead of sampling every p-th sample?Show answer
Reshaping keeps every time step in the input, so the gradients from the discriminator reach all samples of the audio. Sampling every p-th value alone would throw away the other samples in the period, so the discriminator would learn only from a subset of the signal.
QuestionHiFi-GAN V3 scores 4.05 MOS and WaveNet scores 4.02. Does that mean V3 is better than WaveNet?Show answer
Not necessarily. The difference of 0.03 is well inside the confidence intervals, which are about ±0.08 for both. The honest reading is that V3 is comparable to WaveNet in this test while being far faster, not that it is better.
Sources
- Kong, Kim, Bae, "HiFi-GAN: Generative Adversarial Networks for Efficient and High Fidelity Speech Synthesis", NeurIPS 2020 (arXiv:2010.05646).
- van den Oord et al., "WaveNet: A Generative Model for Raw Audio", 2016 (arXiv:1609.03499).
- Generative adversarial network, Wikipedia.