Playback
Playback is optional. generate() works without a player; speak() and play() require one.
Expo Audio
import * as ExpoAudio from 'expo-audio';
import {KittenTTS, createExpoAudioPlayer} from '@kittentts/react-native';
const tts = await KittenTTS.create({
player: createExpoAudioPlayer(ExpoAudio),
});
await tts.speak('This plays through Expo Audio.');
React Native Sound
import Sound from 'react-native-sound';
import {KittenTTS, createRNSoundPlayer} from '@kittentts/react-native';
const tts = await KittenTTS.create({
player: createRNSoundPlayer(Sound),
});
Generate, then play
const result = await tts.generate('Prepare the UI before playback.');
await tts.play(result, {
onPlaybackStart: () => {
startHighlighting(result.wordTimings);
},
});
onPlaybackStart should represent actual playback start, not the moment a temporary WAV begins loading.
Custom player
Implement the package AudioPlayer interface when your app already owns an audio pipeline. The adapter receives Float32 PCM and a 24 kHz sample rate, plus playback callbacks. Its promise should resolve after playback finishes when sequential behavior matters.
Browser
createBrowserAudioPlayer() encodes the result and plays it through browser audio. Browser autoplay policies still apply, so begin playback from a click or tap when required.