WordHighlight

data class WordHighlight(val utteranceId: String, val start: Int, val end: Int)

Represents the word (or text range) currently being spoken by the TTS engine.

Positions refer to the original text passed to BetterFrenchTts.speak or BetterFrenchTts.speakAndAwait. For DSL-based calls, positions refer to the generated SSML and may not map directly to any single source string.

Usage with Compose

var highlight by remember { mutableStateOf<WordHighlight?>(null) }

tts.onWordHighlight { highlight = it }

val annotated = buildAnnotatedString {
val h = highlight
if (h != null && h.start in text.indices && h.end <= text.length) {
append(text.substring(0, h.start))
withStyle(SpanStyle(background = Color.Yellow)) {
append(text.substring(h.start, h.end))
}
append(text.substring(h.end))
} else {
append(text)
}
}

Constructors

Link copied to clipboard
constructor(utteranceId: String, start: Int, end: Int)

Properties

Link copied to clipboard
val end: Int

End index (exclusive) of the currently spoken range in the original text.

Link copied to clipboard
val start: Int

Start index (inclusive) of the currently spoken range in the original text.

Link copied to clipboard

The unique identifier of the utterance being spoken.