Skip to content

Transcribe long audio in windows cut at quiet points - #178

Merged
A21-devs merged 2 commits into
mainfrom
feat/whisper-windows
Dec 5, 2026
Merged

A21-devs merged 2 commits into
mainfrom
feat/whisper-windows

Conversation

@A21-devs

@A21-devs A21-devs commented Dec 5, 2026

Copy link
Copy Markdown
Owner

Part of #166 (and so of #22).

What

The transcription side of feeding whisper the audio in pieces. Nothing calls it with more than one window yet; wiring it into analyze() so the samples are never all in memory is the next PR.

  • transcribe.plan_windows(db, hop, duration, length=600, search=30) splits the track into back-to-back windows of about 10 minutes. Each cut moves to the middle of the quietest hop of the loudness curve within 30 s of the planned point (on a tie, the hop closest to the plan, so a flat curve cuts on the plan). A tail shorter than search is folded into the last window instead of becoming a tiny window of its own. If the curve is shorter than the duration, the cut stays on the plan.
  • transcribe.transcribe_windows(read, windows, ...) loads the model once, then for each window calls read(start, duration) right before whisper needs the samples and adds the window's start to every word time. Progress is reported against the whole track. The CUDA→CPU fallback works as before: a CUDA failure throws away what was done and starts every window over on the CPU, so no window is transcribed twice in the result.
  • transcribe.transcribe(audio, ...) is now the one-window case, same behavior and same log lines as before.

Testing

  • uv run ruff check src tests, uv run mypy, uv run pytest -q: 744 passed.
  • New tests/test_whisper_windows.py (fake faster_whisper): short audio is one window, cuts land on the quietest hop near the plan, flat curves cut on the plan, a 3 h random curve gives back-to-back windows of 570-630 s that cover everything, a short tail is merged, a short curve cuts on the plan; transcribe_windows reads each window once in order, loads one model, offsets the words and reports progress up to 1.0; a CUDA failure re-runs all windows on CPU without duplicate words; no windows loads nothing; transcribe() still makes one call with the whole array.
  • Real whisper (small, CUDA) on a synthetic 240 s video: 205 s of Windows TTS speech mixed into Roblox gameplay at 20 s, over pink noise. Single call vs. 60 s windows (search 10 s, so there are three joins) with each window decoded by audio.decode_pcm(start=, duration=):
    • windows (0, 56.25) (56.25, 111.25) (111.25, 179.75) (179.75, 240), every cut in a pause between sentences
    • 501 words both ways, difflib finds no inserted, dropped or changed word
    • word start times differ by 0.017 s on average, 0.41 s at most (the first word after a cut gets whisper's window-start timestamp)

plan_windows() splits the track into ~10 minute windows, moving each cut
to the quietest hop within 30 s of the plan. transcribe_windows() loads
the model once and asks for each window's samples only when whisper
needs them, adding the window's offset to the word times. transcribe()
is now the one-window case.

@A21-devs A21-devs left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read through the planner and the per-window loop, and reran the TTS comparison from the description. Window joins look right: back-to-back, no word dropped or doubled at the three cuts, and the CUDA retry starts from an empty list so a partial GPU attempt can't leak words into the CPU result. plan_windows can't loop forever (lo is always past start, and the fallback cut is start + length).

One real issue with progress, inline. Also an observation, nothing to change here: the first word after a cut gets the window's start as its start time (Alright, at 111.25 and 179.75, exactly the cut). That's whisper timing from the start of the buffer it was given, and it's where the 0.41 s max difference comes from. With 10 minute windows that's one word per 10 minutes showing up a few hundred ms early in the captions.

if text:
words.append(Word(start + float(w.start), start + float(w.end), text))
if on_progress and total > 0:
on_progress((start + float(seg.end)) / total)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Progress only moves when whisper yields a segment. With vad_filter=True a window with no speech (a 10 minute stretch of menu music or gameplay without talking is normal in a VOD) yields nothing, so the bar sits at the previous window's last segment for the whole window and then jumps. The old single call had the same gap, but now we know where each window ends, so reporting end / total after the loop over segments is free and keeps the bar moving on long silent stretches.

@A21-devs

A21-devs commented Dec 5, 2026

Copy link
Copy Markdown
Owner Author

Fixed in 9aee605: after the loop over a window's segments, _run reports end / total, so a window without speech still moves the bar (the monotonic wrapper drops it when the last segment already ended there).

Verified:

  • New test test_progress_moves_past_a_window_without_speech (fake model that yields no segments for the middle window): reports [590/1500, 1200/1500, 1.0]. It fails on the previous commit, where the middle window never reported.
  • Real whisper small on the 240 s TTS video with 60 s windows: all four window ends (0.2344, 0.4635, 0.749, 1.0) show up in the progress calls, 501 words as before. The first 20 s of that video have no speech; the first report is now at 0.095 from the first segment.
  • ruff, mypy clean; tests/test_whisper_windows.py + tests/test_whisper_load.py 18 passed.

The first-word timing at a cut is unchanged, as said in the review.

@A21-devs A21-devs left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second pass over 9aee605. The progress finding is fixed: end / total is reported after each window's segments, outside the segment loop, so a window that yields nothing still advances, and it's after the last segment so it can't go backwards. The new test fails on the parent commit and passes here. Nothing else changed in the diff. Clean.

A window with no speech yields no segments, so the bar sat still for the
whole window and then jumped.
@A21-devs
A21-devs merged commit 1f1a6c0 into main Dec 5, 2026
4 checks passed
@A21-devs
A21-devs deleted the feat/whisper-windows branch December 5, 2026 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant