from abc import ABC, abstractmethod from transformers import pipeline class Transcriber(ABC): @abstractmethod def transcribe(self, file_path: str) -> str: pass class SpanishTranscriber(Transcriber): def __init__(self, pipe: pipeline) -> None: self.pipe = pipe def transcribe(self, file_path: str = "yt_audio.mp3") -> str: print("Pipe:", self.pipe) print("Audo file at:", file_path) transcription = self.pipe(file_path)["text"] return transcription class WhisperTranscriber(Transcriber): def __init__(self, model, without_timestamps: bool=True) -> None: self.model = model self.without_timestamps = without_timestamps def transcribe(self, file_path: str = "yt_audio.mp3") -> str: print("Model:", self.model) print("Audo file at:", file_path) transcription = self.model.transcribe(file_path, without_timestamps=self.without_timestamps)["text"] return transcription