From b6e6e80cfbeb626c13a3f787952e18eb048d71bc Mon Sep 17 00:00:00 2001 From: Heiko Joerg Schick Date: Thu, 22 May 2025 20:31:18 +0200 Subject: [PATCH] Added progress bar --- src/transcriber.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/transcriber.py b/src/transcriber.py index c493cfd..9dc158f 100644 --- a/src/transcriber.py +++ b/src/transcriber.py @@ -1,6 +1,7 @@ # Audio transcription logic using Faster Whisper from faster_whisper import WhisperModel +from tqdm import tqdm def transcribe_audio(input_path, output_path, model_size="medium", turbo=False): """ @@ -35,10 +36,31 @@ def transcribe_audio(input_path, output_path, model_size="medium", turbo=False): if model is None: raise RuntimeError("Failed to initialize Whisper model with any compute type") - segments, info = model.transcribe(input_path) + # Create a progress bar for the transcription process + print(f"Starting transcription of {input_path}...") + + # Initialize a progress bar without a known total + # We'll update it as segments come in + progress_bar = tqdm(desc="Transcribing", unit="segment") + + # Transcribe the audio + segments_generator, info = model.transcribe(input_path) + + # Process the segments and update the progress bar as we go transcription = "" - for segment in segments: + segment_count = 0 + + for segment in segments_generator: transcription += segment.text.strip() + "\n" + segment_count += 1 + progress_bar.update(1) + + # Close the progress bar + progress_bar.close() + + print(f"Transcription complete. Processed {segment_count} segments.") + with open(output_path, "w", encoding="utf-8") as f: f.write(transcription.strip()) + return transcription.strip()