Voice agents & migration
Switch existing OpenAI, ElevenLabs, or Deepgram audio code in minutes, wire a sub-second conversational agent loop, or hand our docs directly to your AI coding assistant.
Drop-in OpenAI SDK swap
Spero and Odesa expose OpenAI-compatible paths (/v1/audio/transcriptions and /v1/audio/speech). Point your existing openai client at https://api.spero.audio/v1 with your SPERO_API_KEY — no custom wrapper SDK required.
import os
from openai import OpenAI
# 1. Point the official OpenAI SDK at Spero
client = OpenAI(
base_url="https://api.spero.audio/v1",
api_key=os.environ["SPERO_API_KEY"],
)
# 2. Speech to text (replaces whisper-1 / gpt-transcribe)
with open("call.wav", "rb") as f:
tx = client.audio.transcriptions.create(
model="odesa-1-pro",
file=f,
language="en",
extra_body={"smart_format": True},
)
# 3. Text to speech (replaces tts-1 / gpt-4o-mini-tts)
audio = client.audio.speech.create(
model="spero-v1",
voice="spero-f1",
input=f"Thanks, I heard: {tx.text}",
)
audio.write_to_file("reply.mp3")Migrating from OpenAI, ElevenLabs, or Deepgram
Compare exact header, URL, and model swaps below:
- client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
+ client = OpenAI(
+ base_url="https://api.spero.audio/v1",
+ api_key=os.environ["SPERO_API_KEY"],
+ )
tx = client.audio.transcriptions.create(
- model="gpt-transcribe", # $0.27/hr batch · $1.02/hr live · 6.38% MAIN-7
+ model="odesa-1-pro", # $0.09/hr batch & live · 4.29% MAIN-7
file=audio,
+ extra_body={"smart_format": True},
)| Concept | OpenAI Audio | ElevenLabs | Deepgram | Spero / Odesa-1 |
|---|---|---|---|---|
| Auth header | Authorization: Bearer | xi-api-key | Authorization: Token | Authorization: Bearer sp_live_... |
| Batch STT | POST /v1/audio/transcriptions | POST /v1/speech-to-text | POST /v1/listen | POST /v1/audio/transcriptions |
| Live STT | GPT Live Transcribe ($1.02/hr) | Scribe v3 Live ($0.22/hr) | WS /v1/listen ($0.46/hr) | WS /v1/audio/stream ($0.036-$0.09/hr) |
| Formatting | Prompt-dependent | Automatic | smart_format=true | smart_format=true |
| Glossary bias | prompt | keyterms | keyterm | prompt (up to 1,000 chars, free) |
Building a real-time voice agent
A modular voice agent separates listening (WS /v1/audio/stream), turn-taking (Kuroko), reasoning (your LLM), and speaking (POST /v1/audio/speech with stream: true). Keeping a persistent HTTP keep-alive pool for TTS and a single long-lived WebSocket for STT minimizes turn-to-turn latency.
import asyncio, json, os, httpx, websockets
STT_URL = "wss://api.spero.audio/v1/audio/stream?model=odesa-1-pro&smart_format=true&vad_silence_ms=500"
TTS_URL = "https://api.spero.audio/v1/audio/speech"
HEADERS = {"Authorization": f"Bearer {os.environ['SPERO_API_KEY']}"}
async def stream_tts_reply(http: httpx.AsyncClient, text: str, send_pcm):
# Keep-alive HTTP client saves ~60 ms per turn; first audio arrives in ~330 ms.
async with http.stream(
"POST",
TTS_URL,
headers=HEADERS,
json={"model": "spero-v1", "voice": "spero-f1", "input": text, "stream": True, "response_format": "pcm"},
) as resp:
resp.raise_for_status()
async for pcm24k_chunk in resp.aiter_bytes(chunk_size=4800): # 100 ms jitter pre-buffer
await send_pcm(pcm24k_chunk)
async def run_agent(mic_frames, ask_llm, play_pcm):
async with httpx.AsyncClient(timeout=60.0) as http:
async with websockets.connect(STT_URL, additional_headers=HEADERS) as ws:
async def pump_mic():
async for pcm16k in mic_frames:
await ws.send(pcm16k)
async def handle_turns():
async for raw in ws:
ev = json.loads(raw)
if ev["type"] == "final" and ev["text"].strip():
reply = await ask_llm(ev["text"])
await stream_tts_reply(http, reply, play_pcm)
await asyncio.gather(pump_mic(), handle_turns())Latency budget breakdown
| Stage | Component | Typical timing |
|---|---|---|
| Live captioning (partial) | WS /v1/audio/stream (English) | ~24 ms |
| Turn finalization | VAD silence (vad_silence_ms=500) + Odesa-1 final | ~500-700 ms |
| Interruption detection | Kuroko 14.9M (local CPU) | ~560 ms median |
| First spoken audio | POST /v1/audio/speech (spero-f1, stream: true, keep-alive) | ~330 ms TTFB (~60 ms saved with keep-alive) |
Telephony & SIP pipelines (Twilio, LiveKit, Pipecat)
| Direction | Recommended audio handling |
|---|---|
| Inbound caller audio (8 kHz G.711 mu-law) | Decode mu-law to linear PCM16 and upsample 8 kHz -> 16 kHz mono before streaming binary frames into WS /v1/audio/stream. |
| Outbound agent speech (real-time) | Stream 24 kHz PCM16 from POST /v1/audio/speech (spero-f1, stream: true), downsample 24 kHz -> 8 kHz, and encode G.711 mu-law into your SIP/Twilio socket. |
| Prerecorded IVR prompts | Request response_format: "ulaw" directly from POST /v1/audio/speech to receive ready-to-play headerless 8 kHz G.711 mu-law. |
AI coding agents (llms.txt)
Every page of this documentation has a synchronized Markdown representation served specifically for AI coding agents (Cursor, Claude Code, Codex, Antigravity):
# Concise docs & model index (llms.txt standard)
https://spero.audio/llms.txt
# Complete single-file Markdown API manual
https://spero.audio/llms-full.txt
# Single page as clean Markdown
https://spero.audio/api/docs/markdown?path=/docs/streaming