Twilio Frame Serializer
Serializer for Twilio Media Streams WebSocket protocol
Overview
TwilioFrameSerializer
enables integration with Twilio’s Media Streams WebSocket protocol, allowing your Pipecat application to handle phone calls via Twilio’s voice services.
Features
- Bidirectional audio conversion between Pipecat and Twilio
- DTMF (touch-tone) event handling
- Automatic call termination via Twilio’s REST API
- μ-law audio encoding/decoding
Installation
The TwilioFrameSerializer
does not require any additional dependencies beyond the core Pipecat library.
Configuration
Constructor Parameters
The Twilio Media Stream SID
The associated Twilio Call SID (required for auto hang-up)
Twilio account SID (required for auto hang-up)
Twilio auth token (required for auto hang-up)
Configuration parameters
InputParams Configuration
Sample rate used by Twilio (typically 8kHz)
Optional override for pipeline input sample rate
Whether to automatically terminate call on EndFrame
Basic Usage
Hang-up Functionality
When auto_hang_up
is enabled, the serializer will automatically hang up the Twilio call when an EndFrame
or CancelFrame
is processed, using Twilio’s REST API:
Server Code Example
Here’s a complete example of handling a Twilio WebSocket connection:
See the Twilio Chatbot example for a complete implementation.