Word timings
let result = try await tts.generate("Highlight each word as it plays.")
for timing in result.wordTimings {
print(timing.wordIndex, timing.word, timing.startTime, timing.endTime)
}
Each KittenWordTiming contains:
| Field | Meaning |
|---|---|
wordIndex | Zero-based word index within the generated result |
word | Original display text for the word |
startTime | Start in seconds |
endTime | End in seconds |
Timings are derived from the model's predicted phoneme durations, not a second forced-alignment pass.
UI synchronization
Start the elapsed-time clock when playback actually starts. For native speaker output through speak(), the current public API does not expose a playback-start callback; generate first and use your own AVAudioEngine or player when precise synchronized UI is required.
Limits
- Timings can be empty when duration data is unavailable.
- Multi-chunk text can omit timing data.
- Punctuation and normalization can affect word mapping.
- Generate sentences or short paragraphs for best highlighting behavior.
generateStreaming() produces a separate timing array for each sentence result.