TranscriptAlignment
A word-level comparison between the text someone was asked to say and what a speech recognizer heard.
Use it for read-aloud exercises: show the reference sentence, record the speaker, and align the transcript against the sentence to find matched, misheard, missed, and extra words:
val alignment = TranscriptAlignment.align(
reference = "The quick brown fox",
heard = listOf(TranscriptToken("the"), TranscriptToken("quick"), TranscriptToken("box")),
)
// alignment.tokens.map { it.status } is Match, Match, Omission, Substitution
alignment.tokens.map { it.status }Words are compared after normalization (case-folded, punctuation stripped, curly apostrophes straightened, hyphenated words split), so "Don’t" matches "don't". Numbers aren't spelled out, so a recognizer that writes "3" for a spoken "three" counts as a substitution.
The alignment is a minimum-edit-distance alignment over words, so a single missed word doesn't shift every following word into a mismatch. It measures what the recognizer understood, not pronunciation itself. A recognizer's language model often repairs mildly mispronounced words, so treat a clean alignment as "intelligible", not "perfect".
Properties
The share of reference words that were heard at all (matched, low-confidence, or substituted), from 0 to 1. An empty reference counts as complete.
The number of words in the reference text.
Every aligned position, in reading order.
Functions
The number of positions with the given status.