TTS: VITS Coqui (German)

Generate speech with the VITS Coqui German (CSS10) model. It supports both synchronous and asynchronous generation.

For model documentation, see VITS Coqui.

Source files

Synchronous generation

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

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-coqui-de-css10.tar.bz2
    tar xf vits-coqui-de-css10.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_coqui_de.js
    node tts_vits_coqui_de_async.js
    

Notes

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

  • This model does not use dataDir (no espeak-ng dependency).

  • 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.