Skip to content

Commit

Permalink
feat: progress callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
deeeed committed Feb 5, 2025
1 parent 44e8bf5 commit 696679c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions whisperx/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def align(
return_char_alignments: bool = False,
print_progress: bool = False,
combined_progress: bool = False,
progress_callback=None,
) -> AlignedTranscriptionResult:
"""
Align phoneme recognition predictions to known transcription.
Expand Down Expand Up @@ -147,6 +148,8 @@ def align(
base_progress = ((sdx + 1) / total_segments) * 100
percent_complete = (50 + base_progress / 2) if combined_progress else base_progress
print(f"Progress: {percent_complete:.2f}%...")
if progress_callback:
progress_callback(percent_complete)

num_leading = len(segment["text"]) - len(segment["text"].lstrip())
num_trailing = len(segment["text"]) - len(segment["text"].rstrip())
Expand Down
7 changes: 5 additions & 2 deletions whisperx/asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def transcribe(
print_progress=False,
combined_progress=False,
verbose=False,
progress_callback=None,
) -> TranscriptionResult:
if isinstance(audio, str):
audio = load_audio(audio)
Expand Down Expand Up @@ -258,6 +259,8 @@ def data(audio, segments):
base_progress = ((idx + 1) / total_segments) * 100
percent_complete = base_progress / 2 if combined_progress else base_progress
print(f"Progress: {percent_complete:.2f}%...")
if progress_callback:
progress_callback(percent_complete)
text = out['text']
if batch_size in [0, 1, None]:
text = text[0]
Expand Down Expand Up @@ -364,8 +367,8 @@ def load_model(
"without_timestamps": True,
"max_initial_timestamp": 0.0,
"word_timestamps": False,
"prepend_punctuations": "\"'¿([{-",
"append_punctuations": "\"'.。,,!!??::)]}、",
"prepend_punctuations": "\"'¿([{-",
"append_punctuations": "\"'.。,,!!??::"")]}、",
"multilingual": model.model.is_multilingual,
"suppress_numerals": False,
"max_new_tokens": None,
Expand Down

0 comments on commit 696679c

Please sign in to comment.