Skip to content

whisper: add progress_callback to transcribe() - #1459

Open
KAJI-JAPAN wants to merge 1 commit into
ml-explore:mainfrom
KAJI-JAPAN:whisper-progress-callback
Open

KAJI-JAPAN wants to merge 1 commit into
ml-explore:mainfrom
KAJI-JAPAN:whisper-progress-callback

Conversation

@KAJI-JAPAN

Copy link
Copy Markdown

What

Adds an optional progress_callback argument to mlx_whisper.transcribe(). It is called with (frames_done, total_frames) after each 30-second window is decoded or skipped as silence (a frame is 10 ms of audio). The default None keeps the current behaviour.

Why

transcribe() reports progress only through the tqdm bar (verbose=False) or by printing segments (verbose=True), so a program that embeds mlx-whisper (a web UI, a GUI, a job queue) cannot receive progress as a value. In my own small web app for transcribing lesson recordings, I currently monkey-patch mlx_whisper.transcribe.tqdm to read the frame count. That breaks silently on any refactor and leaks across concurrent calls.

The callback is also called when a window is skipped as no-speech. Without that, a recording that ends in silence stops reporting at the last voiced window (3000 of 6666 frames for the test audio plus 60 s of silence) even though transcription has finished. The tqdm bar has the same gap; I left it unchanged to keep this PR small.

Related: #1373 asks for a way to cancel or time out transcribe(). This PR does not solve that, because the callback runs between windows and not inside decode().

Tests

  • Added test_transcribe_progress_callback: the test audio plus 60 s of trailing silence. It checks that the callback is called more than once, frames_done never decreases, and the last call is (total, total). It fails without the call in the no-speech branch.
  • python -m unittest test in whisper/: 12 tests pass.
  • pre-commit run (black, isort) passes.
  • Checked manually that the calls are the same with verbose=None, False and True.

Call an optional progress_callback(frames_done, total_frames) after each
30-second window is decoded or skipped as silence, so that programs
embedding mlx-whisper can show progress without patching tqdm.
The default None keeps the current behaviour.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant