Telnyx

class pipecat.serializers.telnyx.TelnyxFrameSerializer(stream_id, outbound_encoding, inbound_encoding, call_control_id=None, api_key=None, params=None)[source]

Bases: FrameSerializer

Serializer for Telnyx WebSocket protocol.

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

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

Parameters:
  • stream_id (str)

  • outbound_encoding (str)

  • inbound_encoding (str)

  • call_control_id (str | None)

  • api_key (str | None)

  • params (InputParams | None)

_stream_id

The Telnyx Stream ID.

_call_control_id

The associated Telnyx Call Control ID.

_api_key

Telnyx API key for API access.

_params

Configuration parameters.

_telnyx_sample_rate

Sample rate used by Telnyx (typically 8kHz).

_sample_rate

Input sample rate for the pipeline.

_resampler

Audio resampler for format conversion.

_hangup_attempted

Flag to track if hang-up has been attempted.

class InputParams(*, telnyx_sample_rate=8000, sample_rate=None, inbound_encoding='PCMU', outbound_encoding='PCMU', auto_hang_up=True)[source]

Bases: BaseModel

Configuration parameters for TelnyxFrameSerializer.

Parameters:
  • telnyx_sample_rate (int)

  • sample_rate (int | None)

  • inbound_encoding (str)

  • outbound_encoding (str)

  • auto_hang_up (bool)

telnyx_sample_rate

Sample rate used by Telnyx, defaults to 8000 Hz.

Type:

int

sample_rate

Optional override for pipeline input sample rate.

Type:

int | None

inbound_encoding

Audio encoding for data sent to Telnyx (e.g., “PCMU”).

Type:

str

outbound_encoding

Audio encoding for data received from Telnyx (e.g., “PCMU”).

Type:

str

auto_hang_up

Whether to automatically terminate call on EndFrame.

Type:

bool

telnyx_sample_rate: int
sample_rate: int | None
inbound_encoding: str
outbound_encoding: str
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 Telnyx WebSocket format.

Handles conversion of various frame types to Telnyx WebSocket messages. For EndFrames and CancelFrames, 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.

Raises:

ValueError – If an unsupported encoding is specified.

Return type:

str | bytes | None

async deserialize(data)[source]

Deserializes Telnyx WebSocket data to Pipecat frames.

Handles conversion of Telnyx media events to appropriate Pipecat frames, including audio data and DTMF keypresses.

Parameters:

data (str | bytes) – The raw WebSocket data from Telnyx.

Returns:

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

Raises:

ValueError – If an unsupported encoding is specified.

Return type:

Frame | None