Overview

WebSocket transports provide both client and server WebSocket implementations for real-time bidirectional communication. These transports support audio streaming, frame serialization, and connection management, making them ideal for prototyping and lightweight client-server applications where WebRTC might be overkill.
WebSocket transports are best suited for prototyping and controlled network environments.For production client-server applications, we recommend WebRTC-based transports for more robust network handling, NAT traversal, and media optimization.

Installation

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

Prerequisites

WebSocket Application Setup

Before using WebSocket transports, you need:
  1. Server Implementation: Set up WebSocket server using your preferred framework
  2. Client Implementation: Configure WebSocket client for browser or application use
  3. Audio Configuration: Set up audio streaming parameters and formats
  4. Connection Management: Handle WebSocket lifecycle and error recovery

Configuration Options

  • Transport Type: Choose between client or server WebSocket transport
  • Audio Parameters: Configure sample rates, channels, and audio formats
  • Frame Serialization: Set up custom frame serializers if needed
  • Connection Handling: Configure reconnection and error handling strategies

Key Features

  • Bidirectional Communication: Real-time audio and data streaming
  • Simple Protocol: Lightweight WebSocket-based communication
  • Flexible Serialization: Support for custom frame formats and audio codecs
  • Cross-Platform: Works with any WebSocket-compatible client or server

Usage

WebSocket transports provide simple client-server communication for audio streaming and real-time interaction. They’re ideal for prototyping and controlled network environments. See the complete examples for full implementations including:
  • WebSocket server setup and configuration
  • Client-side WebSocket integration
  • Audio streaming and frame handling
  • Connection management and error recovery