WebSocket Server
WebSocket server transport implementation for real-time audio communication
Overview
WebsocketServerTransport
provides a WebSocket server implementation for real-time audio communication. It supports bidirectional audio streams and voice activity detection (VAD).
WebsocketServerTransport is best suited for server-side applications and prototyping client/server apps.
For client/server production applications, we strongly recommend using a WebRTC-based transport for robust network and media handling.
Installation
To use WebsocketServerTransport
, install the required dependencies:
Configuration
Constructor Parameters
Host address to bind the WebSocket server
Port number for the WebSocket server
Transport configuration parameters
WebsocketServerParams Configuration
Add WAV header to audio frames
Frame serializer for WebSocket messages
Session timeout in seconds. If set, triggers timeout event when no activity is detected
Audio Output Configuration
Enable audio output capabilities
Audio output sample rate in Hz
Number of audio output channels
Voice Activity Detection (VAD)
Enable voice activity detection
Pass through audio during VAD
Voice Activity Detection analyzer. You can set this to either
SileroVADAnalyzer()
or WebRTCVADAnalyzer()
. SileroVADAnalyzer is the
recommended option. Learn more about the
SileroVADAnalyzer.
Basic Usage
Check out the Websocket Server example to see how to use this transport in a pipeline.
Event Callbacks
WebsocketServerTransport provides callbacks for handling client connection events. Register callbacks using the @transport.event_handler()
decorator.
Connection Events
Called when a client connects to the WebSocket server.
Parameters:
transport
: The WebsocketServerTransport instanceclient
: WebSocket client connection object
Called when a client disconnects from the WebSocket server.
Parameters:
transport
: The WebsocketServerTransport instanceclient
: WebSocket client connection object
Called when a session times out (if session_timeout is configured).
Parameters:
transport
: The WebsocketServerTransport instanceclient
: WebSocket client connection object
Frame Types
Input Frames
Raw audio data from the WebSocket client
Output Frames
Audio data to be sent to the WebSocket client
Notes
- Supports real-time audio communication
- Best suited for server-side applications
- Handles WebSocket connection management
- Provides voice activity detection
- Supports session timeouts
- Single client per server (new connections replace existing ones)
- All callbacks are asynchronous