| import requests | |
| from config import GROQ_API_KEY, GROQ_STT_MODEL | |
| def speech_to_text(audio_file: str) -> str: | |
| if not GROQ_API_KEY: | |
| raise RuntimeError("GROQ_API_KEY is not set in config") | |
| url = "https://api.groq.ai/openai/v1/audio/transcriptions" | |
| headers = { | |
| "Authorization": f"Bearer {GROQ_API_KEY}" | |
| } | |
| with open(audio_file, "rb") as f: | |
| files = { | |
| "file": (audio_file, f, "audio/wav") | |
| } | |
| data = { | |
| "model": GROQ_STT_MODEL | |
| } | |
| response = requests.post(url, headers=headers, data=data, files=files) | |
| response.raise_for_status() | |
| result = response.json() | |
| return result.get("text", "") | |