Added progress bar
This commit is contained in:
+24
-2
@@ -1,6 +1,7 @@
|
|||||||
# Audio transcription logic using Faster Whisper
|
# Audio transcription logic using Faster Whisper
|
||||||
|
|
||||||
from faster_whisper import WhisperModel
|
from faster_whisper import WhisperModel
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
def transcribe_audio(input_path, output_path, model_size="medium", turbo=False):
|
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:
|
if model is None:
|
||||||
raise RuntimeError("Failed to initialize Whisper model with any compute type")
|
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 = ""
|
transcription = ""
|
||||||
for segment in segments:
|
segment_count = 0
|
||||||
|
|
||||||
|
for segment in segments_generator:
|
||||||
transcription += segment.text.strip() + "\n"
|
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:
|
with open(output_path, "w", encoding="utf-8") as f:
|
||||||
f.write(transcription.strip())
|
f.write(transcription.strip())
|
||||||
|
|
||||||
return transcription.strip()
|
return transcription.strip()
|
||||||
|
|||||||
Reference in New Issue
Block a user