base_audio_filter

Base audio filter interface for transport audio processing.

This module provides the abstract base class for implementing audio filters that process audio data before VAD and downstream processing in input transports, or before the mixer and the write in output transports.

class pipecat.audio.filters.base_audio_filter.BaseAudioFilter[source]

Bases: ABC

Base class for transport audio filters.

This is a base class for transport audio filters. If an audio filter is provided to the input transport it will be used to process audio before VAD and before pushing it downstream. If an audio filter is provided to the output transport it will be used to process the audio it receives before mixing and writing it. There are control frames to update filter settings or to enable or disable the filter at runtime.

abstractmethod async start(sample_rate: int)[source]

Initialize the filter when the transport is set up.

Called once, from the transport’s setup, and paired with stop(). The transport sample rate is provided so the filter can adjust to that sample rate.

Parameters:

sample_rate – The sample rate of the transport in Hz.

abstractmethod async stop()[source]

Clean up the filter when the transport is cleaned up.

Called once, from the transport’s cleanup, and paired with start().

abstractmethod async process_frame(frame: FilterControlFrame)[source]

Process control frames for runtime filter configuration.

This will be called when the transport receives a FilterControlFrame.

Parameters:

frame – The control frame containing filter commands or settings.

abstractmethod async filter(audio: bytes) → bytes[source]

Apply the audio filter to the provided audio data.

Parameters:

audio – Raw audio data as bytes to be filtered.

Returns:

Filtered audio data as bytes.