Voice AI Day is baaaaack! 🎙️ 11 cities, 10 Dec
    Video5:06by Voice AI Space

    SIP Explained for AI Voice Agents

    How a phone call reaches an AI voice agent: SIP, SIP trunks, the call setup script, phone audio limits and DTMF keypad tones.

    Part of Voice AI Explained. See every episode, in learning order, in How Voice AI Works: A Complete Guide.

    Summary

    Connecting Phone Calls to AI Agents

    When users interact with a voice AI agent via a phone call rather than a browser, the call must transition from the phone network to an AI running on a server. This process relies on SIP (Session Initiation Protocol), a plain-text language used to set up, manage, and terminate calls.

    How SIP and SIP Trunks Work

    To receive calls, an AI agent requires a phone number rented from a carrier or provider. Businesses typically connect to the phone network using a SIP trunk, which acts as a virtual bundle of phone lines over the internet to handle multiple concurrent calls. A standard SIP call setup follows a specific script:

    • The caller sends an invite.
    • The receiving side responds with "ringing" and then "OK."
    • The caller confirms the connection.
    • The invite and reply exchange details on supported audio formats and destination addresses.
    • The call is terminated with a "bye" message from either side.

    While SIP manages the call state, the actual voice audio travels separately in small packets.

    Phone Audio Quality and DTMF

    Phone audio is significantly limited compared to studio audio. A standard phone call restricts frequencies to between 300 and 3,400 Hz and samples audio only 8,000 times per second. This low resolution makes certain sounds, like "S" and "F," easy to confuse, meaning speech-to-text engines have less data to work with. Additionally, callers can interact using keypad presses, which transmit dual-tone multi-frequency (DTMF) signals to navigate menus or request a human operator.

    Paths to the AI Agent

    There are two primary pathways for a phone call to reach an AI server:

    • Path 1 (WebSocket Stream): A phone provider answers the call and streams the audio bidirectionally to the AI server over a WebSocket.
    • Path 2 (Direct SIP): The call travels over a SIP trunk directly to a system that natively speaks SIP. Because SIP and WebRTC are closely related, a bridge can translate between them to place the caller into a virtual room with the agent, or the call can connect directly to an API without a bridge.

    Best Practices for Going Live

    Before deploying a phone-based voice agent, developers should consider several practical steps:

    • Test the agent using real phone calls rather than high-quality laptop microphones.
    • Select a speech-to-text model optimized for thin phone audio, specifically testing its accuracy with names and numbers.
    • Ensure the system can handle keypad (DTMF) inputs.
    • Always provide an option to transfer the caller to a human.
    • Review local consent and robocall regulations if the agent is making outbound calls.

    Full transcript

    Not everyone will talk to your voice agent in a browser. Many will just call a phone number. That call starts on the phone network and has to find its way to an AI running on a server. On the internet side, the language that usually sets up that call is called SIP. Today, how a phone call reaches an AI agent in plain words.

    First, the phone network. It connects billions of phones, run by phone companies called carriers. Behind the scenes, much of it now runs on internet technology. From the outside, nothing changed. You dial a number and it rings. To take calls, your agent needs a phone number rented from a carrier or from a provider that works with carriers.

    Then the call has to be set up. That's the job of SIP, the Session Initiation Protocol. SIP messages are plain text, a bit like the web, and a call follows a simple script. The caller's side sends an invite, "can we talk?" The other side replies, "ringing". Then, "OK, let's talk". The caller confirms, and at the end, one side says, "bye". Like the contact cards from last episode, the invite and the reply describe which audio formats each side understands and where to send the audio. SIP runs the call. It sets it up, changes it, and ends it. The voice itself travels separately in small pieces, just like in WebRTC.

    So how does a business plug into the phone network today? Often not with copper wires. It uses a SIP trunk, a connection, usually over the internet, to a carrier or provider that can carry many calls at once. Think of it as a bundle of phone lines, but virtual. Calls to your number come in through the trunk. Calls your agent makes go out through it.

    Now the sound. Phone audio is thin. A classic call keeps only the sounds between about 300 and 3,400 Hz, and measures the voice 8,000 times per second. Studio audio is often measured 48,000 times per second. So on the phone, sounds like "s" and "f" are easy to confuse. For your agent, speech-to-text has less to work with. Many providers offer models or settings made for phone audio. Some calls carry HD voice with about twice the range, but you can't count on it; many agents still get 8,000 samples a second.

    Callers can also press keys. Each key sends a pair of tones or a small message saying which key was pressed. That's how "press 1 for sales" works. It's called DTMF. Voice agents need it too, for menus, for typing a number, or when someone presses zero, hoping for a human.

    So how does the call finally reach the AI? There are two common paths. Path 1, the phone provider answers the call and streams the audio to your server over a WebSocket. Several providers offer this. Twilio's version, for example, sends the caller's voice at 8,000 samples per second and lets your agent send its voice back. Wait, WebSockets? Last episode, they waited for lost pieces. Between two servers on solid networks, that's rarely a problem.

    Path 2, the call comes in over a SIP trunk straight to a system that speaks SIP. SIP and WebRTC are cousins. Both swap contact cards, and both send the voice in small pieces. So a bridge can translate between them. LiveKit, for example, turns each caller into a participant in a room where the agent joins like a person. And OpenAI's Realtime API can take calls straight from your SIP trunk with no bridge. Many voice agent platforms handle all of this for you. You connect a number and they do the rest.

    A few honest tips before you connect a real number: Test with real phone calls, not only your laptop microphone. Pick speech-to-text that handles phone audio well and test it on names and numbers. Handle keypad presses. Always give callers a way to reach a human. SIP or your phone provider can transfer the call to a person or another number. And if your agent makes calls, check the local rules on consent first. In the US, AI voices fall under robocall rules.

    To recap: You rent a number. Your provider or your own SIP trunk brings the calls in. SIP runs the call, and the voice travels separately. The audio is thin: 8,000 samples a second. And the call reaches your agent as a stream over a WebSocket or over SIP all the way.

    Next time, the latency budget and where the time goes in one turn of a conversation. If we got something wrong, tell us. Corrections get pinned. And you'll find voice AI products sorted by role in the Voice AI Space library.