base_user_turn_start_strategy
Base turn start strategy for determining when the user starts speaking.
- class pipecat.turns.user_start.base_user_turn_start_strategy.UserTurnStartedParams(enable_interruptions: bool, enable_user_speaking_frames: bool)[source]
Bases:
objectParameters emitted when a user turn starts.
These parameters are passed to the on_user_turn_started event and provide contextual information about how the user turn should be handled by the user aggregator.
- Parameters:
enable_user_speaking_frames – Whether to emit
UserStartedSpeakingFramefor this turn. False when the turn was already announced elsewhere — by a sharedUserTurnProcessor, or by a service that emits turn frames rather than proposing them.
- class pipecat.turns.user_start.base_user_turn_start_strategy.BaseUserTurnStartStrategy(*, enable_interruptions: bool = True, enable_user_speaking_frames: bool | None = None, **kwargs)[source]
Bases:
BaseObjectBase class for strategies that determine when a user starts speaking.
Subclasses should implement logic to detect the start of a user’s turn. This could be based on voice activity, number of words spoken, or other heuristics.
Events triggered by user turn start strategies:
on_push_frame: Indicates the strategy wants to push a frame.
on_broadcast_frame: Indicates the strategy wants to broadcast a frame.
on_user_turn_started: Reports the strategy’s decision that the user started, from
report_user_turn_started(). The turn controller starts the turn on the first decision, or once every start strategy has decided in aStrategyMode.ALLlist.on_reset_aggregation: Asks the user aggregator to drop the text aggregated so far, from
trigger_reset_aggregation().
- __init__(*, enable_interruptions: bool = True, enable_user_speaking_frames: bool | None = None, **kwargs)[source]
Initialize the base user turn start strategy.
- Parameters:
enable_interruptions – If True, the user aggregator will emit an interruption frame when the user turn starts.
enable_user_speaking_frames –
Whether to emit
UserStartedSpeakingFramewhen a turn starts, unlessreport_user_turn_started()overrides it for a given turn.Deprecated since version 1.8.0: Use
report_user_turn_started()’senable_user_speaking_framesargument instead. Will be removed in 2.0.0.**kwargs – Additional keyword arguments.
- property resolves_proposed_turn_start_frames: bool
Whether this strategy resolves proposals into turn starts.
A
ProposedUserStartedSpeakingFrameis a request for a decision, so a strategy that acts on one consumes it: the frame stops travelling, and no resolver further along decides the same turn a second time. Override to True in a strategy that handles that frame.
- async setup(setup: FrameProcessorSetup)[source]
Set up the strategy.
- Parameters:
setup – Configuration object containing setup parameters.
- async reset()[source]
Reset the strategy to its initial state.
Deprecated since version 1.6.0: Use
handle_user_turn_started()instead. Will be removed in 2.0.0.For a start strategy this only ever ran at turn start, so its work is “on turn start” — which is exactly what
handle_user_turn_started()names. New strategies should override that callback directly.
- async handle_user_turn_started()[source]
Notify the strategy that a user turn has started.
The controller calls this on every start strategy when a turn begins. Override to run, for example, logic to reset state and prepare for the next detection.
- async handle_user_turn_stopped()[source]
Notify the strategy that the user turn has stopped.
The controller calls this on every start strategy when a turn ends. Override if the strategy needs to act on turn end (likely uncommon).
- async process_frame(frame: Frame) ProcessFrameResult | None[source]
Process an incoming frame.
Subclasses should override this to implement logic that decides whether the user turn has started.
- Parameters:
frame – The frame to be processed.
- Returns:
Nothing. A returned
ProcessFrameResultis deprecated:STOPkeeps the strategies after this one from seeing the frame, and only in aStrategyMode.FIRSTlist.
- async push_frame(frame: Frame, direction: FrameDirection = FrameDirection.DOWNSTREAM)[source]
Emit on_push_frame to push a frame using the user aggreagtor.
- Parameters:
frame – The frame to be pushed.
direction – What direction the frame should be pushed to.
- async broadcast_frame(frame_cls: type[Frame], **kwargs)[source]
Emit on_broadcast_frame to broadcast a frame using the user aggreagtor.
- Parameters:
frame_cls – The class of the frame to be broadcasted.
**kwargs – Keyword arguments to be passed to the frame’s constructor.
- async report_user_turn_started(*, enable_interruptions: bool | None = None, enable_user_speaking_frames: bool | None = None)[source]
Report that the user started, by firing
on_user_turn_started.A strategy calls this when it decides the user’s turn has started. The turn controller starts the turn on the first decision, or once every start strategy has decided in a
StrategyMode.ALLlist.- Parameters:
enable_interruptions – Whether to broadcast an interruption for this turn, overriding the strategy’s configured setting. Pass False when something else in the pipeline has already broadcast one.
enable_user_speaking_frames – Whether to emit
UserStartedSpeakingFramefor this turn. Pass False when something else in the pipeline has already emitted it.
- async trigger_user_turn_started(*, enable_interruptions: bool | None = None, enable_user_speaking_frames: bool | None = None)[source]
Report that the user started.
Deprecated since version 1.15.0: Use
report_user_turn_started()instead. Will be removed in 2.0.0.- Parameters:
enable_interruptions – Whether to broadcast an interruption for this turn, overriding the strategy’s configured setting.
enable_user_speaking_frames – Whether to emit
UserStartedSpeakingFramefor this turn.