Skip to content
AI Engineering
AI Engineering11 min read0 views

Asterisk 22 + AI Agent Integration: ARI, AudioSocket, and ExternalMedia

How Asterisk 22 connects to AI voice agents in 2026 using ARI for call control, AudioSocket for audio streaming, and ExternalMedia for low-latency RTP bridges.

If your business already runs Asterisk and you want an AI receptionist without ripping out the PBX, the 2026 stack is ARI for call control plus AudioSocket or ExternalMedia for the audio path to your model.

Background: Asterisk in the AI era

flowchart TD
  Out[Outbound campaign] --> Twilio[Twilio Voice API]
  Twilio --> STIR[STIR/SHAKEN attestation]
  STIR --> Carrier[Originating carrier]
  Carrier --> Term[Terminating carrier]
  Term --> Recipient[Recipient phone]
  Recipient --> Webhook[/voice webhook/]
  Webhook --> Agent[AI sales agent]
CallSphere reference architecture

Asterisk 22 is the long-term-support release stewarded by Sangoma and the open-source community. It is in production at thousands of FreePBX, hosted PBX, and call-center deployments. For years the AI angle on Asterisk was limited to text-to-speech IVR and rudimentary speech recognition. In 2025 and 2026 that picture changed: serious AI voice agents now run alongside Asterisk by streaming raw audio out to model providers and accepting text-or-audio responses back.

Three integration paths matter in 2026:

  • AGI (Asterisk Gateway Interface) for line-by-line scripting. Mature but synchronous, which makes it awkward for streaming AI.
  • ARI (Asterisk REST Interface) for event-driven control over channels, bridges, and applications. The right call-control plane for AI.
  • AudioSocket and ExternalMedia for moving raw audio frames in and out of Asterisk over TCP or RTP. The right media plane for AI.

How VoIP and SIP work for this use case

Asterisk receives a SIP INVITE on its chan_pjsip endpoint. The dialplan decides what to do with the channel. For an AI agent flow, the dialplan dispatches the call to a Stasis application whose name maps to your ARI app. ARI then takes over: it can answer the channel, attach it to a bridge, and add an ExternalMedia channel that opens an RTP stream toward your AI service. Audio flows out as 16-bit PCM at 8 or 16 kHz. Your service streams audio to OpenAI Realtime, Deepgram, or your own model and pipes responses back into the ExternalMedia channel.

Hear it before you finish reading

Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.

Try Live Demo →

AudioSocket is similar but uses TCP rather than RTP, with a simple framing protocol. It is often easier to debug and works well behind NAT, at the cost of slightly higher latency than RTP.

CallSphere implementation

CallSphere itself is Twilio-first across all six verticals, but Asterisk integration matters because many CallSphere prospects already run an Asterisk PBX and want their AI receptionist to live behind it. The supported pattern is: Asterisk handles internal extensions and existing IVR; calls that should reach the AI are dialed out via SIP to a CallSphere-provided URI; CallSphere terminates on Twilio Elastic SIP Trunking and bridges to OpenAI Realtime.

For customers who insist on a pure on-premises stack, CallSphere ships a reference Stasis app that uses ARI plus ExternalMedia to bridge an Asterisk channel to a CallSphere agent over a private SIP trunk. The platform's 37 agents, 90+ tools, 115+ database tables, HIPAA and SOC 2 controls, and pricing of $149, $499, and $1499 for 1, 3, and 10 numbers all work the same regardless of whether the call originates on Asterisk or directly on Twilio.

Build and integration steps

  1. Run Asterisk 22 with chan_pjsip enabled and a SIP endpoint registered to your carrier.
  2. Add an ARI user in ari.conf with a strong password and bind to localhost or a private network.
  3. Write a dialplan rule that hands matching numbers to a Stasis application: exten => _X.,1,Stasis(ai-agent,$\{EXTEN\}).
  4. Build an ARI client (Python, Node, or Go) that listens for StasisStart events and answers the channel.
  5. Add an ExternalMedia channel for that channel ID, pointing at your AI service's RTP listener with format slin16.
  6. Bridge the original channel and the ExternalMedia channel.
  7. Stream audio to OpenAI Realtime over its SIP endpoint or over a WebSocket; pipe responses back into the bridge.
  8. Implement a graceful shutdown that destroys the bridge and ExternalMedia channel on hangup.

Code or config snippet

; extensions.conf — route inbound calls to the AI agent Stasis app
[from-trunk]
exten => _X.,1,NoOp(Inbound to AI agent)
 same => n,Answer()
 same => n,Stasis(ai-agent,inbound,$\{CALLERID(num)\})
 same => n,Hangup()

; ari.conf — REST control plane
[general]
enabled = yes
pretty = yes

[callsphere]
type = user
read_only = no
password = REPLACE_WITH_STRONG_SECRET

FAQ

Should I use AudioSocket or ExternalMedia? ExternalMedia for lower latency, AudioSocket for easier NAT traversal and a simpler protocol.

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.

Does Asterisk 22 add anything specific for AI workloads? The 22 LTS line tightened PJSIP, hardened ARI, and improved media handling. The bigger shift is the ecosystem: open-source AI agent projects now target Asterisk 18+ as the floor.

Can Asterisk handle 100 concurrent AI calls? Yes, on modest hardware, as long as the audio path is offloaded to ExternalMedia. The bottleneck is usually your AI provider's quota, not Asterisk.

What if my carrier does not speak SIP cleanly? Use a Session Border Controller in front of Asterisk to normalize SIP and handle STIR/SHAKEN.

Is FreePBX fine for this or do I need raw Asterisk? FreePBX works for prototypes; production AI deployments usually want raw Asterisk to keep dialplan logic explicit and version-controlled.

Sources

If you want a managed alternative without running your own PBX, start a 14-day trial, book a demo, or read about healthcare AI deployments.

Share

Try CallSphere AI Voice Agents

See how AI voice agents work for your industry. Live demo available -- no signup required.