import os from groq import Groq class Transcriber: def __init__(self): # We need 'os' imported to access environment variables self.api_key = os.environ.get("GROQ_API_KEY", "") self.client = Groq(api_key=self.api_key) self._last_segments = [] # Required for stats in main.py def transcribe(self, audio_path, src_lang="auto"): with open(audio_path, "rb") as file: # Groq's Whisper handles 'auto' if language is None lang_param = None if src_lang == "auto" else src_lang response = self.client.audio.transcriptions.create( file=(audio_path, file.read()), model="whisper-large-v3", response_format="verbose_json", language=lang_param ) # Capture segments for the 'word_segments' stat in main.py self._last_segments = getattr(response, 'segments', []) # Return 3 values: transcript, detected language, method label # These match the unpacking expectation in main.py detected_lang = getattr(response, 'language', src_lang) return response.text, detected_lang, "Groq Whisper Large-v3"