### The Voice AI Latency Equation
In natural human speech, the gap between conversational turns is approximately 200 to 450 milliseconds. Traditional chained API implementations (recording audio, saving to an MP3, calling an STT API, waiting for full text completion from an LLM, and generating speech via standard TTS) produce 2,500ms to 4,000ms of lag. Callers immediately talk over the bot or hang up in frustration.
Achieving carrier-grade conversational flow requires an end-to-end streaming pipeline: 1. Audio Streaming (WebSockets / SIP): Twilio passes raw audio packets to Vapi via TLS SIP Trunking (<40ms). 2. Speech-to-Text (STT): Deepgram Nova-2 transcribes speech with word-level streaming timestamps (<180ms). 3. LLM Inference: Fast low-latency models (e.g. Claude 3.5 Sonnet or GPT-4o-mini) stream tokens with early first-chunk emission (<220ms). 4. Text-to-Speech (TTS): ElevenLabs Turbo v2 or Cartesia synthesizes audio chunks the instant the first clause arrives (<120ms).
Total end-to-end response latency: 540ms to 590ms, delivering completely natural, interruptible conversations.
Twilio SIP Trunking & PSTN Provisioning
Rather than running client calls through webRTC in a browser, production B2B voice agents must terminate directly onto phone networks (PSTN). In Twilio, we provision local DID numbers and configure an Elastic SIP Trunk pointing to Vapi's signaling gateway:
<!-- Twilio Voice Webhook TwiML Response -->
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial>
<Sip>sip:vapi-agent@sip.vapi.ai;transport=tls</Sip>
</Dial>
</Response>This configuration delivers crystal-clear audio codecs (G.711 / Opus), automated caller ID transmission, and sub-500ms call handoff to human managers whenever sentiment analysis flags an escalation.
Vapi Assistant Architecture & System Prompts
A voice assistant prompt differs drastically from a standard chat prompt. It must enforce short sentences, phonetic spelling for names and numbers, and zero markdown formatting (since asterisks or emojis cause speech synthesizers to hallucinate):
{
"transcriber": {
"provider": "deepgram",
"model": "nova-2",
"language": "en"
},
"model": {
"provider": "anthropic",
"model": "claude-3-5-sonnet-20241022",
"temperature": 0.3,
"systemPrompt": "You are Sarah, an expert intake coordinator for Sheharyar Siraj Architecture. Speak in short, conversational sentences of 12 words or less. Never use bullet points, lists, or markdown symbols. Ask one clear qualifying question at a time. If the caller provides their budget or timeline, invoke the checkAvailability tool immediately."
},
"voice": {
"provider": "elevenlabs",
"voiceId": "21m00Tcm4TlvDq8ikWAM",
"model": "eleven_turbo_v2"
}
}Notice the instruction limiting spoken output to twelve words or less. Human phone dialogue thrives on rapid back-and-forth validation rather than lengthy monologues.
Real-Time Tool Calling & Calendar Booking
The true commercial power of voice agents lies in real-time execution. When a caller asks, "Can we book a scoping call for Thursday afternoon?", the voice agent executes an authenticated webhook function call directly to your n8n or Node.js server:
// Express.js Webhook Tool Handler for Vapi Function Calls
app.post('/api/voice/book-slot', async (req, res) => {
const { parameters } = req.body.message.toolCalls[0].function;try { // 1. Query Google Calendar / Cal.com API for conflict detection const isAvailable = await checkCalendarSlot(preferredDate, preferredTime);
if (!isAvailable) { return res.json({ results: [{ toolCallId: req.body.message.toolCalls[0].id, result: "That slot is booked, but 3:30 PM is available. Would that work?" }] }); }
// 2. Schedule meeting and trigger SMS confirmation via Twilio await createCalendarEvent({ callerPhone, preferredDate, preferredTime }); await sendSmsConfirmation(callerPhone, preferredDate, preferredTime);
return res.json({
results: [{
toolCallId: req.body.message.toolCalls[0].id,
result: "I have successfully booked that slot for you and sent an SMS confirmation."
}]
});
} catch (err) {
return res.json({
results: [{
toolCallId: req.body.message.toolCalls[0].id,
result: "I recorded your request and our team will confirm via text message within 15 minutes."
}]
});
}
});
`
The webhook executes and returns its response within 280ms, allowing the assistant to speak the confirmation before the caller even finishes processing their request.
Audio Caching Resilience and Dialect Localization
For international clients in the GCC (Saudi Arabia, UAE), speech agents must navigate regional dialects, bilingual Arabic/English greetings, and background noise from busy offices. By pre-caching standard audio acknowledgments ("Understood, let me check that for you right now"), the agent plays instant verbal affirmations while asynchronous background functions fetch external CRM data.
The result is a telephone system that operates 24/7, never places callers on hold, qualifies intent with precision, and feeds pre-qualified bookings directly into your sales pipeline.
Which STT API delivers low-latency, sub-500ms transcription?
This pipeline uses Deepgram Nova-2 with WebSocket streaming. As the latency breakdown above shows, it transcribes speech with word-level streaming timestamps in under 180ms, which keeps transcription well inside a sub-500ms budget and leaves room for LLM inference (under 220ms) and speech synthesis (under 120ms) inside the 540ms to 590ms end-to-end response time.
Two ways to run the STT step, compared:
1. Deepgram Nova-2 with WebSocket streaming (used here): audio is transcribed as it arrives, with zero-buffer streaming between speech-to-text, LLM inference and text-to-speech, so the assistant can start reasoning on partial transcripts instead of waiting for a finished file. 2. Traditional chained flow: recording the audio, saving it to an MP3 file, calling an STT API and waiting for the full text back before doing anything else. That is the pattern the latency equation above rejects, because every saved and waited step adds delay the caller can hear.
Streaming transcription is what makes the sub-600ms target possible at all, which is why the STT choice matters more than any single model choice downstream.
Can AI Voice Agents Scale Call Volume Using SIP?
Yes, and SIP is the mechanism that makes it possible. In the architecture above, inbound calls terminate on Twilio Elastic SIP Trunking rather than in a browser, so each call is a carrier-grade phone session that hands off to the voice pipeline over a managed signaling gateway. Because the telephony layer is separate from the assistant layer, call capacity scales by adding trunk capacity and gateway concurrency, not by changing the assistant itself. The same SIP handoff that delivers the call also supports transfer to a human manager when sentiment analysis flags an escalation, which keeps high-volume automation safe to deploy.
Vapi vs Twilio: What Is the Difference?
Vapi and Twilio solve different layers of the same system, so the comparison is really about which layer you are buying. Twilio provides the telephony transport: phone numbers, Elastic SIP Trunking, and the PSTN connection that carries the call. Vapi provides the voice-agent orchestration: the assistant configuration, the streaming pipeline that connects speech-to-text, the language model, and text-to-speech, plus the webhook tool calling that lets the agent book appointments and query live systems. In the build described in this guide they are used together, with Twilio terminating the call and Vapi running the conversation, which is why choosing between them is usually the wrong question.
