plivo

Plivo WebSocket frame serializer for audio streaming.

class pipecat.serializers.plivo.PlivoFrameSerializer(stream_id: str, call_id: str | None = None, auth_id: str | None = None, auth_token: str | None = None, params: InputParams | None = None)[source]

Bases: FrameSerializer

Serializer for Plivo Audio Streaming WebSocket protocol.

This serializer handles converting between Pipecat frames and Plivo’s WebSocket audio streaming protocol. It supports audio conversion, DTMF events, and automatic call termination.

When auto_hang_up is enabled (default), the serializer will automatically terminate the Plivo call when an EndFrame or CancelFrame is processed, but requires Plivo credentials to be provided.

class InputParams(*, ignore_rtvi_messages: bool = True, plivo_sample_rate: int = 8000, sample_rate: int | None = None, auto_hang_up: bool = True)[source]

Bases: InputParams

Configuration parameters for PlivoFrameSerializer.

Parameters:
  • plivo_sample_rate – Sample rate used by Plivo, defaults to 8000 Hz.

  • sample_rate – Optional override for pipeline input sample rate.

  • auto_hang_up – Whether to automatically terminate call on EndFrame.

  • ignore_rtvi_messages – Inherited from base FrameSerializer, defaults to True.

plivo_sample_rate: int
sample_rate: int | None
auto_hang_up: bool
__init__(stream_id: str, call_id: str | None = None, auth_id: str | None = None, auth_token: str | None = None, params: InputParams | None = None)[source]

Initialize the PlivoFrameSerializer.

Parameters:
  • stream_id – The Plivo Stream ID.

  • call_id – The associated Plivo Call ID (optional, but required for auto hang-up).

  • auth_id – Plivo auth ID (required for auto hang-up).

  • auth_token – Plivo auth token (required for auto hang-up).

  • params – Configuration parameters.

async setup(frame: StartFrame)[source]

Sets up the serializer with pipeline configuration.

Parameters:

frame – The StartFrame containing pipeline configuration.

async serialize(frame: Frame) str | bytes | None[source]

Serializes a Pipecat frame to Plivo WebSocket format.

Handles conversion of various frame types to Plivo WebSocket messages. For EndFrames, initiates call termination if auto_hang_up is enabled.

Parameters:

frame – The Pipecat frame to serialize.

Returns:

Serialized data as string or bytes, or None if the frame isn’t handled.

async deserialize(data: str | bytes) Frame | None[source]

Deserializes Plivo WebSocket data to Pipecat frames.

Handles conversion of Plivo media events to appropriate Pipecat frames.

Parameters:

data – The raw WebSocket data from Plivo.

Returns:

A Pipecat frame corresponding to the Plivo event, or None if unhandled.