TTS: VITS Piper (English)

Generate speech with the VITS Piper English (GB, cori-medium) model. VITS is a popular end-to-end TTS architecture. It supports both synchronous and asynchronous generation.

For model documentation, see VITS Piper.

Source files

Synchronous generation

 1// Copyright (c)  2024  Xiaomi Corporation
 2//
 3// Text-to-speech with the VITS Piper English (GB) model.
 4//
 5// Usage:
 6//   node tts_vits_piper_en.js
 7//
 8const sherpa_onnx = require('sherpa-onnx-node');
 9
10function createOfflineTts() {
11  const config = {
12    model: {
13      vits: {
14        model: './vits-piper-en_GB-cori-medium/en_GB-cori-medium.onnx',
15        tokens: './vits-piper-en_GB-cori-medium/tokens.txt',
16        dataDir: './vits-piper-en_GB-cori-medium/espeak-ng-data',
17      },
18      debug: true,
19      numThreads: 1,
20      provider: 'cpu',
21    },
22    maxNumSentences: 1,
23  };
24  return new sherpa_onnx.OfflineTts(config);
25}
26
27const tts = createOfflineTts();
28
29const text =
30    '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.';
31
32const generationConfig = new sherpa_onnx.GenerationConfig({
33  sid: 0,
34  speed: 1.0,
35  silenceScale: 0.2,
36});
37
38let start = Date.now();
39const audio = tts.generate({text: text, generationConfig});
40let stop = Date.now();
41const elapsed_seconds = (stop - start) / 1000;
42const duration = audio.samples.length / audio.sampleRate;
43const real_time_factor = elapsed_seconds / duration;
44console.log('Wave duration', duration.toFixed(3), 'seconds');
45console.log('Elapsed', elapsed_seconds.toFixed(3), 'seconds');
46console.log(
47    `RTF = ${elapsed_seconds.toFixed(3)}/${duration.toFixed(3)} =`,
48    real_time_factor.toFixed(3));
49
50const filename = 'test-vits-piper-en.wav';
51sherpa_onnx.writeWave(
52    filename, {samples: audio.samples, sampleRate: audio.sampleRate});
53
54console.log(`Saved to ${filename}`);

Asynchronous generation

 1// Copyright (c)  2026  Xiaomi Corporation
 2//
 3// Asynchronous text-to-speech with the VITS Piper English model.
 4//
 5// Usage:
 6//   node tts_vits_piper_en_async.js
 7//
 8const sherpa_onnx = require('sherpa-onnx-node');
 9
10async function createOfflineTts() {
11  const config = {
12    model: {
13      vits: {
14        model: './vits-piper-en_GB-cori-medium/en_GB-cori-medium.onnx',
15        tokens: './vits-piper-en_GB-cori-medium/tokens.txt',
16        dataDir: './vits-piper-en_GB-cori-medium/espeak-ng-data',
17      },
18      debug: false,
19      numThreads: 1,
20      provider: 'cpu',
21    },
22    maxNumSentences: 1,
23  };
24  return await sherpa_onnx.OfflineTts.createAsync(config);
25}
26
27async function main() {
28  const tts = await createOfflineTts();
29
30  const text =
31      '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.';
32
33  const generationConfig = new sherpa_onnx.GenerationConfig({
34    sid: 0,
35    speed: 1.0,
36    silenceScale: 0.2,
37  });
38
39  const start = Date.now();
40  const audio = await tts.generateAsync({
41    text,
42    enableExternalBuffer: true,
43    generationConfig,
44    onProgress: ({samples, progress}) => {
45      process.stdout.write(
46          `Progress: ${(progress * 100).toFixed(1)}%, ` +
47          `Samples: ${samples.length}\r`);
48      return 1;
49    },
50  });
51
52  console.log('');
53  const stop = Date.now();
54  const elapsed_seconds = (stop - start) / 1000;
55  const duration = audio.samples.length / audio.sampleRate;
56  const real_time_factor = elapsed_seconds / duration;
57  console.log('Wave duration', duration.toFixed(3), 'seconds');
58  console.log('Elapsed', elapsed_seconds.toFixed(3), 'seconds');
59  console.log(
60      `RTF = ${elapsed_seconds.toFixed(3)}/${duration.toFixed(3)} =`,
61      real_time_factor.toFixed(3));
62
63  const filename = 'test-vits-piper-en-async.wav';
64  sherpa_onnx.writeWave(
65      filename, {samples: audio.samples, sampleRate: audio.sampleRate});
66  console.log(`Saved to ${filename}`);
67}
68
69main().catch((err) => {
70  console.error('Error:', err);
71});

How to run

  1. Install the package:

    npm install sherpa-onnx-node
    
  2. Download the model:

    curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-en_US-amy-low.tar.bz2
    tar xf vits-piper-en_US-amy-low.tar.bz2
    
  3. 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_vits_piper_en.js
    node tts_vits_piper_en_async.js
    

Notes

  • The config key is vits with fields: model, tokens, dataDir.

  • VITS models from Piper are self-contained (no separate vocoder needed).

  • dataDir points to the espeak-ng data directory for phoneme conversion.

  • The sync API uses new sherpa_onnx.OfflineTts(config) and tts.generate({text, generationConfig}).

  • The async API uses OfflineTts.createAsync() and tts.generateAsync() with an onProgress callback.