alignment/aligner
Alignment algorithm — map transcript turn boundaries to audio timestamps.
Strategy: whisper.cpp word timestamps give absolute time for every word in the audio. The transcript parser gives words per turn. We distribute expected turn boundaries proportionally across the audio timeline, then snap each boundary to the LARGEST silence gap within a ±3s window.
This is robust to whisper hallucinations (ggml-tiny/base mishears words) because we DON’T try to match transcript text to whisper text — we only use the TIMESTAMPS from whisper’s AUDIO analysis, and the word-COUNT distribution from the transcript.
Types
pub type AlignError {
NoWordTimestamps
EmptyTranscript
ComputationFailed(String)
}
Constructors
-
NoWordTimestamps -
EmptyTranscript -
ComputationFailed(String)
An aligned turn with absolute audio start/end times (seconds).
pub type AlignedTurn {
AlignedTurn(
index: Int,
role: dialogue_types.Role,
text: String,
word_count: Int,
audio_start_s: Float,
audio_end_s: Float,
)
}
Constructors
-
AlignedTurn( index: Int, role: dialogue_types.Role, text: String, word_count: Int, audio_start_s: Float, audio_end_s: Float, )
A single gap between consecutive whisper words where silence > threshold.
pub type SilenceGap {
SilenceGap(start: Float, end: Float, duration: Float)
}
Constructors
-
SilenceGap(start: Float, end: Float, duration: Float)
Values
pub fn align_turns(
turns: List(dialogue_types.Turn),
words: List(whisper_driver.Word),
audio_duration_s: Float,
) -> Result(List(AlignedTurn), AlignError)
Align transcript turns to whisper word timestamps.
pub fn count_words(text: String) -> Int
pub fn find_silence_gaps(
words: List(whisper_driver.Word),
threshold_s: Float,
) -> List(SilenceGap)
pub fn flatten_words(
segments: List(whisper_driver.Segment),
) -> List(whisper_driver.Word)
pub fn transcription_words(
t: whisper_driver.Transcription,
) -> List(whisper_driver.Word)