API reference
KittenTTS
public actor KittenTTS
| API | Purpose |
|---|---|
init(_:downloadProgressHandler:) async throws | Prepare assets and ONNX session |
generate(_:voice:speed:) async throws | Return one result |
generateStreaming(_:voice:speed:) | Return an AsyncThrowingStream |
speak(_:voice:speed:) async throws | Generate and play |
stopSpeaking() | Stop current playback |
isModelCached(for:) | Check one configuration |
isModelCached(_:) | Check one model |
prewarm(config:) async throws | Download and initialize early |
KittenTTSConfig
| Property | Default |
|---|---|
model | .nano |
defaultVoice | .bella |
speed | 1.0, clamped to 0.5–2.0 |
phonemizer | .builtin |
storageDirectory | Application Support |
modelFiles | nil |
ortNumThreads | 4 |
maxTokensPerChunk | 400, minimum 50 |
KittenTTSResult
Contains [Float] samples, a 24 kHz sample rate, computed duration, voice, effective speed, original text, word timings, wavData(), and writeWAV(to:).
Error cases
emptyInput, engineNotReady, modelFileNotFound, voicesFileNotFound, noVoiceEmbedding, inferenceFailed, emptyOutput, downloadFailed, invalidModelData, espeakNotInstalled, phonemizerLoadFailed, audioSessionFailed, and playbackFailed.
Use error.localizedDescription for user-facing diagnostic text and switch on KittenTTSError when recovery differs by case.