Spaces:
Running
Running
File size: 1,114 Bytes
83a4e82 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import torch
from transformers import pipeline
from logging_config import logger
def run_whisper_transcription(wav_file_path: str, device: str):
try:
model_name = "distil-whisper/distil-small.en"
logger.info(f"Initialising Whisper ASR pipeline with model: {model_name}")
logger.info(f"Running pipeline on device: {device}")
asr_pipeline = pipeline(
"automatic-speech-recognition",
model=model_name,
device=0 if device == "cuda" else -1,
return_timestamps=True
)
logger.info("Whisper ASR pipeline initialised.")
logger.info(f"Starting transcription for file: {wav_file_path}")
# Perform transcription
result = asr_pipeline(wav_file_path)
transcription = result.get("text", "")
logger.info("Transcription completed successfully.")
yield transcription # Yield only the transcription string
except Exception as e:
err_msg = f"Error during transcription: {str(e)}"
logger.error(err_msg)
yield err_msg # Yield only the error message string
|