OpenAI Realtime-AgentStream Integration
12 min
connect an exotel phone call to openai realtime https //platform openai com/docs/guides/realtime (speech to speech) exotel stays at 8 khz pcm the bridge talks to openai as pcm 16 bit at 24 khz and resamples both directions locally sample code integrations/openai realtime https //github com/exotel/agent stream/tree/main/integrations/openai realtime in the agent stream https //github com/exotel/agent stream repo if you have not set up connect yet, start with connect voice ai with agentstream docid xb3tdmzuz6jbcqdsboqd what you get true speech to speech (no separate stt → llm → tts pipeline in your code) instant pre cached greeting on call start (optional, on by default) paced agentstream media frames suitable for connect voice ai openai does not accept linear pcm at 8 khz do not set audio/pcm with rate 8000 use 24 khz pcm on the openai wire (this sample) or g 711 μ law at 8 khz if you deliberately implement that path before you start item notes openai api key with realtime access exotel account sid, api key, api token, exophone python 3 10+ on 3 13+, audioop lts is pulled in via requirements public wss cloudflared or ngrok for the first test install git clone https //github com/exotel/agent stream git cd agent stream cp shared/env exotel example shared/ env exotel \# fill exotel values cd integrations/openai realtime python3 m venv venv && source venv/bin/activate pip install r requirements txt cp env example env edit env (never commit this file) openai api key=sk openai model=gpt realtime openai voice=coral sample rate=8000 default sample rate=8000 server port=5000 company name=your company sales bot name=sara send test tone=false instant greeting=true run the bot and open a tunnel terminal a cd integrations/openai realtime source venv/bin/activate python main py on startup you should see a greeting cache message, then server listening on 0 0 0 0 5000 websocket path is / (root) terminal b cloudflared tunnel url http //127 0 0 1 5000 place a connect call from the repo root set a && source shared/ env exotel && set +a python shared/place connect call py \\ \ to +91xxxxxxxxxx \\ \ stream url "wss\ //your cloudflare host/?sample rate=8000" streamurl wss\ //host/?sample rate=8000 port 5000 the ?sample rate=8000 query parameter is required for pstn answer the phone you should hear the greeting quickly, then be able to talk turn by turn verify logs instant greeting (or realtime greeting fallback), audio format audio/pcm → audio/pcm , first audio ms=… pitch sounds like a normal phone call (not stretched or deep) after you speak, the model replies; barge in cancels playback when configured go live checklist bot on a stable host with valid tls for wss\ // openai api key only in secrets — not in git send test tone=false in production streamurl always includes ?sample rate=8000 for 8 khz telephony voice and instructions tuned for short phone turns process supervision and disconnect handling this tree is a working sample for pilots large concurrent load needs multiple processes, a wss edge, and capacity testing — it is not a multi tenant autoscaler by itself troubleshoot symptom what to check deep / slow voice old μ law/pcm mismatch — current sample uses pcm 24 khz ↔ 8 khz; pull latest core/bot py beep before greeting send test tone=true — set to false no audio tunnel url, ?sample rate=8000 , openai key / realtime access long delay to first speech instant greeting cache failed (check boot logs); otherwise realtime ttfa is often 1–3s after connect without cache related repo readme integrations/openai realtime/readme md connect voice ai api https //docs exotel com/exotel agentstream/connect voice ai api elevenlabs's elevenagents agentstream integration docid\ xwx948gytzp66hccgkklq sarvam ai agentstream integration docid\ os9lcvtosfqtjzly qmvu
