patient-virtuel-dentiste / stt_engine.py
carlosduplar
build-small-hackathon: switch to modal.asgi_app, fix endpoint body parsing, base64 audio
4ff45b3
Raw History Blame
584 Bytes
import base64
import os
import httpx
MODAL_ENDPOINT = os.environ.get("MODAL_ENDPOINT_WHISPER", "")
MODAL_AUTH_TOKEN = os.environ.get("MODAL_AUTH_TOKEN", "")
def transcribe(audio_path: str) -> str | None:
if not MODAL_ENDPOINT:
raise RuntimeError("MODAL_ENDPOINT_WHISPER not set")
with open(audio_path, "rb") as f:
b64 = base64.b64encode(f.read()).decode()
resp = httpx.post(
MODAL_ENDPOINT,
json={"audio_base64": b64, "token": MODAL_AUTH_TOKEN},
timeout=30,
)
resp.raise_for_status()
return resp.json().get("text")