TTS: Matcha (English)
Generate speech with the Matcha English (ljspeech) model. Matcha uses a separate vocoder model (Vocos) for waveform synthesis and supports both synchronous and asynchronous generation.
For model documentation, see Matcha English.
Source files
Synchronous generation
1// Copyright (c) 2025 Xiaomi Corporation
2//
3// Text-to-speech with the Matcha English (ljspeech) model.
4// Requires a separate vocoder model (vocos-22khz-univ.onnx).
5//
6// Usage:
7// node tts_matcha_en.js
8//
9const sherpa_onnx = require('sherpa-onnx-node');
10
11function createOfflineTts() {
12 const config = {
13 model: {
14 matcha: {
15 acousticModel: './matcha-icefall-en_US-ljspeech/model-steps-3.onnx',
16 vocoder: './vocos-22khz-univ.onnx',
17 tokens: './matcha-icefall-en_US-ljspeech/tokens.txt',
18 dataDir: './matcha-icefall-en_US-ljspeech/espeak-ng-data',
19 },
20 debug: true,
21 numThreads: 1,
22 provider: 'cpu',
23 },
24 maxNumSentences: 1,
25 };
26 return new sherpa_onnx.OfflineTts(config);
27}
28
29const tts = createOfflineTts();
30
31const text =
32 'Today as always, men fall into two groups: slaves and free men. Whoever does not have two-thirds of his day for himself, is a slave, whatever he may be: a statesman, a businessman, an official, or a scholar.';
33
34const generationConfig = new sherpa_onnx.GenerationConfig({
35 sid: 0,
36 speed: 1.0,
37 silenceScale: 0.2,
38});
39
40let start = Date.now();
41const audio = tts.generate({text, generationConfig});
42let stop = Date.now();
43const elapsed_seconds = (stop - start) / 1000;
44const duration = audio.samples.length / audio.sampleRate;
45const real_time_factor = elapsed_seconds / duration;
46console.log('Wave duration', duration.toFixed(3), 'seconds');
47console.log('Elapsed', elapsed_seconds.toFixed(3), 'seconds');
48console.log(
49 `RTF = ${elapsed_seconds.toFixed(3)}/${duration.toFixed(3)} =`,
50 real_time_factor.toFixed(3));
51
52const filename = 'test-matcha-en.wav';
53sherpa_onnx.writeWave(
54 filename, {samples: audio.samples, sampleRate: audio.sampleRate});
55
56console.log(`Saved to ${filename}`);
Asynchronous generation
1// Copyright (c) 2026 Xiaomi Corporation
2//
3// Asynchronous text-to-speech with the Matcha English model.
4//
5// Usage:
6// node tts_matcha_en_async.js
7//
8const sherpa_onnx = require('sherpa-onnx-node');
9
10async function createOfflineTts() {
11 const config = {
12 model: {
13 matcha: {
14 acousticModel: './matcha-icefall-en_US-ljspeech/model-steps-3.onnx',
15 vocoder: './vocos-22khz-univ.onnx',
16 tokens: './matcha-icefall-en_US-ljspeech/tokens.txt',
17 dataDir: './matcha-icefall-en_US-ljspeech/espeak-ng-data',
18 },
19 debug: false,
20 numThreads: 1,
21 provider: 'cpu',
22 },
23 maxNumSentences: 1,
24 };
25 return await sherpa_onnx.OfflineTts.createAsync(config);
26}
27
28async function main() {
29 const tts = await createOfflineTts();
30
31 const text =
32 'Today as always, men fall into two groups: slaves and free men. Whoever does not have two-thirds of his day for himself, is a slave, whatever he may be: a statesman, a businessman, an official, or a scholar.';
33
34 const generationConfig = new sherpa_onnx.GenerationConfig({
35 sid: 0,
36 speed: 1.0,
37 silenceScale: 0.2,
38 });
39
40 const start = Date.now();
41 const audio = await tts.generateAsync({
42 text,
43 enableExternalBuffer: true,
44 generationConfig,
45 onProgress: ({samples, progress}) => {
46 process.stdout.write(
47 `Progress: ${(progress * 100).toFixed(1)}%, ` +
48 `Samples: ${samples.length}\r`);
49 return 1;
50 },
51 });
52
53 console.log('');
54 const stop = Date.now();
55 const elapsed_seconds = (stop - start) / 1000;
56 const duration = audio.samples.length / audio.sampleRate;
57 const real_time_factor = elapsed_seconds / duration;
58 console.log('Wave duration', duration.toFixed(3), 'seconds');
59 console.log('Elapsed', elapsed_seconds.toFixed(3), 'seconds');
60 console.log(
61 `RTF = ${elapsed_seconds.toFixed(3)}/${duration.toFixed(3)} =`,
62 real_time_factor.toFixed(3));
63
64 const filename = 'test-matcha-en-async.wav';
65 sherpa_onnx.writeWave(
66 filename, {samples: audio.samples, sampleRate: audio.sampleRate});
67 console.log(`Saved to ${filename}`);
68}
69
70main().catch((err) => {
71 console.error('Error:', err);
72});
How to run
Install the package:
npm install sherpa-onnx-node
Download the model and vocoder:
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/matcha-icefall-en_US-ljspeech.tar.bz2 tar xvf matcha-icefall-en_US-ljspeech.tar.bz2 rm matcha-icefall-en_US-ljspeech.tar.bz2 curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/vocoder-models/vocos-22khz-univ.onnx
Set the library path and run:
# macOS export DYLD_LIBRARY_PATH=$(npm root)/sherpa-onnx-node/lib:$DYLD_LIBRARY_PATH # Linux export LD_LIBRARY_PATH=$(npm root)/sherpa-onnx-node/lib:$LD_LIBRARY_PATH # Choose one: node tts_matcha_en.js node tts_matcha_en_async.js
Notes
The config key is
matchawith fields:acousticModel,vocoder,tokens,dataDir.Matcha requires a separate vocoder model. Download
vocos-22khz-univ.onnxand place it in the working directory.The sync API uses
new sherpa_onnx.OfflineTts(config)andtts.generate({text, generationConfig}).The async API uses
OfflineTts.createAsync()andtts.generateAsync()with anonProgresscallback.For Chinese, see TTS: Matcha (Chinese).