base_output

Base output transport implementation for Pipecat.

This module provides the BaseOutputTransport class which handles audio and video output processing, including frame buffering, mixing, timing, and media streaming.

class pipecat.transports.base_output.BaseOutputTransport(params: TransportParams, **kwargs)[source]

Bases: FrameProcessor

Base class for output transport implementations.

Handles audio and video output processing including frame buffering, audio mixing, timing coordination, and media streaming. Supports multiple output destinations and provides interruption handling for real-time communication.

__init__(params: TransportParams, **kwargs)[source]

Initialize the base output transport.

Parameters:
  • params – Transport configuration parameters.

  • **kwargs – Additional arguments passed to parent class.

property sample_rate: int

Get the current audio sample rate.

Returns:

The sample rate in Hz.

property audio_chunk_size: int

Get the audio chunk size for output processing.

Returns:

The size of audio chunks in bytes.

async start(frame: StartFrame)[source]

Start the output transport and initialize components.

Parameters:

frame – The start frame containing initialization parameters.

async stop(frame: EndFrame)[source]

Stop the output transport and cleanup resources.

Parameters:

frame – The end frame signaling transport shutdown.

async cancel(frame: CancelFrame)[source]

Cancel the output transport and stop all processing.

Parameters:

frame – The cancel frame signaling immediate cancellation.

async set_transport_ready(frame: StartFrame)[source]

Called when the transport is ready to stream.

Parameters:

frame – The start frame containing initialization parameters.

async send_message(frame: OutputTransportMessageFrame | OutputTransportMessageUrgentFrame)[source]

Send a transport message.

Parameters:

frame – The transport message frame to send.

async register_video_destination(destination: str)[source]

Register a video output destination.

Parameters:

destination – The destination identifier to register.

async register_audio_destination(destination: str)[source]

Register an audio output destination.

Parameters:

destination – The destination identifier to register.

async write_video_frame(frame: OutputImageRawFrame) bool[source]

Write a video frame to the transport.

Parameters:

frame – The output video frame to write.

Returns:

True if the video frame was written successfully, False otherwise.

async write_audio_frame(frame: OutputAudioRawFrame) bool[source]

Write an audio frame to the transport.

Parameters:

frame – The output audio frame to write.

Returns:

True if the audio frame was written successfully, False otherwise.

async write_dtmf(frame: OutputDTMFFrame | OutputDTMFUrgentFrame)[source]

Write a DTMF tone using the transport’s preferred method.

Parameters:

frame – The DTMF frame to write.

async write_transport_frame(frame: Frame)[source]

Handle a queued frame after preceding audio has been sent.

Override in transport subclasses to handle custom frame types that flow through the audio queue. Called by the media sender after the frame has waited for any preceding audio to finish.

Parameters:

frame – The frame to handle.

async send_audio(frame: OutputAudioRawFrame)[source]

Send an audio frame downstream.

Parameters:

frame – The audio frame to send.

async send_image(frame: OutputImageRawFrame | SpriteFrame)[source]

Send an image frame downstream.

Parameters:

frame – The image frame to send.

async process_frame(frame: Frame, direction: FrameDirection)[source]

Process incoming frames and handle transport-specific logic.

Parameters:
  • frame – The frame to process.

  • direction – The direction of frame flow in the pipeline.

class MediaSender(transport: BaseOutputTransport, *, destination: str | None, sample_rate: int, audio_chunk_size: int, params: TransportParams)[source]

Bases: object

Handles media streaming for a specific destination.

Manages audio and video output processing including buffering, timing, mixing, and frame delivery for a single output destination.

__init__(transport: BaseOutputTransport, *, destination: str | None, sample_rate: int, audio_chunk_size: int, params: TransportParams)[source]

Initialize the media sender.

Parameters:
  • transport – The parent transport instance.

  • destination – The destination identifier for this sender.

  • sample_rate – The audio sample rate in Hz.

  • audio_chunk_size – The size of audio chunks in bytes.

  • params – Transport configuration parameters.

property sample_rate: int

Get the audio sample rate.

Returns:

The sample rate in Hz.

property audio_chunk_size: int

Get the audio chunk size.

Returns:

The size of audio chunks in bytes.

async start(frame: StartFrame)[source]

Start the media sender and initialize components.

Parameters:

frame – The start frame containing initialization parameters.

async stop(frame: EndFrame)[source]

Stop the media sender and cleanup resources.

Parameters:

frame – The end frame signaling sender shutdown.

async cancel(frame: CancelFrame)[source]

Cancel the media sender and stop all processing.

Parameters:

frame – The cancel frame signaling immediate cancellation.

async handle_interruptions(_: InterruptionFrame)[source]

Handle interruption events by restarting tasks and clearing buffers.

Parameters:

_ – The start interruption frame (unused).

async handle_audio_frame(frame: OutputAudioRawFrame)[source]

Handle incoming audio frames by buffering and chunking.

Parameters:

frame – The output audio frame to handle.

async handle_image_frame(frame: OutputImageRawFrame | SpriteFrame)[source]

Handle incoming image frames for video output.

Parameters:

frame – The output image or sprite frame to handle.

async handle_timed_frame(frame: Frame)[source]

Handle frames with presentation timestamps.

Parameters:

frame – The frame with timing information to handle.

async handle_sync_frame(frame: Frame)[source]

Handle frames that need synchronized processing.

Parameters:

frame – The frame to handle synchronously.

async handle_mixer_control_frame(frame: MixerControlFrame)[source]

Handle audio mixer control frames.

Parameters:

frame – The mixer control frame to handle.