Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
22 lines
746 B
TypeScript
22 lines
746 B
TypeScript
// Couples playback to the transcript: which line is being heard.
|
|
|
|
/** The part of a transcript line the lookup needs. */
|
|
export interface Timed {
|
|
start: number
|
|
end: number
|
|
}
|
|
|
|
/** Index of the line heard at `secs`: the one whose `[start, end)` holds
|
|
* it — of overlapping lines (both sides talking at once) the one that
|
|
* started last. `null` before the first line, in a pause between lines and
|
|
* after the last one. */
|
|
export function segmentAt(segments: readonly Timed[], secs: number): number | null {
|
|
let found: number | null = null
|
|
segments.forEach((segment, i) => {
|
|
if (segment.start <= secs && secs < segment.end) {
|
|
if (found === null || segment.start >= segments[found].start) found = i
|
|
}
|
|
})
|
|
return found
|
|
}
|