By Sagar Shankaran, Founder of CallSphere
Deep dive into the real-time STT → LLM → TTS pipeline that powers modern AI voice agents — latency, streaming, and error recovery.
Key takeaways
Even with the OpenAI Realtime API collapsing STT, LLM, and TTS into one endpoint, it is still useful to understand the pipeline as three distinct stages. You will still debug issues by stage. You will still profile latency by stage. And when a customer wants to swap in their own TTS (ElevenLabs, Cartesia, PlayHT) you need to know where the seams are.
This post is a deep dive into the real-time STT → LLM → TTS pipeline, including the streaming, back-pressure, and error-recovery patterns that separate production systems from demos.
mic/carrier ──► STT ──► LLM ──► TTS ──► speaker/carrier
│ │ │
▼ ▼ ▼
partials tokens audio frames
┌──────────────┐ PCM16 ┌──────────────┐ tokens ┌──────────────┐
│ STT stage │──────────► │ LLM stage │─────────► │ TTS stage │
│ streaming │ │ streaming │ │ streaming │
└──────────────┘ └──────────────┘ └──────────────┘
▲ │ │
│ │ │
└── interrupt on VAD ◄─────┘ │
▼
carrier / speaker
Batch STT will not work for real-time. You need partial transcripts that arrive every 100-300ms.
sequenceDiagram
autonumber
participant Client
participant Edge as Edge Worker
participant LLM as LLM Provider
participant DB as Logs and Trace
Client->>Edge: POST /chat (stream=true)
Edge->>LLM: messages.create(stream=true)
loop Each token
LLM-->>Edge: SSE chunk delta
Edge-->>Client: SSE chunk delta
Edge->>DB: append token to span
end
LLM-->>Edge: stop_reason=end_turn
Edge-->>Client: event: done
Edge->>DB: finalize trace
# Example using Deepgram streaming as an STT-only alternative
from deepgram import DeepgramClient, LiveOptions
dg = DeepgramClient(DG_KEY)
conn = dg.listen.asyncwebsocket.v("1")
await conn.start(LiveOptions(
model="nova-2",
encoding="linear16",
sample_rate=24000,
interim_results=True,
endpointing=300,
))
async def on_stt_message(result):
if result.is_final:
await on_user_utterance(result.channel.alternatives[0].transcript)
from openai import AsyncOpenAI
client = AsyncOpenAI()
async def stream_llm(messages):
async with client.chat.completions.stream(
model="gpt-4o",
messages=messages,
) as stream:
async for event in stream:
if event.type == "content.delta":
yield event.delta
# ElevenLabs streaming example
import requests
def stream_tts(text: str, voice_id: str):
url = f"https://api.elevenlabs.io/v1/text-to-speech/{voice_id}/stream"
with requests.post(
url,
headers={"xi-api-key": EL_KEY},
json={"text": text, "model_id": "eleven_turbo_v2_5"},
stream=True,
) as r:
for chunk in r.iter_content(chunk_size=1024):
yield chunk
async def handle_final_user_turn(text: str, session):
session.messages.append({"role": "user", "content": text})
buffer = ""
async for token in stream_llm(session.messages):
buffer += token
# Flush on sentence boundary
if buffer.endswith((".", "!", "?")):
for audio_chunk in stream_tts(buffer, session.voice_id):
await session.send_audio(audio_chunk)
buffer = ""
if buffer:
for audio_chunk in stream_tts(buffer, session.voice_id):
await session.send_audio(audio_chunk)
When VAD fires speech_started, you must cancel the in-flight LLM stream, drop any queued TTS chunks, and clear the carrier's playback buffer. Anything less and the caller will hear the agent keep talking over them.
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
async def on_interrupt(session):
session.llm_cancel_event.set()
await session.tts_queue.empty()
await session.carrier.clear_playback()
CallSphere uses the OpenAI Realtime API with gpt-4o-realtime-preview-2025-06-03 for the STT → LLM → TTS pipeline in most verticals because collapsing all three into one WebSocket keeps first-word latency under 1 second and simplifies interruption handling. The sales vertical swaps the TTS leg for ElevenLabs streaming via 5 GPT-4 specialists orchestrated through the OpenAI Agents SDK; the rest — 14 healthcare tools, 10 real estate agents, 4 salon agents, 7 after-hours escalation tools, 10 plus RAG IT helpdesk tools — stay on the unified Realtime pipeline.
Audio is PCM16 at 24kHz end-to-end; conversion to G.711 ulaw happens only at the Twilio boundary. Server VAD drives interruption. A GPT-4o-mini post-call pipeline writes sentiment, intent, lead score, satisfaction, and escalation flags into per-vertical Postgres databases. CallSphere supports 57+ languages with sub-second end-to-end response times.
Start with the Realtime API. Compose only if you need a specific voice or a specific STT model.
XTTS, Orpheus, and Coqui all work but add latency and operational overhead. Fine for staging, rarely for production.
Still reading? Stop comparing — try CallSphere live.
CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.
For greetings and holding phrases yes. Cache the audio and replay it directly.
Rely on server VAD to detect it and cancel the current response.
24kHz PCM16 matches the Realtime API and ElevenLabs Turbo. 16kHz works for STT-only stacks.
Want to see the full pipeline running on real traffic? Book a demo, read the technology page, or see pricing.
#CallSphere #STT #TTS #VoiceAI #Architecture #Streaming #AIVoiceAgents
Written by
Sagar Shankaran· Founder, CallSphere
Sagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
A how-to for Colombian education and tutoring SMBs to answer parents and students instantly, book trial classes 24/7 in Spanish and English, and grow enrollment with a CallSphere AI agent.
Tbilisi professional-services firms serving relocating founders and IT companies use CallSphere AI voice and chat agents to answer enquiries 24/7 in English, Georgian and Russian and book consultations.
A practical how-to for Palau eco-resorts and dive operators on capturing every high-value, multilingual enquiry with a CallSphere AI voice and chat agent, while honouring Palau’s marine-conservation commitments.
How salons, spas and wellness SMBs across the UAE, Saudi Arabia and Qatar use CallSphere AI voice and chat agents to capture every booking 24/7 in Arabic, English and expat languages, and cut no-shows.
How estate agents and property managers in Luxembourg City and across the Grand Duchy use CallSphere to capture multilingual viewing and enquiry calls 24/7, GDPR compliant.
A practical guide for Senegalese logistics, freight, legal and consulting SMBs in Dakar and Thiès to capture every enquiry 24/7 with a CallSphere AI voice and chat agent in French, Wolof and English.
© 2026 CallSphere LLC. All rights reserved.
Made within New York
Watch how CallSphere handles real customer calls, schedules appointments, and processes payments — live.
Try Live DemoBook a DemoCalculate Your ROI