Twilio voice AI · Comparison Twilio 语音 AI · 方案对比
Five ways to connect an AI agent to a Twilio phone call 把 AI agent 接入 Twilio 电话的五种方式
Twilio offers several ways to put an AI agent on a phone line. The real difference is not "text or audio". It is who runs speech recognition and text-to-speech, and how your server stays connected during the call. This page compares them side by side. My live demo uses two of them: ConversationRelay (key 3) and Connect Virtual Agent with Dialogflow CX (key 4). Twilio 有好几种把 AI agent 接到电话上的方式。它们的真正区别不在于"传文本还是传音频",而在于谁来做语音识别(ASR)和语音合成(TTS),以及通话过程中你的服务器怎样和 Twilio 保持连接。本页把它们放在一起对比。我的在线演示用到了其中两种:ConversationRelay(按 3)和接入 Dialogflow CX 的 Connect Virtual Agent(按 4)。
Side-by-side comparison 对比总表
| Gather + webhook<Gather input="speech"> | ConversationRelay<Connect><ConversationRelay> | Media Streams<Connect><Stream> | Connect Virtual AgentDialogflow CX one-clickDialogflow CX 一键集成 | Elastic SIP TrunkingSIP trunkSIP 中继 | |
|---|---|---|---|---|---|
| Connection连接方式 | One HTTP request per turn每轮一次 HTTP 请求 | One WebSocket for the whole call一通电话一条 WebSocket | One WebSocket for the whole call一通电话一条 WebSocket | Twilio connects to Google for youTwilio 直接连 Google | SIP signalling + RTP to your SIP serverSIP 信令 + RTP 到你的 SIP 服务器 |
| What your server receives你的服务器收到什么 | Text (form POST), you reply with TwiML文本(表单 POST),回复 TwiML | Text + events (JSON)文本 + 事件(JSON) | Audio frames, μ-law 8 kHz, 20 ms音频帧,μ-law 8kHz,每帧 20ms | Nothing (only optional webhooks from Dialogflow)什么都不收(Dialogflow 可选调 webhook) | Raw SIP call and RTP audio原始 SIP 呼叫和 RTP 音频 |
| Speech recognition (ASR)语音识别(ASR) | Twilio | Twilio | You你自己 | You你自己 | |
| Text-to-speech (TTS)语音合成(TTS) | Twilio <Say>, or your own audio via <Play>Twilio <Say>,或用 <Play> 播你自己的音频 | Twilio | You你自己 | You你自己 | |
| Dialog logic对话逻辑 | You你自己 | You你自己 | You你自己 | Dialogflow CX | You你自己 |
| End-of-speech detection端点检测 | Twilio | Twilio | You你自己 | You你自己 | |
| Barge-in打断 | Limited: speech can stop a nested <Say>有限:说话可打断嵌套的 <Say> | Built in, you get an interrupt event内建,会收到 interrupt 事件 |
You build it, send clear to stop playback自己实现,发 clear 停止播放 |
Handled by GoogleGoogle 处理 | You build it自己实现 |
| Server can speak first without waiting for the caller服务器能否主动说话 不等来电者先开口 |
Not in the turn; only by updating the live call with the REST API对话里不能;只能调 REST API 改写通话 | Yes能 | Yes能 | Not your server不经过你的服务器 | Yes能 |
| Streamed reply回答能否分段发送 | No, one full reply per turn不能,每轮一次完整回答 | Optional: text pieces with last: false可选:用 last: false 分段发文本 |
Yes, audio frames能,发音频帧 | Handled by GoogleGoogle 处理 | Yes, RTP audio能,RTP 音频 |
| Effort开发量 | Lowest: a plain HTTP endpoint最低:一个普通 HTTP 接口 | Low: a small WebSocket server低:一个小的 WebSocket 服务 | High: audio, ASR, TTS, VAD, barge-in高:音频、ASR、TTS、VAD、打断都要做 | Low: setup in two consoles低:在两个控制台里配置 | High: you need your own SIP server高:需要自己的 SIP 服务器 |
| In my demo我的演示 | Not used未使用 | Key 3按 3 | Not used未使用 | Key 4按 4 | Not used未使用 |
When to use each one 各自适合什么场景
Gather + webhook
<Gather input="speech" action="/turn">
The classic IVR pattern. Twilio listens, turns speech into text, and POSTs it to your URL. You answer with TwiML. Good for a quick prototype or a simple turn-by-turn bot.经典 IVR 模式。Twilio 负责听,把语音转成文字,POST 到你的 URL,你回一段 TwiML。适合快速做原型,或者简单的一问一答机器人。
Watch out: waiting for ASR, HTTP and TTS adds up, and a slow reply can time out.注意:ASR、HTTP、TTS 的时间是串行累加的,回答太慢还会超时。
ConversationRelay
wss://your-server/relay
Twilio still does ASR and TTS, but your server keeps one WebSocket open for the whole call. You get prompt, interrupt and dtmf events and can send text at any time. Good for bringing your own LLM agent without building a speech stack.ASR 和 TTS 仍然由 Twilio 做,但你的服务器和 Twilio 之间整通电话保持一条 WebSocket。你会收到 prompt、interrupt、dtmf 等事件,也可以随时主动发文字。适合想接入自己的 LLM agent、又不想自己做语音层的场景。
In my demo: a Python relay behind nginx forwards each turn to my agent, prompts the caller after silence, and ends the session with a transfer or hang-up instruction for Studio.我的演示:nginx 后面的 Python relay 把每轮文字转给我的 agent;来电者长时间不说话时主动提示;需要转人工或挂断时结束会话,把指令交回 Studio。
Media Streams
<Connect><Stream url="wss://..."/>
Raw call audio over a WebSocket. You run ASR, TTS, end-of-speech detection and barge-in yourself. Good for using your own speech models or a speech-to-speech model, with full control over timing.通过 WebSocket 拿到原始通话音频,ASR、TTS、端点检测、打断全部自己做。适合想用自己的语音模型或语音到语音模型、要完全控制交互节奏的场景。
Watch out: the audio is μ-law, so you usually convert it to PCM before ASR and back again before sending.注意:音频是 μ-law 编码,通常要先转成 PCM 再做 ASR,发回去之前再转回 μ-law。
Connect Virtual Agent
Studio widget → Dialogflow CX
Twilio streams the call audio straight to Google. Dialogflow CX does ASR, TTS and the dialog, and can answer from a knowledge base. Good for teams that already build bots in Dialogflow CX.Twilio 把通话音频直接传给 Google,Dialogflow CX 负责 ASR、TTS 和对话,还能用知识库回答问题。适合已经在用 Dialogflow CX 做 bot 的团队。
Watch out: recognition is tuned on the Google side, for example the speech model in the agent's Speech and IVR settings, not in Twilio.注意:识别效果要在 Google 那边调,比如 agent 的 Speech and IVR 设置里的语音模型,改 Twilio 的设置没有用。
Elastic SIP Trunking
PSTN ⇄ Twilio ⇄ your SIP server
Twilio only provides phone numbers and the phone network. Calls arrive at your own SIP server or PBX as normal SIP calls. Good for an existing telephony platform that just needs PSTN access.Twilio 只提供电话号码和电话网络,来电作为普通 SIP 呼叫直接进入你自己的 SIP 服务器或 PBX。适合已经有电话平台、只需要接入公共电话网的场景。
Watch out: you handle NAT, codecs and security yourself.注意:NAT、编解码、安全都要自己处理。
Where Studio fitsStudio 在哪里
Twilio Studio flow
Studio is the visual IVR builder, not a voice AI method. It plays the menu, reads keypresses, and hands the call to ConversationRelay or Connect Virtual Agent. My demo uses Studio for the main menu.Studio 是可视化的 IVR 编辑器,本身不是一种语音 AI 接入方式。它负责播放菜单、读取按键,再把通话交给 ConversationRelay 或 Connect Virtual Agent。我的演示用 Studio 做主菜单。
Key takeaway 核心结论
Gather and ConversationRelay both send text, and Twilio does the speech in both. The difference is the connection: one HTTP request per turn versus one WebSocket for the whole call. That open connection is what lets the server react to interruptions and speak first.Gather 和 ConversationRelay 传的都是文本,语音也都由 Twilio 处理。区别在于连接方式:一个是每轮一次 HTTP 请求,一个是整通电话一条 WebSocket。正是这条持续的连接,让服务器能响应打断、能主动说话。
Only Media Streams and SIP Trunking give you the audio itself. Choose them when you want your own ASR and TTS.只有 Media Streams 和 SIP Trunking 能拿到音频本身。想用自己的 ASR 和 TTS,就选这两种。
See also: Amazon Connect voice AI paths compared →另见:Amazon Connect 语音 AI 路径对比 →