WebSocket transport implementation for FastAPI web applications with telephony integration
FastAPIWebsocketTransport
provides WebSocket support for FastAPI web applications, enabling real-time audio communication over WebSocket connections. It’s primarily designed for telephony integrations with providers like Twilio, Telnyx, and Plivo, supporting bidirectional audio streams with configurable serializers and voice activity detection.
FastAPIWebsocketTransport
, install the required dependencies:
InputAudioRawFrame
- Raw audio data from WebSocket clientFrame
- Other frame types based on configured serializerOutputAudioRawFrame
- Audio data to WebSocket client (with optional WAV headers)TransportMessageFrame
- Application messages to clientTransportMessageUrgentFrame
- Urgent messages to clientFastAPIWebsocketTransport
for telephony is with Pipecat’s development runner:
-x
flag specifies your public domain (like ngrok) that telephony
providers can reach for webhooks.parse_telephony_websocket()
utility to auto-detect and extract call data.@transport.event_handler()
decorator:
on_client_connected
- Client connects to WebSocket endpointon_client_disconnected
- Client disconnects from WebSocket endpointon_session_timeout
- Session timeout occurs (if configured)TwilioFrameSerializer
for Media Streams integrationTelnyxFrameSerializer
for WebSocket streamingPlivoFrameSerializer
for WebSocket streamingExotelFrameSerializer
for WebSocket integration