Playback and queues
Browser helper
import {KittenTTS, createBrowserAudioPlayer} from '@kittentts/web';
const tts = await KittenTTS.create({
player: createBrowserAudioPlayer(),
});
await tts.speak('This plays through an HTML audio element.');
Browser autoplay policies apply. Call playback from a user interaction when required.
Generate, then play
const result = await tts.generate('Prepare the interface first.');
await tts.play(result, {
onPlaybackStart: () => startHighlighting(result.wordTimings),
});
FIFO queue
const queue = tts.createPlaybackQueue();
await queue.enqueue(firstResult);
await queue.enqueueText('Generate after earlier clips.', {voice: 'luna'});
queue.clear() rejects pending tasks. queue.stop() clears pending tasks and stops active audio. Queue properties expose total length, pending count, and active state.
Custom player
const player: AudioPlayer = {
async play(samples, sampleRate, options) {
options?.onPlaybackStart?.();
await sendToAudioEngine(samples, sampleRate);
},
async stop() {},
};
Use a custom adapter for Web Audio, Electron, game engines, server pipelines, or framework-owned media components. Resolve play() after audio finishes when strict queue sequencing is required.