Python
pip install speechrouterAsync-first (httpx + websockets).
Client
Section titled “Client”from speechrouter import SpeechRouter
sr = SpeechRouter(api_key=os.environ["SPEECHROUTER_API_KEY"])# self-hosted: SpeechRouter(api_key=..., base_url="https://gateway.internal")with open("meeting.wav", "rb") as f: result = await sr.transcribe(model="openai/whisper-1", file=f)print(result["text"])
# URL input + subtitles outsrt = await sr.transcribe( model="assemblyai/universal-2", url="https://example.com/podcast.mp3", response_format="srt",)Streaming
Section titled “Streaming”async with sr.listen( model="soniox/stt-rt-v5", fallbacks=["deepgram/nova-3"], sample_rate=16000,) as stream: asyncio.create_task(feed_microphone(stream)) # stream.send_audio(pcm)
async for event in stream: match event["type"]: case "transcript" if event["is_final"]: print(event["text"]) case "utterance_end": await agent.respond()await stream.finalize() flushes finals and resolves when the gateway sends
done. Keepalives on idle sockets are automatic (keepalive=8.0).
Tokens & models
Section titled “Tokens & models”token = await sr.create_token(ttl_seconds=60) # for browser/mobile clientsmodels = await sr.list_models() # live catalog with pricesErrors
Section titled “Errors”Failures raise SpeechRouterError carrying the gateway’s
stable code.