Engineering Sub-450ms Voice AI Agents with Vapi, Twilio SIP, and WebRTC
A technical breakdown of acoustic echo cancellation, full-duplex audio packet routing, and dynamic interruption handling for production phone agents.
The Latency Bottleneck in Telephony AI
In conversational AI, latency is the difference between human-like cadence and an awkward walkie-talkie exchange. Human conversational turn-taking happens within 200ms to 450ms. If your voice pipeline exceeds 600ms, users perceive hesitation, speak over the bot, and trigger conversational collisions.
Standard phone architectures route audio through HTTP webhooks: user speech is captured via PSTN, transcribed via batch STT, fed to an LLM completion endpoint, synthesized via TTS, and played back. This naive sequence consistently clocks in at 1,400ms to 2,200ms.
The Sub-450ms Full-Duplex Architecture
To break the 450ms barrier, we eliminate HTTP request-response loops and migrate the entire transport layer to persistent SIP trunks over WebRTC with streaming PCM audio buffers:
[ PSTN / Phone Call ]
│ (G.711 / Opus)
▼
[ Twilio Elastic SIP Trunk ]
│ (SIP Signalling + TLS Media)
▼
[ Vapi Audio Gateway ] ◄── (Direct WebSocket Stream, 16kHz Mono 16-bit PCM)
├── Deepgram Nova-2 (Streaming STT: ~110ms)
├── Groq / Cerebras Llama-3 70B (First-Token TTFT: ~120ms)
└── Cartesia Sonic / ElevenLabs Turbo v2.5 (Streaming Audio Chunk: ~140ms)
│
▼ (Sub-450ms Total Turnaround)
[ Inbound Audio Track to Caller ]
1. Acoustic Echo Cancellation & Barge-In Detection
The most critical challenge in voice AI is barge-in: when a caller interrupts while the AI is speaking. Standard thresholding triggers false interruptions from background static, office murmurs, or acoustic echo leaking from the speaker into the microphone.
We deploy a two-tier interruption filter:
- Hardware-accelerated AEC (Acoustic Echo Cancellation): Filters out the outgoing synthetic audio stream before it enters the transcription pipeline.
- Semantic Voice Activity Detection (Silero VAD + Spectral Energy): We enforce a 90ms energy gate combined with phonetic boundary checks so transient coughs or background door clicks do not kill the bot's speech output.
"If the caller says 'Right', 'Uh-huh', or 'Got it', the system classifies it as backchannel acknowledgement and maintains output continuity. If they articulate a conflicting semantic token ('Wait', 'Stop', 'Actually'), the audio buffer is flushed in under 35ms."
2. Streaming Token Buffer Execution
You cannot wait for a complete sentence before initiating Text-to-Speech. Our voice bridge parses the incoming LLM token stream with punctuation-aware lookahead:
// Dynamic Punctuation Chunker for Streaming TTS
function streamAudioChunks(tokenStream: AsyncIterable<string>) {
let sentenceBuffer = "";
const delimiterRegex = /([.,!?;:
]+)/;
for await (const token of tokenStream) {
sentenceBuffer += token;
if (delimiterRegex.test(sentenceBuffer) && sentenceBuffer.trim().length > 18) {
const [completeSentence, ...rest] = sentenceBuffer.split(delimiterRegex);
dispatchToTTSStream(completeSentence);
sentenceBuffer = rest.join("");
}
}
}
3. Failover Protocol: Warm Human Transfer
Deterministic voice systems must never abandon the caller when an unhandled edge case occurs. If model confidence drops below 92% or the user expresses frustration twice in succession, our system executes an automated SIP REFER transfer directly into the sales or support desk, injecting a live conversational transcript into the CRM before the agent answers.
Looking to automate your sales or operations stack?
Book a 30-minute architecture discovery call with one of our systems engineers.