Matcha-TTS is a non-autoregressive text-to-speech (TTS) model that learns, with a neural network, the "velocity" (vector field) leading from noise to a mel spectrogram, and produces speech by solving an ordinary differential equation (ODE) in a few steps. It is trained with optimal-transport conditional flow matching (OT-CFM). Mehta et al. at KTH Royal Institute of Technology in Sweden published it in 2023, and it was accepted at ICASSP 2024.
Diffusion models such as DDPM give high-quality results in speech synthesis too. However, they repeat the procedure of gradually removing noise dozens of times in sequence, which makes synthesis slow, because each step requires one pass of the entire network.
Matcha-TTS reduces this weakness in two ways.
Train with OT-CFM: It learns a vector field that follows paths connecting noise and data with straight lines. Because the paths are straight, they can be solved accurately in few steps.
Use a light decoder: A 1D U-Net combining 1D convolutions and Transformers makes each step fast and reduces training memory.
The alignment between text and speech is learned by the model itself with monotonic alignment search (MAS), as in Glow-TTS. No external alignment tool is needed.
Compared with three pretrained models (FastSpeech 2, VITS, and Grad-TTS) on LJ Speech, the results were as follows.
Quality: A MOS of 3.84 with 10 steps, the highest of all conditions compared
Memory: The lowest GPU memory needed for training, 4.8 GiB
Speed: With 2 steps, about as fast as the fastest model, FastSpeech 2, on long sentences
Intelligibility: A low speech-recognition word error rate of 2.34% even with 2 steps
Flow matching is a method that learns a "velocity field" that moves samples from a simple distribution (the standard normal) from time t=0 to t=1, carrying them to the data distribution.
Given a vector field vtโ that changes over time tโ[0,1], the following ODE defines a flow ฯtโ that moves samples.
dtdโฯtโ(x)=vtโ(ฯtโ(x)),ฯ0โ(x)=x
Starting from the distribution p0โ(x)=N(x;0,I) at t=0, if vtโ can be learned so that the distribution p1โ at t=1 is close to the data distribution q(x), data can be generated simply by solving the ODE from noise. In terms of a river, it means building a current such that a leaf dropped anywhere always reaches the destination by drifting along it.
Training is approached in the following stages.
Flow matching: If the true vector field utโ were known, it would suffice to bring the network vtโ(x;ฮธ) close to it. However, utโ for the distribution of the whole dataset cannot be computed.
Conditional flow matching (CFM): Use paths conditioned on a single data point x1โ and their vector fields utโ(xโฃx1โ). These can be written in closed form, and the gradient of the loss has been shown to be the same as for flow matching.
Optimal-transport CFM (OT-CFM): Use paths that connect a noise sample x0โ and data x1โ with straight lines.
The loss of Matcha-TTS brings the network vtโ(โ โฃฮผ;ฮธ), conditioned on the mean ฮผ computed from the text, close to this velocity. t is drawn from the uniform distribution on [0,1] and x0โ from the standard normal.
The target velocity utOTโ depends only on x0โ and x1โ and is constant regardless of time t. The network only needs to predict "the direction from the current position straight toward the destination".
The paths of diffusion models are curved, so solving them with coarse steps strays off the path. OT-CFM paths are straight, so even a few steps (2โ10 in the paper) reach the destination accurately. Rectified Flow, proposed around the same time, is based on the same idea.
Architecture
Matcha-TTS consists of three parts: a text encoder, a duration predictor, and a vector field network (the decoder). In the figure at the top of the article, the left side is the overall synthesis flow and the right side is the inside of the decoder.
At synthesis time, processing goes in the following order.
Convert to phonemes: phonemizer (espeak-ng) turns the text into a sequence of International Phonetic Alphabet (IPA) phonemes.
Text encoder: The same encoder as Glow-TTS and Grad-TTS (a prenet and Transformer blocks), with only the positional representation replaced by RoPE. A final linear layer outputs the per-phoneme mean ฮผ~โ.
Duration predictor: Same form as in Glow-TTS; predicts each phoneme's duration in the log domain.
Upsample: Round up the predicted durations and repeat each phoneme's ฮผ~โ that many times to form the per-frame mean ฮผ.
Solve the ODE: Starting from standard normal noise x0โ, repeat xโx+ฮtโ vtโ(xโฃฮผ)n times with the velocity predicted by the decoder (first-order Euler method). The final x is the mel spectrogram.
Vocoder: In the paper, a pretrained HiFi-GAN converts it to a waveform.
ฮผ is used only to condition the decoder, not as the mean of the starting noise. This is the difference from Grad-TTS, which starts from N(ฮผ,I).
The decoder (vector field network) is a 1D U-Net modeled on the 2D U-Net of Stable Diffusion.
Blocks: 1D convolutional residual blocks shrink the sequence (downsampling) and expand it again (upsampling). Each residual block is followed by one Transformer block.
Time embedding: The flow-matching time t is embedded and fed in the same way as in Grad-TTS.
Transformer: The feed-forward network uses BigVGAN's snake beta activation. No positional embedding is used, because the encoder already encodes positions between phonemes, and the convolutions and downsampling distinguish frame positions within the same phoneme.
Input: In the official implementation, the current x and ฮผ are concatenated along the channel dimension, and the output of each downsampling stage is concatenated into the corresponding upsampling stage (U-Net skip connections).
In the paper's configuration, there are 2 downsampling, 2 middle, and 2 upsampling stages, and each Transformer has a hidden size of 256, 2 heads, and an attention dimension of 64.
Grad-TTS's decoder is a 2D convolutional U-Net that treats the mel spectrogram as an image, assuming invariance to shifts along frequency as well. Speech spectra are not like that along frequency, and 2D also uses a lot of memory. Matcha-TTS reduces memory by using 1D convolutions along time only, and captures long-range dependencies with Transformers.
Training and Inference
Training follows the same steps as Grad-TTS. The loss is the sum of three terms: encoder, duration, and flow matching (confirmed in the official implementation).
Find the alignment: Between the encoder output ฮผ~โ and the mel spectrogram y, monotonic alignment search finds the monotonic alignment Aโ that minimizes the encoder loss Lencโ below.
Encoder loss: Under Aโ, bring ฮผ~โ close to the mel spectrogram (ฯ is the normal density; in effect, this is the mean squared error).
Duration loss: Predict the log of the durations counted from Aโ from the encoder output with gradients stopped (mean squared error).
Flow-matching loss: Draw t and x0โ, and bring the predicted velocity at ฯtOTโ close to utOTโ.
Lencโ=โj=1โFโlogฯ(yjโ;ฮผ~โA(j)โ,I)
F is the number of frames. Lencโ is what the Grad-TTS paper calls the "prior loss", and the Grad-TTS paper reports that the alignment could not be learned without it.
At inference, the encoder and duration predictor produce ฮผ, and the ODE is solved from noise. Fewer steps (number of network evaluations, NFE) make it faster; more steps improve quality. In the paper's evaluation, the standard deviation of the noise (temperature) is set to 0.667.
The paper's training settings are as follows.
Item
Value
Data
LJ Speech (standard split)
Encoder and duration predictor
Same settings as Grad-TTS (only the positional representation is RoPE)
First-order Euler method; 2, 4, and 10 steps evaluated
Vocoder
Pretrained HiFi-GAN (LJ_V1) with a denoising filter of strength 2.5ร10โ4
Experimental Results
The paper compared against pretrained public models on LJ Speech. FS2 is FastSpeech 2, GRAD is Grad-TTS, GCFM is the Grad-TTS architecture retrained with OT-CFM, MAT is Matcha-TTS, and VOC is the recordings passed through the vocoder only (a rough upper bound). The trailing number is the number of steps.
Condition
Parameters
Training memory (GiB)
RTF
WER (%)
MOS
VOC
13.9M
โ
0.001 ยฑ 0.001
1.97
4.13 ยฑ 0.09
FS2
41.2M
6.0
0.010 ยฑ 0.004
4.18
3.29 ยฑ 0.09
VITS
36.3M
12.4
0.074 ยฑ 0.083
2.52
3.71 ยฑ 0.08
GRAD-10
14.8M
7.8
0.049 ยฑ 0.013
3.44
3.49 ยฑ 0.08
GRAD-4
14.8M
7.8
0.019 ยฑ 0.006
3.69
3.20 ยฑ 0.09
GCFM-4
14.8M
7.8
0.019 ยฑ 0.004
2.70
3.57 ยฑ 0.08
MAT-10
18.2M
4.8
0.038 ยฑ 0.019
2.09
3.84 ยฑ 0.08
MAT-4
18.2M
4.8
0.019 ยฑ 0.008
2.15
3.77 ยฑ 0.07
MAT-2
18.2M
4.8
0.015 ยฑ 0.006
2.34
3.65 ยฑ 0.08
Each column is measured as follows.
Training memory: The minimum GPU memory needed to train with batch size 32 in half precision
RTF: Seconds needed per second of audio to synthesize the test set (including the vocoder)
WER: The word error rate of transcribing the synthesized speech with Whisper medium; a proxy for intelligibility
MOS: 80 native English speakers rated 40 sentences on a 1โ5 scale, giving 800 ratings per condition
The results show the following.
Quality: MAT was always significantly better than GRAD at the same number of steps, and always outperformed FS2. MAT-10 was significantly better than VITS, and MAT-2 and MAT-4 were on par with VITS.
Both the architecture and the training method matter: MOS ranked MAT-4 > GCFM-4 > GRAD-4. GCFM-4 > GRAD-4 is the effect of OT-CFM, and MAT-4 > GCFM-4 is the effect of the new architecture.
Few steps are enough: GRAD dropped sharply going from 10 to 4 steps, but the difference between MAT-10 and MAT-4 was not significant.
Lightweight: Even including the vocoder (13.9M), MAT is smaller than VITS, and its training memory was lower than any other model.
Sentence length and speed: Measured on 180 sentences of varying length, MAT-2 was about as fast as FS2 on long sentences, and MAT-4 came close. GRAD-4 and GCFM-4 were much slower, and the gap with MAT widened as sentences got longer. The speed difference comes mainly from the new decoder architecture.
The paper states that MOS depends on conditions such as the listener population and instructions, so it is not an absolute value, and comparing it with MOS from other papers is meaningless. Use the MOS in the table only for comparisons within this paper.
Practical Considerations
Keep the following points in mind when using Matcha-TTS.
Choose speed versus quality with the number of steps: The paper compared 2, 4, and 10 steps, and the quality difference between 4 and 10 steps was not significant. Choose according to your use case.
Set the temperature: In the paper's evaluation, the standard deviation of the starting noise is 0.667.
Evaluated on a single English speaker: The paper's experiments use only LJ Speech. Extending to multiple speakers and modeling durations stochastically are left as future work.
Durations are deterministic: The duration predictor predicts log durations with mean squared error, so the rhythm is the same every time for the same sentence. Variation in intonation comes from the starting noise.
A separate vocoder is needed: The output is a mel spectrogram. The paper combines HiFi-GAN with a denoising filter.
The paper's speed (RTF) was measured on an NVIDIA RTX 3090, including the vocoder (HiFi-GAN). On other GPUs, on CPUs, or with a different vocoder, the speed differences between models may change.
Comparison with Other Models
Probabilistic speech synthesis models that learn the text-speech alignment by themselves compare as follows.
Generates all the way to the waveform in one stage with variational inference and normalizing flows
Variational lower bound and adversarial training
Generates the waveform
1
All of them learn the alignment with monotonic alignment search.
Rough guidelines for choosing:
To get diffusion-level quality in few steps: Matcha-TTS fits. In the paper, it achieved a higher MOS with 4 steps than Grad-TTS with 10 steps.
To reduce training memory: Matcha-TTS needed the least training memory among the models compared.
To prioritize speed above all: The deterministic FastSpeech 2 runs fast even on short sentences. However, its MOS in the paper was the lowest of the models compared.
To have a single model including the vocoder: There are models like VITS that generate from text to waveform in one stage.
PyTorch example
โถShow code
python
import torch
import torch.nn as nn
import torch.nn.functional as F
"""
A small implementation of Matcha-TTS's OT-CFM (Section 3.1, Eq. (4) of the paper) and synthesis with the Euler method
PyTorch and torchaudio have no built-in Matcha-TTS
1. Training: draw t ~ U[0, 1] and x0 ~ N(0, I), and form the point ฯt on the straight path and the target velocity u
2. Bring the network v(ฯt | ฮผ, t) close to u (mean squared error)
3. Synthesis: from x0, repeat x โ x + ฮt ยท v(x | ฮผ, t) n times (first-order Euler method)
(The vector field network here is a small convolutional example. The real one is a 1D U-Net + Transformer)
"""
SIGMA_MIN = 1e-4
class VectorField(nn.Module):
"""v_t(x | ฮผ): concatenate the current x and the condition ฮผ, add the embedding of time t, and predict the velocity"""
def __init__(self, n_mels=80, hidden=256):
super().__init__()
self.t_emb = nn.Sequential(nn.Linear(1, hidden), nn.SiLU(), nn.Linear(hidden, hidden))
self.inp = nn.Conv1d(2 * n_mels, hidden, 3, padding=1)
self.mid = nn.Conv1d(hidden, hidden, 3, padding=1)
self.out = nn.Conv1d(hidden, n_mels, 3, padding=1)
def forward(self, x, mu, t): # x, mu: [B, 80, T], t: [B]
h = self.inp(torch.cat([x, mu], dim=1)) + self.t_emb(t[:, None])[:, :, None]
return self.out(F.silu(self.mid(F.silu(h))))
def ot_cfm_loss(net, x1, mu):
"""x1: real mel spectrogram [B, 80, T], mu: upsampled encoder output [B, 80, T]"""
b = x1.shape[0]
t = torch.rand(b, 1, 1) # t ~ U[0, 1]
x0 = torch.randn_like(x1) # x0 ~ N(0, I)
phi = (1 - (1 - SIGMA_MIN) * t) * x0 + t * x1 # point on the straight path
u = x1 - (1 - SIGMA_MIN) * x0 # target velocity (constant in t)
return F.mse_loss(net(phi, mu, t.view(b)), u)
@torch.no_grad()
def synthesise(net, mu, n_steps=4, temperature=0.667):
"""Solve the ODE from noise. n_steps is the number of network evaluations (NFE)"""
x = torch.randn_like(mu) * temperature # ฮผ is not used as the mean of the starting point
dt = 1.0 / n_steps
for k in range(n_steps):
t = torch.full((mu.shape[0],), k * dt)
x = x + dt * net(x, mu, t)
return x # mel spectrogram
net = VectorField()
x1 = torch.randn(2, 80, 120) # mel spectrogram (120 frames)
mu = torch.randn(2, 80, 120) # ฮผ upsampled with the monotonic alignment search alignment
loss = ot_cfm_loss(net, x1, mu) # in practice, the encoder and duration losses are added too
loss.backward()
net.eval()
mel = synthesise(net, mu, n_steps=2) # can synthesize even with 2 steps
print(loss.item(), mel.shape)
FAQ
Q. How does flow matching differ from diffusion models?
A.
Both generate data by gradually moving from noise to data, but they differ in what they learn and in the shape of the path. Diffusion models (such as DDPM) predict noise or scores, and their paths are curved. OT-CFM predicts the velocity along a path that connects noise and data in a straight line, so it can be solved accurately even with few steps. In the paper, retraining the same Grad-TTS architecture with OT-CFM raised the 4-step MOS from 3.20 to 3.57.
Q. How many steps should be used?
A.
The paper compared 2, 4, and 10 steps. The MOS values were 3.65, 3.77, and 3.84, and the difference between 4 and 10 was not significant. As a rule of thumb, use 2โ4 to prioritize speed and 10 to squeeze out a bit more quality.
Q. What does it share with Glow-TTS, and how does it differ?
A.
The alignment (monotonic alignment search) and the duration predictor follow the same ideas. The difference is the decoder: Glow-TTS passes once through an invertible normalizing flow, whereas Matcha-TTS solves an ODE in a few steps with a network that predicts velocity. Because Matcha-TTS's decoder does not need to be invertible, it can use flexible architectures such as U-Nets and Transformers.