17 lines
581 B
Python
17 lines
581 B
Python
from transformers import pipeline
|
|
|
|
class WhisperTranscriber:
|
|
def __init__(self, model_name: str, device: str = "cuda"):
|
|
print("Loading Whisper model...")
|
|
self.pipe = pipeline(
|
|
task="automatic-speech-recognition",
|
|
model=model_name,
|
|
tokenizer=model_name,
|
|
device=0 if device == "cuda" else -1
|
|
)
|
|
print("Whisper model loaded.")
|
|
|
|
def transcribe(self, audio_file: str) -> str:
|
|
result = self.pipe(audio_file, batch_size=4, return_timestamps=True)
|
|
return result.get("text", "").strip()
|