Plivo
- class pipecat.serializers.plivo.PlivoFrameSerializer(stream_id, call_id=None, auth_id=None, auth_token=None, params=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.
- Parameters:
stream_id (str)
call_id (str | None)
auth_id (str | None)
auth_token (str | None)
params (InputParams | None)
- _stream_id
The Plivo Stream ID.
- _call_id
The associated Plivo Call ID.
- _auth_id
Plivo auth ID for API access.
- _auth_token
Plivo authentication token for API access.
- _params
Configuration parameters.
- _plivo_sample_rate
Sample rate used by Plivo (typically 8kHz).
- _sample_rate
Input sample rate for the pipeline.
- _resampler
Audio resampler for format conversion.
- class InputParams(*, plivo_sample_rate=8000, sample_rate=None, auto_hang_up=True)[source]
Bases:
BaseModel
Configuration parameters for PlivoFrameSerializer.
- Parameters:
plivo_sample_rate (int)
sample_rate (int | None)
auto_hang_up (bool)
- plivo_sample_rate
Sample rate used by Plivo, defaults to 8000 Hz.
- Type:
int
- sample_rate
Optional override for pipeline input sample rate.
- Type:
int | None
- auto_hang_up
Whether to automatically terminate call on EndFrame.
- Type:
bool
- plivo_sample_rate: int
- sample_rate: int | None
- auto_hang_up: bool
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- property type: FrameSerializerType
Gets the serializer type.
- Returns:
The serializer type, either TEXT or BINARY.
- async setup(frame)[source]
Sets up the serializer with pipeline configuration.
- Parameters:
frame (StartFrame) – The StartFrame containing pipeline configuration.
- async serialize(frame)[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 (Frame) – The Pipecat frame to serialize.
- Returns:
Serialized data as string or bytes, or None if the frame isn’t handled.
- Return type:
str | bytes | None
- async deserialize(data)[source]
Deserializes Plivo WebSocket data to Pipecat frames.
Handles conversion of Plivo media events to appropriate Pipecat frames.
- Parameters:
data (str | bytes) – The raw WebSocket data from Plivo.
- Returns:
A Pipecat frame corresponding to the Plivo event, or None if unhandled.
- Return type:
Frame | None