Skip to main content

Generation and streaming

Generate one result

const result = await tts.generate('Save this as audio.', {
voice: 'luna',
speed: 1.05,
});

console.log(result.samples); // Float32Array
console.log(result.sampleRate); // 24000
console.log(result.duration);
console.log(result.wordTimings);

Encode output

const wav = result.wavData();
const wavBase64 = result.wavBase64();
const mp3 = await result.mp3Data({bitRate: 128});
const mp3Base64 = await result.mp3Base64({bitRate: 128});

Stream long input

for await (const chunk of tts.stream(articleText, {
voice: 'jasper',
speed: 1.0,
})) {
await tts.play(chunk);
}

The SDK divides long text into sentence groups and yields a complete result after each local inference. This improves time to first audio and provides UI update boundaries.

Resource lifecycle

Reuse the initialized instance. Call dispose() when the application is permanently finished with it. Analytics can be disabled with analytics: false; no input text or generated audio is included in the anonymous generation metadata.