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: object

Parameters 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 UserStartedSpeakingFrame for this turn. False when the turn was already announced elsewhere — by a shared UserTurnProcessor, or by a service that emits turn frames rather than proposing them.

enable_interruptions: bool
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: BaseObject

Base 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 a StrategyMode.ALL list.

  • 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 UserStartedSpeakingFrame when a turn starts, unless report_user_turn_started() overrides it for a given turn.

    Deprecated since version 1.8.0: Use report_user_turn_started()’s enable_user_speaking_frames argument 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 ProposedUserStartedSpeakingFrame is 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 cleanup()[source]

Cleanup the strategy.

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 ProcessFrameResult is deprecated: STOP keeps the strategies after this one from seeing the frame, and only in a StrategyMode.FIRST list.

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.ALL list.

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 UserStartedSpeakingFrame for 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 UserStartedSpeakingFrame for this turn.

async trigger_reset_aggregation()[source]

Trigger the on_reset_aggregation event.