By Sagar Shankaran, Founder of CallSphere
A technical guide to building real-time voice AI agents using WebRTC for audio transport, speech-to-text, LLM reasoning, and text-to-speech in a low-latency pipeline.
Key takeaways
Text-based AI interactions dominate today, but voice is the natural human communication medium. Building voice AI agents that feel conversational — with low latency, natural turn-taking, and contextual understanding — requires integrating multiple real-time systems: audio transport (WebRTC), speech recognition (STT), language model reasoning (LLM), and speech synthesis (TTS).
The technical challenge is latency. A human-to-human conversation has roughly 200-300ms of silence between turns. To feel natural, a voice AI agent must perceive speech, understand it, reason about a response, generate speech, and deliver audio within a similar window.
User's Browser
|
| WebRTC (audio stream)
|
Media Server (audio processing)
|
+-> VAD (Voice Activity Detection) -> STT (Speech-to-Text)
| |
| LLM Reasoning
| |
+<- Audio Stream <-- TTS (Text-to-Speech) <-+
WebRTC provides peer-to-peer real-time communication with built-in handling for NAT traversal, codec negotiation, and network adaptation. For voice AI, it solves critical problems:
sequenceDiagram
autonumber
participant Caller as Caller
participant Agent as CallSphere Agent
participant API as CRM API
participant DB as CRM Database
participant Webhook as Webhook Listener
Caller->>Agent: Inbound call begins
Agent->>Agent: STT plus intent detection
Agent->>API: Lookup contact by phone
API->>DB: Read contact record
DB-->>API: Contact and history
API-->>Agent: Personalized context
Agent->>API: Create call activity
Agent->>API: Update deal stage
API->>Webhook: Outbound webhook fires
Webhook-->>Agent: Confirmed
Agent->>Caller: Spoken confirmation
For production deployments, a media server sits between the user and the AI pipeline:
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
// LiveKit server-side participant (simplified)
import { RoomServiceClient, Room } from 'livekit-server-sdk';
const roomService = new RoomServiceClient(LIVEKIT_URL, API_KEY, API_SECRET);
// Create a room for the voice session
await roomService.createRoom({ name: 'voice-session-123' });
// AI agent joins as a participant
const agentToken = generateToken({ identity: 'ai-agent', roomName: 'voice-session-123' });
const room = await Room.connect(LIVEKIT_URL, agentToken);
// Receive audio from user
room.on('trackSubscribed', async (track) => {
const audioStream = track.getMediaStream();
await processAudioStream(audioStream);
});
VAD determines when the user starts and stops speaking. This is critical for turn-taking:
Natural conversation includes interruptions. When the user starts speaking while the agent is talking:
For low latency, STT must process audio incrementally rather than waiting for the complete utterance:
The LLM processes the transcribed text and generates a response. For voice, two optimizations are critical:
Start TTS on the first generated tokens without waiting for the complete response. This "time to first byte" optimization can reduce perceived latency by 1-3 seconds:
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.
async def stream_llm_to_tts(transcript: str):
buffer = ""
async for chunk in llm.stream(messages=[{"role": "user", "content": transcript}]):
buffer += chunk.text
# Send to TTS at sentence boundaries for natural speech
if buffer.endswith((".", "!", "?", ":")):
audio = await tts.synthesize(buffer)
await send_audio_to_user(audio)
buffer = ""
LLM responses for voice agents should be:
| Provider | Latency | Quality | Streaming |
|---|---|---|---|
| ElevenLabs | 200-400ms | Very high | Yes |
| OpenAI TTS | 300-500ms | High | Yes |
| Cartesia | 100-200ms | High | Yes |
| XTTS v2 (open source) | 300-600ms | Good | Yes |
Production voice agents need consistent voice characteristics across sessions. Most TTS providers support voice cloning from a short audio sample (10-30 seconds), allowing organizations to create branded agent voices.
For a natural-feeling conversation, the total pipeline latency should be under 1 second:
| Component | Target Latency |
|---|---|
| WebRTC transport | 50-100ms |
| VAD + endpointing | 200-300ms |
| STT transcription | 200-300ms |
| LLM time-to-first-token | 200-400ms |
| TTS time-to-first-audio | 150-300ms |
| Total | 800-1400ms |
Achieving the lower end of this range requires careful optimization at every stage, geographic co-location of services, and streaming throughout the pipeline rather than sequential processing.
Sources: LiveKit Documentation | Deepgram Streaming API | Silero VAD

Written by
Sagar Shankaran· Founder, CallSphere
LinkedInSagar 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 founder's guide to page chat: web page chat box options, best live chat for small business, and how CallSphere ships an embed in 5 minutes.
A founder's guide to texto a voz (text-to-speech in Spanish): LATAM vs Castilian voices, free options, and how CallSphere ships Spanish agents.
A founder's guide to building a chatbot for answering questions on your website: RAG, voice, and how CallSphere ships one in 3-5 days.
A founder's guide to the Siri voice generator landscape: how AI voice cloning works, what is legal, and how CallSphere uses 57+ voices in production.
A founder's guide to the female voice generator landscape: AI female voices, Japanese voices, robot voices, and how CallSphere ships 57+ voices live.
An AI voice bot in 2026 handles both inbound and outbound calls at human-level quality. Here is the production guide, the API options, and what to pick.
© 2026 CallSphere Inc. All rights reserved.
Made within San Francisco
Watch how CallSphere handles real customer calls, schedules appointments, and processes payments — live.
Try Live DemoBook a DemoCalculate Your ROI