Repository navigation
Transcribe long audio in windows cut at quiet points - #178
Conversation
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
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
|
Fixed in 9aee605: after the loop over a window's segments, Verified:
The first-word timing at a cut is unchanged, as said in the review. |
A21-devs
left a comment
There was a problem hiding this comment.
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.
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 thansearchis 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 callsread(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.tests/test_whisper_windows.py(fakefaster_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_windowsreads 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.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 byaudio.decode_pcm(start=, duration=):(0, 56.25) (56.25, 111.25) (111.25, 179.75) (179.75, 240), every cut in a pause between sentencesdifflibfinds no inserted, dropped or changed word