Search

Search papers and lessons

HiFi-GAN: Generative Adversarial Networks for Efficient and High Fidelity Speech

Jungil Kong, Jaehyeon Kim, Bae, Jaekyoung · 2020

HiFi-GAN turns mel-spectrograms into speech waveforms with a GAN whose discriminators look at periodic patterns, reaching near-human quality far faster than real time.

On this page

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

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.

  1. 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 22050/256≈8622050 / 256 \approx 86 frames. Check: the number of frames is set by the hop, not by the window.
  2. 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.
  3. 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.
  4. Judge with the multi-period discriminator. The waveform is reshaped into a grid whose width is the period pp, for pp in 2, 3, 5, 7 and 11. A 2D convolution then looks down each column, so each sub-discriminator sees every pp-th sample. Check: with period 3, a sample at time 0 and a sample at time 3 land in the same column.
  5. 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.
  6. 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 xx be the real waveform, ss the mel-spectrogram condition, and G(s)G(s) the generated waveform. Let DD be a discriminator, and let ϕ\phi 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, LAdv(D;G)=E(x,s)[(D(x)−1)2+D(G(s))2]\mathcal{L}_{Adv}(D; G) = \mathbb{E}_{(x, s)}\left[ (D(x) - 1)^2 + D(G(s))^2 \right]. The generator is pushed to make the discriminator output 1 on its own samples, LAdv(G;D)=Es[(D(G(s))−1)2]\mathcal{L}_{Adv}(G; D) = \mathbb{E}_{s}\left[ (D(G(s)) - 1)^2 \right].

Step 6 in symbols: the mel loss

The mel loss is the sum of absolute differences between the two spectrograms, the L1 distance, LMel(G)=E(x,s)[∥ϕ(x)−ϕ(G(s))∥1]\mathcal{L}_{Mel}(G) = \mathbb{E}_{(x, s)}\left[ \lVert \phi(x) - \phi(G(s)) \rVert_1 \right]. 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 TT layers, let DiD^{i} be the features at layer ii and NiN_i the number of features there. The feature-matching loss is LFM(G;D)=E(x,s)[∑i=1T1Ni∥Di(x)−Di(G(s))∥1]\mathcal{L}_{FM}(G; D) = \mathbb{E}_{(x, s)}\left[ \sum_{i=1}^{T} \frac{1}{N_i} \lVert D^{i}(x) - D^{i}(G(s)) \rVert_1 \right]. It asks the generator to match the discriminator's internal view of real audio.

The total objective

The generator minimises LG=∑k[LAdv(G;Dk)+λfmLFM(G;Dk)]+λmelLMel(G)\mathcal{L}_G = \sum_{k} \left[ \mathcal{L}_{Adv}(G; D_k) + \lambda_{fm} \mathcal{L}_{FM}(G; D_k) \right] + \lambda_{mel} \mathcal{L}_{Mel}(G), summed over all sub-discriminators DkD_k, with λfm=2\lambda_{fm} = 2 and λmel=45\lambda_{mel} = 45. Each discriminator minimises its own adversarial loss, LD=∑kLAdv(Dk;G)\mathcal{L}_{D} = \sum_{k} \mathcal{L}_{Adv}(D_k; G).

Worked examples

Example
1. Tiny: one adversarial score

Suppose the discriminator gives real audio the score D(x)=0.9D(x) = 0.9 and the generated audio the score D(G(s))=0.2D(G(s)) = 0.2.

  1. Discriminator loss: (0.9−1)2+0.22=0.01+0.04=0.05(0.9 - 1)^2 + 0.2^2 = 0.01 + 0.04 = 0.05.
  2. Generator adversarial loss: (0.2−1)2=0.64(0.2 - 1)^2 = 0.64.
  3. 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.
Example
2. Standard: the mel term in the generator loss

Use a toy spectrogram with two values. The real spectrum is ϕ(x)=(1.0,2.0)\phi(x) = (1.0, 2.0) and the generated one is ϕ(G(s))=(1.5,1.0)\phi(G(s)) = (1.5, 1.0).

  1. Absolute differences: ∣1.0−1.5∣=0.5|1.0 - 1.5| = 0.5 and ∣2.0−1.0∣=1.0|2.0 - 1.0| = 1.0.
  2. Mel loss: 0.5+1.0=1.50.5 + 1.0 = 1.5.
  3. Weighted mel term: λmel⋅1.5=45⋅1.5=67.5\lambda_{mel} \cdot 1.5 = 45 \cdot 1.5 = 67.5.
  4. 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.
Example
3. Realistic: how fast is fast

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.

  1. Time for one second of audio on V1 on the GPU: 1/167.86≈0.005961 / 167.86 \approx 0.00596 seconds, about 6 milliseconds.
  2. Time for ten seconds of audio on V3 on the CPU: 10/13.44≈0.74410 / 13.44 \approx 0.744 seconds.
  3. 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.
  4. Try it: a 20-second reply is generated by V3 on the CPU. How long does the vocoder take? Answer: 20/13.44≈1.4920 / 13.44 \approx 1.49 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.

ModelMOS (95% CI)Speed on GPU (times real time)Parameters (millions)
Ground truth4.45 (±0.06)n/an/a
WaveNet (MoL)4.02 (±0.08)about 0.00324.73
WaveGlow3.81 (±0.08)about 22.7587.73
MelGAN3.79 (±0.09)about 645.734.26
HiFi-GAN V14.36 (±0.07)about 167.8613.92
HiFi-GAN V24.23 (±0.07)about 764.800.92
HiFi-GAN V34.05 (±0.08)about 1,186.801.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

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 (0.8−1)2+0.52=0.04+0.25=0.29(0.8 - 1)^2 + 0.5^2 = 0.04 + 0.25 = 0.29.

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.

Read the full paper

Jungil Kong, Jaehyeon Kim, Bae, Jaekyoung, 2020. arXiv:2010.05646