File size: 584 Bytes
4ff45b3 b05542b 4ff45b3 b05542b 4ff45b3 b05542b 4ff45b3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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")
|