Pipecat C++ Client SDK 1.0.0
Connect native apps to Pipecat bots
Loading...
Searching...
No Matches
pipecat::WebSocketTransport Class Reference

#include <pipecat/websocket/transport.h>

Inheritance diagram for pipecat::WebSocketTransport:
pipecat::Transport

Public Member Functions

 WebSocketTransport (WebSocketTransportOptions options={})
 Creates a transport.
 
 ~WebSocketTransport () override
 Disconnects if needed.
 
 WebSocketTransport (const WebSocketTransport &)=delete
 Transports can't be copied.
 
WebSocketTransport & operator= (const WebSocketTransport &)=delete
 Transports can't be copied.
 
void initialize (TransportObserver *observer) override
 Prepares the transport.
 
void connect (const nlohmann::json &params) override
 
void disconnect () override
 Closes the WebSocket.
 
void send_ready_message (const rtvi::Message &message) override
 Sends the client-ready message.
 
void send_message (const rtvi::Message &message) override
 Sends a message to the bot.
 
size_t max_message_size () const override
 The largest message the bot accepts, about 1 MB.
 
int32_t send_user_audio (const int16_t *frames, size_t num_frames) override
 
int32_t read_bot_audio (int16_t *frames, size_t num_frames) override
 

Detailed Description

Connects to Pipecat bots over a WebSocket.

Give it to PipecatClientOptions::transport. To connect, it needs the URL of the bot's WebSocket, and a token if the bot needs one. Start endpoints like Pipecat's development runner (python bot.py -t websocket) return both, as wsUrl and token, when asked for the websocket transport.

You can use several at the same time, e.g. one per client to talk to several bots.

Member Function Documentation

◆ connect()

void pipecat::WebSocketTransport::connect ( const nlohmann::json &  params)
overridevirtual

Connects to the bot's WebSocket.

params has the URL in wsUrl (or ws_url), and the token, if the bot needs one, in token. Throws InvalidTransportParamsError if the URL is missing or isn't a WebSocket URL, and TransportStartError if connecting fails.

Implements pipecat::Transport.

◆ disconnect()

void pipecat::WebSocketTransport::disconnect ( )
overridevirtual

Closes the WebSocket.

Implements pipecat::Transport.

◆ initialize()

void pipecat::WebSocketTransport::initialize ( TransportObserver *  observer)
overridevirtual

Prepares the transport.

Implements pipecat::Transport.

◆ max_message_size()

size_t pipecat::WebSocketTransport::max_message_size ( ) const
overridevirtual

The largest message the bot accepts, about 1 MB.

Reimplemented from pipecat::Transport.

◆ read_bot_audio()

int32_t pipecat::WebSocketTransport::read_bot_audio ( int16_t *  frames,
size_t  num_frames 
)
overridevirtual

Reads up to num_frames frames of 16-bit PCM bot audio into frames, converted to the format of the options. Waits until there's audio to read, or until the transport disconnects. Returns the number of frames read, or 0 if it disconnected.

The bot only sends audio while it speaks, and sends it faster than it plays. The transport keeps up to a minute of it, and drops what's left when the bot is interrupted, so read it as you play it.

Implements pipecat::Transport.

◆ send_message()

void pipecat::WebSocketTransport::send_message ( const rtvi::Message &  message)
overridevirtual

Sends a message to the bot.

Implements pipecat::Transport.

◆ send_ready_message()

void pipecat::WebSocketTransport::send_ready_message ( const rtvi::Message &  message)
overridevirtual

Sends the client-ready message.

Implements pipecat::Transport.

◆ send_user_audio()

int32_t pipecat::WebSocketTransport::send_user_audio ( const int16_t *  frames,
size_t  num_frames 
)
overridevirtual

Sends num_frames frames of 16-bit PCM user audio, in the format of the options. Returns the number of frames sent.

Send the audio continuously, as it's captured, and send silence while the user is muted: the bot needs it to tell when the user stops speaking. The audio is sent as is, without echo cancellation.

Implements pipecat::Transport.


The documentation for this class was generated from the following file: