producer_processor
Producer processor for frame filtering and distribution.
- async pipecat.processors.producer_processor.identity_transformer(frame: Frame)[source]
Default transformer that returns the frame unchanged.
- Parameters:
frame – The frame to transform.
- Returns:
The same frame without modifications.
- class pipecat.processors.producer_processor.ProducerProcessor(*, filter: ~collections.abc.Callable[[~pipecat.frames.frames.Frame], ~collections.abc.Awaitable[bool]], transformer: ~collections.abc.Callable[[~pipecat.frames.frames.Frame], ~collections.abc.Awaitable[~pipecat.frames.frames.Frame]] = <function identity_transformer>, passthrough: bool = True)[source]
Bases:
FrameProcessorA processor that filters frames and distributes them to multiple consumers.
This processor receives frames, applies a filter to determine which frames should be sent to consumers (ConsumerProcessor), optionally transforms those frames, and distributes them to registered consumer queues. It can also pass frames through to the next processor in the pipeline.
- __init__(*, filter: ~collections.abc.Callable[[~pipecat.frames.frames.Frame], ~collections.abc.Awaitable[bool]], transformer: ~collections.abc.Callable[[~pipecat.frames.frames.Frame], ~collections.abc.Awaitable[~pipecat.frames.frames.Frame]] = <function identity_transformer>, passthrough: bool = True)[source]
Initialize the producer processor.
- Parameters:
filter – Async function that determines if a frame should be produced. Must return True for frames to be sent to consumers.
transformer – Async function to transform frames before sending to consumers. Defaults to identity_transformer which returns frames unchanged.
passthrough – Whether to pass frames through to the next processor. If True, all frames continue downstream regardless of filter result.
- add_consumer()[source]
Add a new consumer and return its associated queue.
- Returns:
The queue for the newly added consumer.
- Return type:
asyncio.Queue
- async process_frame(frame: Frame, direction: FrameDirection)[source]
Process an incoming frame and determine whether to produce it.
If the frame meets the filter criteria, it will be transformed and added to all consumer queues. If passthrough is enabled, the original frame will also be sent downstream.
- Parameters:
frame – The frame to process.
direction – The direction of the frame flow.