Spaces:
Sleeping
transcript: spill pre-first-boundary cues into the first segment
Browse filesDeselecting the first topic in the topic-preview flow left the new
first kept segment starting well after the transcript did (e.g. the
surviving boundaries become [180s, ...] for a transcript that began
at 0s). _bucket_cues only matched cues whose midpoint fell inside
some [edges[i], edges[i+1]) window, so the opening narration was
silently dropped — several minutes of speech vanishing with no error.
Spill cues with midpoint < edges[0] into bucket 0 instead. The audio
slicer (cue_bounds_per_segment) shares the same bucketing, so its
first segment's bounds extend backwards in lockstep and the dropped
narration is recovered in audio too.
In the common case where the transcript begins at the same time as
the first kept segment, this is a no-op.
https://claude.ai/code/session_01EM8jiYxdVFy1w3LeJ9GBJg
Files changed (2)
184 unmodified lines1851861871881891901 unmodified line192193194195196197184 unmodified linescontains the cue's midpoint, then stitch sentences across boundaries.Shared by align_segments (text) and cue_bounds_per_segment (audio)so both stay in sync."""if not boundaries:return []1 unmodified linebuckets: list[list[Cue]] = [[] for _ in boundaries]for cue in cues:mid = (cue.start + cue.end) / 2.0for i in range(len(boundaries)):if edges[i] <= mid < edges[i + 1]:buckets[i].append(cue)184 unmodified lines1851861871881891901911921931941951961971981 unmodified line200201202203204205206207208184 unmodified linescontains the cue's midpoint, then stitch sentences across boundaries.Shared by align_segments (text) and cue_bounds_per_segment (audio)so both stay in sync.Cues with midpoints earlier than the first boundary spill into thefirst bucket rather than being silently dropped. That matters whenthe caller deselects the first topic in the topic-preview flow:without this spill, the opening narration would vanish because thenew first boundary starts well after the transcript does. For thecommon case where a transcript begins at the same time as the firstscene this is a no-op."""if not boundaries:return []1 unmodified linebuckets: list[list[Cue]] = [[] for _ in boundaries]for cue in cues:mid = (cue.start + cue.end) / 2.0if mid < edges[0]:buckets[0].append(cue)continuefor i in range(len(boundaries)):if edges[i] <= mid < edges[i + 1]:buckets[i].append(cue)
74 unmodified lines7576777879808182838474 unmodified linesdef test_align_segments_handles_cues_outside_range():cues = parse_transcript(VTT_SAMPLE)# All three cues end by 14s. With boundaries starting at 100s, none align.boundaries = [100.0]narrations = align_segments(cues, boundaries, total_duration=200.0)assert narrations == [[]]def test_align_segments_keeps_trailing_cues_when_total_duration_extends_past_last_boundary():74 unmodified lines7576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713874 unmodified linesdef test_align_segments_handles_cues_outside_range():cues = parse_transcript(VTT_SAMPLE)# All three cues end by 14s. With a single boundary at 100s the cues# all fall before it and now spill into the first (and only) segment# instead of being silently lost — see the head-deselection fix.boundaries = [100.0]narrations = align_segments(cues, boundaries, total_duration=200.0)assert len(narrations) == 1joined = " ".join(narrations[0])assert "Welcome to the lecture on photosynthesis." in joinedassert "Calvin cycle." in joineddef test_align_segments_spills_pre_first_boundary_cues_into_first_bucket():"""Deselecting the first topic in the topic-preview UI leaves thenew first kept segment starting well after the transcript does(e.g. boundaries [180s, ...] for a transcript that begins at 0s).The opening narration must land in the new first bucket insteadof being silently dropped — otherwise the user loses severalminutes of speech with no warning."""vtt = ("WEBVTT\n\n""1\n00:00:00.000 --> 00:00:30.000\n""Opening monologue for topic one.\n\n""2\n00:00:30.000 --> 00:01:00.000\n""Continued discussion of topic one.\n\n""3\n00:03:05.000 --> 00:03:10.000\n""Now we move on to topic two.\n")cues = parse_transcript(vtt)# Topic 1 (0–3:00) deselected; the surviving boundaries are just# topic 2's start (3:00) and the trailing edge of the video.boundaries = [180.0]narrations = align_segments(cues, boundaries, total_duration=300.0)assert len(narrations) == 1joined = " ".join(narrations[0])assert "Opening monologue for topic one." in joinedassert "Continued discussion of topic one." in joinedassert "Now we move on to topic two." in joineddef test_cue_bounds_cover_pre_first_boundary_cues():"""The same head-spill fix must extend the first segment's audiobounds backwards too, so the slicer captures the opening narrationin audio (not just text) when the first topic was deselected."""vtt = ("WEBVTT\n\n""1\n00:00:00.000 --> 00:00:30.000\nOpening.\n\n""2\n00:03:05.000 --> 00:03:10.000\nNext.\n")cues = parse_transcript(vtt)boundaries = [180.0]bounds = cue_bounds_per_segment(cues, boundaries, total_duration=300.0)assert bounds[0] is not Nonestart, end = bounds[0]# First-cue start is 0; without the spill fix this would be None.assert start == 0.0assert end >= 185.0 # extends through the trailing cuedef test_align_segments_keeps_trailing_cues_when_total_duration_extends_past_last_boundary():