Overview

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 is best suited for telephony applications and server-side WebSocket integrations.For general client/server applications, we recommend using WebRTC-based transports for more robust network and media handling.

Installation

To use FastAPIWebsocketTransport, install the required dependencies:
pip install "pipecat-ai[websocket]"

Prerequisites

FastAPI Application Setup

Before using FastAPIWebsocketTransport, you need:
  1. FastAPI Application: Set up a FastAPI web application
  2. WebSocket Endpoint: Configure WebSocket routes for real-time communication
  3. Telephony Provider: Set up integration with Twilio, Telnyx, or Plivo
  4. Frame Serializers: Configure appropriate serializers for your telephony provider

Configuration Options

  • Serializer Selection: Choose frame serializer based on telephony provider
  • Audio Parameters: Configure sample rates and audio formats
  • VAD Integration: Set up voice activity detection for optimal performance
  • Connection Management: Handle WebSocket lifecycle and reconnections

Key Features

  • Telephony Integration: Optimized for Twilio, Telnyx, and Plivo WebSocket streams
  • Frame Serialization: Built-in support for telephony provider audio formats
  • FastAPI Integration: Seamless WebSocket handling within FastAPI applications
  • Bidirectional Audio: Real-time audio streaming in both directions

Usage

FastAPIWebsocketTransport integrates with your FastAPI application to handle telephony WebSocket connections. It works with telephony frame serializers to process audio streams from phone calls. See the complete example for a full implementation including:
  • FastAPI WebSocket endpoint configuration
  • Telephony provider integration setup
  • Frame serializer configuration
  • Audio processing pipeline integration