user_start
- class pipecat.turns.user_start.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.
- class pipecat.turns.user_start.ExternalUserTurnStartStrategy(*, enable_interruptions: bool = True, **kwargs)[source]
Bases:
BaseUserTurnStartStrategyUser turn start strategy driven by another component in the pipeline.
Rather than detecting the start of a turn itself, this strategy takes its cue from another processor. It understands two signals, which differ in how much the emitter has already done:
ProposedUserStartedSpeakingFrame— a service with its own turn detection proposing a turn boundary. This strategy makes the decision, emitting theUserStartedSpeakingFrameand broadcasting the interruption itself. Subclass it to adjust when, or whether, a proposal opens a turn.UserStartedSpeakingFrame— the turn was already decided and announced elsewhere, typically by a sharedUserTurnProcessorfanning turns out to several aggregators. This strategy adopts that decision and emits nothing, so the turn isn’t announced twice.
A service that emits turn frames directly lands on the adopt path and keeps working, but it owns the interruption logic itself. Emitting proposals instead hands that job back to the pipeline.
- __init__(*, enable_interruptions: bool = True, **kwargs)[source]
Initialize the external user turn start strategy.
- Parameters:
enable_interruptions – If True, broadcast an interruption when a proposal opens a turn. Ignored on the adopt path, where the emitter has already broadcast one.
**kwargs – Additional keyword arguments.
- class pipecat.turns.user_start.KrispVivaIPUserTurnStartStrategy(*, model_path: str | None = None, threshold: float = 0.5, frame_duration_ms: int = 20, api_key: str = '', **kwargs)[source]
Bases:
BaseUserTurnStartStrategyUser turn start strategy using Krisp VIVA Interruption Prediction.
When VAD detects user speech, this strategy feeds audio frames into the Krisp VIVA IP model. The model outputs a probability indicating whether the speech is a genuine interruption (as opposed to a backchannel). A user turn is triggered only when this probability exceeds the configured threshold. With
krisp_audio1.14.0 or newer the strategy also tracks whether the bot is speaking, and while it is not, a user turn is triggered as soon as VAD detects speech.This strategy can work alongside other start strategies (e.g.
TranscriptionUserTurnStartStrategyas a fallback) via the strategy list inUserTurnStrategies.Example:
from pipecat.turns.user_start import KrispVivaIPUserTurnStartStrategy strategies = UserTurnStrategies( start=[ KrispVivaIPUserTurnStartStrategy( model_path="/path/to/ip_model.kef", threshold=0.5, ), TranscriptionUserTurnStartStrategy(), ], )
- __init__(*, model_path: str | None = None, threshold: float = 0.5, frame_duration_ms: int = 20, api_key: str = '', **kwargs)[source]
Initialize the Krisp VIVA IP user turn start strategy.
- Parameters:
model_path – Path to the Krisp VIVA IP model file (.kef). If None, uses the KRISP_VIVA_IP_MODEL_PATH environment variable.
threshold – IP probability threshold (0.0 to 1.0). When the model’s output exceeds this value, the speech is classified as a genuine interruption.
frame_duration_ms – Frame duration in milliseconds for IP processing. Supported values: 10, 15, 20, 30, 32.
api_key – Krisp SDK API key. If empty, falls back to the KRISP_VIVA_API_KEY environment variable.
**kwargs – Additional arguments passed to BaseUserTurnStartStrategy.
- async process_frame(frame: Frame)[source]
Process a frame to detect genuine user interruptions.
On
VADUserStartedSpeakingFrame, begins collecting audio. OnInputAudioRawFrame, feeds audio through the IP model and triggers a user turn if the interruption probability exceeds the threshold. OnBotStartedSpeakingFrame, marks the bot as speaking. OnBotStoppedSpeakingFrame, clears it; if the user is still speaking with no decision made yet, starts the user turn, otherwise resets the candidate state. OnVADUserStoppedSpeakingFrame, resets the candidate state.- Parameters:
frame – The incoming frame.
- class pipecat.turns.user_start.MinWordsUserTurnStartStrategy(*, min_words: int, use_interim: bool = True, **kwargs)[source]
Bases:
BaseUserTurnStartStrategyUser turn start strategy based on a minimum number of words spoken by the user.
This strategy signals the start of a user turn once the user has spoken at least a specified number of words, as determined from transcription frames. Optionally, interim transcriptions can be used for earlier detection.
A word is a whitespace-separated token. Chinese and Japanese text has no spaces between words, so each of those characters counts as a word. See
pipecat.utils.text.word_count.count_spoken_words().- __init__(*, min_words: int, use_interim: bool = True, **kwargs)[source]
Initialize the minimum words bot turn start strategy.
- Parameters:
min_words – Minimum number of spoken words required to trigger the start of a user turn.
use_interim – Whether to consider interim transcription frames for earlier detection.
**kwargs – Additional keyword arguments.
- class pipecat.turns.user_start.TranscriptionUserTurnStartStrategy(*, use_interim: bool = True, **kwargs)[source]
Bases:
BaseUserTurnStartStrategyUser turn start strategy based on transcriptions.
This strategy signals the start of a user turn when a transcription is received while the bot is speaking. It is useful as a fallback in scenarios where VAD-based detection fails (for example, when the user speaks very softly) but the STT service still produces transcriptions.
- class pipecat.turns.user_start.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.VADUserTurnStartStrategy(*, enable_interruptions: bool = True, enable_user_speaking_frames: bool | None = None, **kwargs)[source]
Bases:
BaseUserTurnStartStrategyUser turn start strategy based on VAD (Voice Activity Detection).
This strategy assumes the user turn starts as soon as a VAD frame indicates that the user has started speaking.
- class pipecat.turns.user_start.WakePhraseUserTurnStartStrategy(*, phrases: list[str], timeout: float = 10.0, single_activation: bool = False, **kwargs)[source]
Bases:
BaseUserTurnStartStrategyUser turn start strategy that requires a wake phrase before interaction.
Starts a turn when it hears a wake phrase in a final transcription, and then, until a configurable timeout, whenever the user starts speaking or a final transcription arrives, which covers speech VAD missed. Use
single_activation=Trueto require the wake phrase before every turn. Speech before the wake phrase is dropped from the aggregation.It starts turns on its own, so use it as the only start strategy:
user_params=LLMUserAggregatorParams( user_turn_strategies=UserTurnStrategies( start=[WakePhraseUserTurnStartStrategy(phrases=["hey pipecat"])], ), )
To combine it with other start strategies, such as
MinWordsUserTurnStartStrategy, put them in aStrategyMode.ALLlist, where it’s one more condition a turn needs. In aStrategyMode.FIRSTlist next to other start strategies it has to come first: until it hears the wake phrase, it keeps the strategies after it from seeing frames, and once awake it starts turns itself, so the strategies after it no longer decide. That is deprecated, along withProcessFrameResult.Event handlers available:
on_wake_phrase_detected: Called when a wake phrase is matched.
on_wake_phrase_timeout: Called when the inactivity timeout expires (timeout mode only).
Example:
# Timeout mode (default): wake phrase unlocks interaction for 10s strategy = WakePhraseUserTurnStartStrategy( phrases=["hey pipecat", "ok pipecat"], timeout=10.0, ) # Single activation: wake phrase required before every turn strategy = WakePhraseUserTurnStartStrategy( phrases=["hey pipecat"], single_activation=True, ) @strategy.event_handler("on_wake_phrase_detected") async def on_wake_phrase_detected(strategy, phrase): ... @strategy.event_handler("on_wake_phrase_timeout") async def on_wake_phrase_timeout(strategy): ...
- Parameters:
phrases – List of wake phrases to detect. Entries that are blank after stripping punctuation are ignored.
timeout – Inactivity timeout in seconds before returning to IDLE. In timeout mode, the timer resets on activity (user, bot speech). In single activation mode, acts as a keepalive window — the strategy stays AWAKE for this duration after wake phrase detection, allowing the current turn to complete before returning to IDLE.
single_activation – If True, the wake phrase is required before every turn. The strategy returns to IDLE after each turn completes.
**kwargs – Additional keyword arguments passed to parent.
- __init__(*, phrases: list[str], timeout: float = 10.0, single_activation: bool = False, **kwargs)[source]
Initialize the wake phrase user turn start strategy.
- Parameters:
phrases – List of wake phrases to detect. Entries that are blank after stripping punctuation are ignored.
timeout – Inactivity timeout in seconds before returning to IDLE. In timeout mode, the timer resets on activity. In single activation mode, acts as a keepalive window after wake phrase detection.
single_activation – If True, the wake phrase is required before every turn. The strategy returns to IDLE after each turn completes.
**kwargs – Additional keyword arguments passed to parent.
- property state: _WakeState
Returns the current wake state.
- async setup(setup: FrameProcessorSetup)[source]
Set up the strategy.
- Parameters:
setup – Configuration object containing setup parameters.
- async handle_user_turn_started()[source]
Ready the strategy for a new user turn.
In timeout mode, preserves state and refreshes the timeout — a turn starting is the activity that keeps the strategy awake. In single activation mode, does nothing: the keepalive timeout (started when the wake phrase was detected) handles the transition back to IDLE.
- async process_frame(frame: Frame) ProcessFrameResult | None[source]
Process an incoming frame for wake phrase detection or passthrough.
- Parameters:
frame – The frame to be processed.
- Returns:
ProcessFrameResult.STOPuntil the wake phrase is heard, which keeps the strategies after this one in aStrategyMode.FIRSTlist from seeing the frame. That gating is deprecated.
Submodules
- base_user_turn_start_strategy
UserTurnStartedParamsBaseUserTurnStartStrategyBaseUserTurnStartStrategy.__init__()BaseUserTurnStartStrategy.resolves_proposed_turn_start_framesBaseUserTurnStartStrategy.setup()BaseUserTurnStartStrategy.cleanup()BaseUserTurnStartStrategy.reset()BaseUserTurnStartStrategy.handle_user_turn_started()BaseUserTurnStartStrategy.handle_user_turn_stopped()BaseUserTurnStartStrategy.process_frame()BaseUserTurnStartStrategy.push_frame()BaseUserTurnStartStrategy.broadcast_frame()BaseUserTurnStartStrategy.report_user_turn_started()BaseUserTurnStartStrategy.trigger_user_turn_started()BaseUserTurnStartStrategy.trigger_reset_aggregation()
- external_user_turn_start_strategy
- krisp_viva_ip_user_turn_start_strategy
- min_words_user_turn_start_strategy
- transcription_user_turn_start_strategy
- vad_user_turn_start_strategy
- wake_phrase_user_turn_start_strategy