Speech to text · Odesa-1
Live streaming
Stream live microphone or telephony audio over a single WebSocket to get real-time partial transcripts with a stable caption prefix and automatic turn finalization.
~24 ms partials16 kHz PCM16 monoFlat $0.036-$0.09/hrZero streaming tax
WSS
wss://api.spero.audio/v1/audio/streamAudio wire format
Send raw binary WebSocket frames containing 16 kHz, mono, signed 16-bit little-endian PCM (int16) with no WAV header. At 16 kHz x 2 bytes/sample, the exact byte rate is 32,000 bytes/second.
| Property | Required value | Recommended chunk size |
|---|---|---|
| Encoding | Linear PCM signed 16-bit LE (int16) | 100 ms = 3,200 bytes (lowest latency) |
| Sample rate | 16000 Hz | 200 ms = 6,400 bytes (balanced default) |
| Channels | 1 (mono) | Resample 8 kHz G.711 telephony to 16 kHz PCM16 before sending |
Authentication
Three secure authentication paths are supported depending on where your WebSocket client runs:
- Server-side backends (recommended): send
Authorization: Bearer sp_live_...on the WebSocket HTTP upgrade request. - Browsers via WebSocket subprotocol: mint a short-lived session JWT on your backend and open
new WebSocket(url, ["spero-auth", `bearer.$${jwt}`]). - First-frame JSON auth: connect without an auth header and send
{"type":"auth","token":"<jwt>"}as the first text frame within 5 seconds.
Query parameters
modelstringoptionaldefault odesa-1-proodesa-1-pro ($0.09/hr), odesa-1-fast ($0.054/hr), or odesa-1-mini ($0.036/hr). No streaming surcharge.languagestringoptionaldefault enAny of our 36 supported ISO codes or
auto. Streams live partial captions as you speak and commits a final transcript on each turn pause.smart_formatbooleanoptionaldefault falseApply inverse text normalization (times, phone numbers, currency, dates) to English partials and finals.
transcription_modestringoptionaldefault verbatimverbatim, clean (strip fillers and stutters in real time), or verbatim_latin.vad_silence_msintegeroptionaldefault 600Range 200 to 3000 ms. Silence duration required after speech before committing a final turn. Lower (400-500 ms) for brisk voice agents; higher (700-1000 ms) for dictation.
partial_msintegeroptionaldefault 320Range 150 to 2000 ms. Minimum cadence between live partial updates while the speaker is talking.
vad_rmsfloatoptionaldefault 0.012Range 0.001 to 0.2. Normalized PCM16 RMS speech threshold. Lower slightly for quiet microphones; raise for noisy call floors.
max_turn_sfloatoptionaldefault 16.0Range 3.0 to 30.0 seconds. Maximum continuous speech duration before forcing a clean turn finalization.
Protocol lifecycle & events
Binary frames carry PCM16 audio; UTF-8 text frames carry JSON control messages and server events. Every partial includes both text (full live hypothesis) and stable (the committed prefix unlikely to change, ideal for low-flicker UI rendering or early LLM prefill).
Client control frames (JSON)
Client JSON
// Force-finalize the currently buffered speech turn without closing the socket
{"type": "flush"} // alias: {"type": "end_turn"}
// Finalize any pending turn, emit session_summary + final usage, and close cleanly
{"type": "stop"}
// Option C auth: if not using Authorization header or subprotocol, send within 5s of connect
{"type": "auth", "token": "<short-lived-session-jwt-or-key>"}Server events (JSON)
Server JSON
// 1. Sent immediately after connect & auth
{
"type": "ready",
"model": "odesa-1-pro",
"language": "en",
"transcription_mode": "verbatim",
"smart_format": true
}
// 2. Live caption updates while speaking (~24 ms partial latency in English)
{
"type": "partial",
"text": "Hi I need to reschedule my Tuesday",
"stable": "Hi I need to reschedule",
"audio_s": 1.84,
"latency_ms": 23.8
}
// 3. Committed turn once vad_silence_ms elapses (or after client {"type":"flush"})
{
"type": "final",
"turn_id": 1,
"text": "Hi, I need to reschedule my Tuesday 2:30 PM appointment.",
"audio_s": 3.42,
"total_audio_s": 3.42,
"latency_ms": 640.2
}
// 4. Settled every 60 seconds of streamed audio and again on close
{
"type": "usage",
"audio_seconds": 60.0,
"cost_usd": "0.001500",
"total_audio_seconds": 60.0,
"total_cost_usd": "0.001500"
}
// 5. Sent after {"type":"stop"} before clean close
{
"type": "session_summary",
"total_audio_s": 142.4,
"turns": 12
}Code examples
import asyncio, json, os, websockets
async def main():
url = (
"wss://api.spero.audio/v1/audio/stream"
"?model=odesa-1-pro&language=en&smart_format=true"
"&vad_silence_ms=600&partial_ms=320"
)
headers = {"Authorization": f"Bearer {os.environ['SPERO_API_KEY']}"}
async with websockets.connect(url, additional_headers=headers) as ws:
ready = json.loads(await ws.recv())
print("Connected:", ready)
async def send_audio():
with open("pcm16_16k_mono.raw", "rb") as f:
while chunk := f.read(6400): # 200 ms chunks (16 kHz * 2 bytes)
await ws.send(chunk)
await asyncio.sleep(0.2)
await ws.send(json.dumps({"type": "stop"}))
async def read_events():
async for raw in ws:
ev = json.loads(raw)
if ev["type"] == "partial":
print("...", ev["text"])
elif ev["type"] == "final":
print(f"[turn {ev['turn_id']}] {ev['text']}")
elif ev["type"] == "usage":
print("Billed:", ev["total_cost_usd"])
await asyncio.gather(send_audio(), read_events())
asyncio.run(main())Billing, session limits & close codes
- Minimum balance at connect: your account must hold at least 60 seconds of credit for the selected model ($0.0015 for
odesa-1-pro). - Incremental settlement: exact PCM16 audio bytes streamed are billed per whole second ceiling every 60 seconds and again on close, emitted as
usageevents. - Session duration & concurrency: up to 45 minutes per connection and 4 concurrent live streams per key and account. If a session reaches 45 minutes, the server emits an
errorevent (session_limit) before closing so you can reconnect seamlessly on the next turn. - Close codes:
4400invalid param/model ·4401auth error ·4402insufficient balance ·4429rate/concurrency limit ·4503service temporarily unavailable. See Errors & limits.