TwilioPaul Kamp, Safdar JaffariTutorial
Build an AI Voice Assistant with Twilio Voice and Media Streams, Rime's Prism, and Node.js
Summary
The tutorial shows how to connect Rime’s Prism speech-to-speech model to Twilio’s voice infrastructure using Twilio Media Streams, Node.js, and Rime’s Node SDK. It covers setting up a Node.js project with Fastify, installing dependencies, and writing audio conversion code to handle the format mismatch between Twilio’s 8 kHz G.711 μ-law and Prism’s 16/24 kHz PCM16. The server manages WebSocket connections, converts incoming μ-law audio to PCM16 for Prism, and converts Prism’s 24 kHz output back to 8 kHz μ-law for Twilio using a low-pass filter and decimation. Additional features include interruption handling, tool calling, persisting customer details with Twilio’s Conversation Memory, and analyzing transcripts with Conversation Intelligence. The tutorial concludes with troubleshooting tips and next steps for further exploration.
Context
Building an AI voice assistant that can handle phone calls using Twilio’s voice infrastructure and Rime’s Prism speech-to-speech model.
Approach / What changed
Set up a Node.js server with Fastify and WebSocket support, connect Twilio Media Streams to Rime Prism via the Rime Node SDK, implement audio conversion between μ-law and PCM16, and add features like interruption handling, tool calling, Conversation Memory, and Conversation Intelligence.
Takeaways
Twilio Media Streams uses 8 kHz G.711 μ-law audio, while Rime Prism uses 16 kHz PCM16 input and 24 kHz PCM16 output, requiring audio conversion.
The audio conversion from 24 kHz PCM16 to 8 kHz μ-law uses a low-pass filter with a 3.6 kHz cutoff and decimation by keeping every third sample.
The tutorial demonstrates persisting customer details across calls using Twilio’s Conversation Memory and analyzing transcripts with Conversation Intelligence.
FAQ
What audio format does Twilio Media Streams use?
Twilio Media Streams sends and receives 8 kHz G.711 μ-law audio. This differs from Rime Prism which uses 16 kHz PCM16 input and 24 kHz PCM16 output, requiring conversion.
How do you convert Prism's 24 kHz output to Twilio's 8 kHz μ-law?
The conversion uses a low-pass filter with a 3.6 kHz cutoff to remove frequencies above 4 kHz, then keeps every third sample to decimate from 24 kHz to 8 kHz, and encodes the result as μ-law.
What features does the tutorial add beyond basic voice conversation?
The tutorial adds interruption handling, tool calling, persisting customer details with Twilio's Conversation Memory, and analyzing transcripts with Conversation Intelligence.
Source and freshness
- Source
- twilio.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.