fix(recut): virtual_transcript must keep Whisper's word-boundary spaces

transcript_words() strips each word, so the remapped transcript handed to
the caption generators lost the leading-space convention the block
collector uses as its word-boundary signal — every recut/reframe with
re-applied captions burned the whole line glued together
("...creesycambiatodo"). Latent since the clip-editor merge; surfaced by
the first caption burn over a recut with real words.
This commit is contained in:
juancarlos.cavero 2026-08-19 12:22:39 +02:00
parent 3cff7e8cd6
commit 602f87674b
2 changed files with 14 additions and 6 deletions

View file

@ -159,14 +159,18 @@ def virtual_transcript(transcript, segments):
if w["e"] <= seg_start or w["s"] >= seg_end: if w["e"] <= seg_start or w["s"] >= seg_end:
continue continue
words.append({ words.append({
"word": w["w"], # Leading space = Whisper's word-boundary convention.
# transcript_words() strips it, and without it the caption
# block collector treats every word as a continuation fragment
# and burns the whole line glued together.
"word": " " + w["w"],
"start": round(max(0.0, w["s"] - seg_start) + offset, 3), "start": round(max(0.0, w["s"] - seg_start) + offset, 3),
"end": round(min(seg_duration, w["e"] - seg_start) + offset, 3), "end": round(min(seg_duration, w["e"] - seg_start) + offset, 3),
}) })
out_segments.append({ out_segments.append({
"start": round(offset, 3), "start": round(offset, 3),
"end": round(offset + seg_duration, 3), "end": round(offset + seg_duration, 3),
"text": " ".join(w["word"] for w in words), "text": "".join(w["word"] for w in words).strip(),
"words": words, "words": words,
}) })
offset += seg_duration offset += seg_duration

View file

@ -124,7 +124,10 @@ class TestVirtualTranscript:
v = recut.virtual_transcript(TRANSCRIPT, [_seg(10, 15), _seg(48, 52)]) v = recut.virtual_transcript(TRANSCRIPT, [_seg(10, 15), _seg(48, 52)])
assert v["language"] == "en" assert v["language"] == "en"
assert len(v["segments"]) == 2 assert len(v["segments"]) == 2
# "hello" (12.0-12.5 in source) → 2.0-2.5 on the clip. # "hello" (12.0-12.5 in source) → 2.0-2.5 on the clip. The leading
# space is Whisper's word-boundary convention: without it the caption
# block collector merges every word into one glued line (regression
# caught on a real burn: "...creesycambiatodo").
first = v["segments"][0] first = v["segments"][0]
assert first["words"] == [{"word": " hello", "start": 2.0, "end": 2.5}] assert first["words"] == [{"word": " hello", "start": 2.0, "end": 2.5}]
assert (first["start"], first["end"]) == (0.0, 5.0) assert (first["start"], first["end"]) == (0.0, 5.0)
@ -132,6 +135,7 @@ class TestVirtualTranscript:
second = v["segments"][1] second = v["segments"][1]
assert second["words"] == [{"word": " again", "start": 7.0, "end": 7.5}] assert second["words"] == [{"word": " again", "start": 7.0, "end": 7.5}]
assert (second["start"], second["end"]) == (5.0, 9.0) assert (second["start"], second["end"]) == (5.0, 9.0)
assert first["text"] == "hello"
def test_partial_overlap_is_clamped_to_the_segment(self): def test_partial_overlap_is_clamped_to_the_segment(self):
# Word 12.0-12.5, segment 12.3-20 → starts at 0, ends at 0.2. # Word 12.0-12.5, segment 12.3-20 → starts at 0, ends at 0.2.