eager_end_of_turn_mixin

Mixin for STT services that predict the end of a turn before committing to it.

class pipecat.turns.eager_end_of_turn_mixin.EagerEndOfTurnSTTServiceMixin(*args, enable_eager_end_of_turn: bool = False, eager_match_policy: EagerMatchPolicy | None = None, **kwargs)[source]

Bases: FrameProcessor

Adds eager end-of-turn signalling to an STT service that predicts one.

Some services report that a turn has probably ended before committing to it, and withdraw the prediction if the user turns out to be mid-sentence. A response can be generated during that gap — see EagerUserTurnStopStrategy, which acts on the frames pushed here. At most one prediction is outstanding at a time, so the frames need not name which one they mean.

A service drives the prediction through its own three lifecycle points:

# the service predicts the turn has ended
await self._push_eager_end_of_turn(transcript, user_id=..., language=...)

# the user resumed speaking, so the prediction is void
await self._cancel_eager_end_of_turn()

# the turn was committed, so the prediction is resolved
self._clear_eager_end_of_turn()

All three are safe to call when no prediction is outstanding, and all three are inert while enable_eager_end_of_turn is off, so a service can call them wherever its protocol reports a prediction without guarding each one.

__init__(*args, enable_eager_end_of_turn: bool = False, eager_match_policy: EagerMatchPolicy | None = None, **kwargs)[source]

Initialize the eager end-of-turn mixin.

Parameters:
  • *args – Positional arguments passed to the parent class.

  • enable_eager_end_of_turn – Whether to answer a predicted end of turn ahead of the committed one. Off by default: it spends an inference on every prediction, including the ones the service withdraws.

  • eager_match_policy – Decides whether the committed transcript is close enough to the predicted one to keep the speculative response. Only consulted while eager end of turn is on. See EagerUserTurnStrategies.

  • **kwargs – Keyword arguments passed to the parent class.

property eager_end_of_turn_enabled: bool

Whether predicted ends of turn are answered ahead of committed ones.

property eager_end_of_turn_pending: bool

Whether a prediction is awaiting a committed end of turn.

recommended_user_turn_strategies(*, enable_interruptions: bool) → UserTurnStrategies[source]

Build the turn strategies this service recommends.

Both recommendations leave turn detection to the service. The eager one additionally answers a predicted end of turn, which only makes sense for a service configured to report one.

Parameters:

enable_interruptions – Whether a proposal starting a turn should interrupt the bot.

Returns:

Strategies for the caller’s STTMetadataFrame.