fix(subtitles): tolerate regressing word timestamps

SRT conversion previously rejected otherwise valid word timestamps when a
start preceded the previous word's start. Clamp regressing starts to the
preceding nonempty word's start and extend ends only when necessary.
Preserve transcript order and the original response while continuing to
reject malformed timestamps. Document the adjustment and cover regressions,
cue boundaries, blank words, and invalid input.

Test Plan:
- python3 -B -m unittest -v: all eight tests passed.
- CLI conversion of a synthetic regressing response: passed.
- git diff --cached --check: passed.
- Actual recording verification blocked by unavailable 1Password auth.
This commit is contained in:
2026-09-05 16:27:03 +02:00
parent 4d7fcb1c8f
commit f8e50e4a3e
3 changed files with 55 additions and 5 deletions
+8 -3
View File
@@ -59,12 +59,17 @@ def convert(response):
or end < start
):
raise ValueError("Invalid subtitle word: expected finite 0 <= start <= end")
if start < previous_start:
raise ValueError("Invalid subtitle words: timestamps are out of order")
previous_start = start
word = dict(item, word=" ".join(item["word"].split()))
if not word["word"]:
continue
# Keep transcript order even when the model's word alignment moves
# backwards. Sorting by time would scramble the spoken text. Clamp
# only regressing starts, retaining the end unless it now precedes
# the start. Work on a copy so the API response remains unchanged.
start = max(start, previous_start)
end = max(end, start)
word.update(start=start, end=end)
previous_start = start
if len(lines(word["word"])) > 2:
raise ValueError("Invalid subtitle word: text exceeds two lines")
if current: