Building a calling AI platform requires a bridge between traditional public switched telephone networks (PSTN) and web application servers. This is accomplished using enterprise-grade VoIP APIs that stream low-latency audio bidirectionally between the phone network and your AI logic. This guide breaks down every layer of that bridge — from the initial webhook to the audio codec details that determine whether a call sounds natural or garbled.
The Two Ways a Call Reaches Your System
Before audio ever streams anywhere, a call has to physically reach your infrastructure. There are two paths:
- Outbound: Your platform initiates the call via a telephony provider's API, specifying the destination number, the caller ID (CLI) to dial from, and the webhook URL that will control the call once it connects.
- Inbound: A customer dials a number registered to your account. The telephony carrier routes the call to your provider's infrastructure, which then triggers a webhook to your server exactly the same way an outbound call does once it's answered.
In India specifically, the routing path matters a lot for call quality and cost. Direct connections to local carriers (Jio, Airtel, Vi) keep the entire call path within the country, whereas platforms built primarily for the US or EU market often route Indian calls through global SIP trunks — adding hops, and therefore latency, before the call even reaches the AI logic.
Telephony Webhooks
When a call is initiated or received, the telephony provider triggers an HTTP webhook requesting instructions on how to handle the call. The server responds with standard XML or JSON commands that control call behavior — directing audio routing, recording, and streaming. A typical webhook response tells the provider to either play a static message, transfer the call, or — for conversational AI — open a live media stream to your AI logic.
Streaming Bidirectional Audio via WebSockets
To support real-time conversational AI, static XML commands are not enough. You must establish a bidirectional WebSocket connection, and the flow looks like this on every turn of the conversation:
- The telephony provider opens a raw WebSocket stream to your server, sending audio packets (usually G.711 PCMU or PCMA format, 8kHz sample rate — the same codec telephone networks have used for decades).
- Your server routes these audio packets into a Speech-to-Text (STT) transcoder, which converts the raw audio into text in near real time, often producing partial transcripts before the caller has even finished speaking.
- The text is fed into the generative AI engine (an LLM) along with conversation history and system instructions, to receive a completion stream — the model's response, generated token by token.
- The completion stream is synthesized into voice packets by a Text-to-Speech (TTS) engine and pushed back down the WebSocket to be played on the phone, ideally starting playback before the full sentence has even finished generating.
Every one of these four steps adds milliseconds of latency, and the difference between a platform that feels human and one that feels robotic almost always comes down to how well this pipeline is engineered, not which LLM is used underneath.
Audio Codecs and Sample Rates: Why They Matter
PSTN audio has historically been narrowband — 8kHz, G.711-encoded — because that's what phone networks were built to carry. This is a real constraint: it caps the audio fidelity below what modern TTS models are capable of producing. Platforms need to correctly downsample high-fidelity TTS output (often generated at 16kHz or 24kHz) to 8kHz PCMU/PCMA without introducing artifacts, and correctly upsample or process incoming 8kHz caller audio for STT models that may expect a different input format. Getting this resampling step wrong is a common, underappreciated source of transcription errors and unnatural-sounding bot speech — a technical detail that is invisible in a demo video but obvious on a real live call.
Optimizing for Ultra-Low Latency
A response delay of more than 1 second starts to kill conversational flow — the caller either starts talking again, assuming the bot didn't hear them, or the pause feels distinctly non-human. To keep total response latency under 600 milliseconds, engineering teams need to get several things right simultaneously:
- Use WebSockets instead of HTTP polling for the entire audio pipeline — polling-based architectures simply cannot hit sub-second latency at any reasonable interval.
- Stream speech synthesis output dynamically rather than waiting for the entire response sentence to be generated before starting audio playback — the first audio chunk should start playing while the rest of the sentence is still being synthesized.
- Use streaming STT with partial results so the system can start reasoning about likely intent before the caller has finished their sentence, rather than waiting for a full stop.
- Co-locate infrastructure geographically — running STT, the LLM, and TTS on servers physically close to the telephony carrier's point of presence, rather than round-tripping audio to a data center on another continent.
- Use lightweight, latency-tuned models for both STT and TTS rather than the highest-quality-but-slowest option available — there's a real tradeoff curve here, and the fastest models that are "good enough" usually beat the best models that are too slow.
- Implement interruption handling (barge-in) so the system can stop talking immediately if the caller starts speaking, rather than finishing a scripted sentence over the top of them — this alone makes a huge difference in perceived naturalness.
Why This Architecture Is Harder in India Specifically
Two India-specific factors make this pipeline meaningfully harder to get right than in an English-only, US-based deployment. First, Hinglish and code-switched speech (a caller moving between Hindi and English mid-sentence) requires STT models specifically trained on that pattern — generic English STT models frequently mis-transcribe or drop words entirely. Second, regional accents vary enormously across states, and a model tuned only on Delhi or Mumbai-accented speech will underperform badly on a caller from Chennai or Kolkata. This is why multilingual, India-tuned models aren't a nice-to-have feature — they're a hard technical requirement for the pipeline to actually work at the latency and accuracy levels enterprise campaigns need.
Reference Architecture Comparison
| Architecture Choice | India-optimized (Vistara AI) | Generic global platform |
|---|---|---|
| Carrier routing | Direct Jio/Airtel/Vi connections | Global SIP trunk, extra hops |
| STT training data | Hinglish + regional accents | English-first, accent gaps |
| Compute location | Regional nodes near carrier POPs | Often overseas data centers |
| Typical end-to-end latency | Sub-600ms | 900ms – 1.5s for Indian calls |
See how this plays out against specific providers in our Vistara AI vs. Vapi and Vistara AI vs. Retell technical comparisons.
Handling Call Recording, Compliance Logging, and Webhooks
Beyond the real-time audio pipeline, a production AI calling platform also has to solve a second, less glamorous engineering problem: reliably capturing everything that happened on the call for compliance and CRM purposes. This typically means recording the raw audio stream to durable storage in parallel with the live processing pipeline, persisting the full turn-by-turn transcript with timestamps, and generating a structured summary (call outcome, key entities mentioned, sentiment) once the call ends. That structured payload is then pushed via webhook to the customer's CRM or spreadsheet — see how this integration layer works in practice. None of this can add meaningful latency to the live conversation, so it has to run asynchronously, off the critical audio path, while still being reliable enough to serve as a compliance record if a regulator or customer ever disputes a call.
Conclusion
None of this pipeline is visible to the person on the other end of the call — they just experience it as either a natural conversation or an awkward one. But every millisecond of that experience is the product of deliberate architecture decisions: codec handling, streaming versus batch processing at every stage, geographic compute placement, and language-specific model tuning. For a market like India, with its linguistic diversity and code-switching speech patterns, getting this right requires infrastructure built for the market, not adapted from one. That's the core engineering bet behind Vistara AI's platform.