speaking_observer
Observer reporting who was speaking, and when.
A conversation is a sequence of people taking the floor and occasionally taking it from each other. This observer reports each of those moments as it happens, leaving what counts as a turn to whoever reads them: a turn boundary is a policy, and a policy that ships inside a record can never be revised.
- class pipecat.observers.speaking_observer.SpeechEventKind(*values)[source]
Bases:
StrEnumWhat happened, to whom, and at which layer.
The user appears at two layers, and they answer different questions.
user_speech_*is the speech itself, as the voice activity detector heard it: speech that never becomes a turn — a cough, a false start, a pause mid-sentence — appears only here.user_turn_*is the turn strategy’s ruling on that speech, which is what the rest of the pipeline acts on, and follows the speech by however long the ruling took.- USER_SPEECH_STARTED = 'user_speech_started'
- USER_SPEECH_STOPPED = 'user_speech_stopped'
- USER_TURN_STARTED = 'user_turn_started'
- USER_TURN_STOPPED = 'user_turn_stopped'
- BOT_SPEECH_STARTED = 'bot_speech_started'
- BOT_SPEECH_STOPPED = 'bot_speech_stopped'
- INTERRUPTION = 'interruption'
- class pipecat.observers.speaking_observer.SpeechEvent(*, kind: SpeechEventKind, timestamp: float, started_at: float | None = None)[source]
Bases:
BaseModelOne moment in the conversation’s speaking lifecycle.
- Parameters:
kind – What happened, to whom, and at which layer.
timestamp – Unix timestamp of the moment itself. Speech is timed to when it began and ended, not to when the detector confirmed it, so an interval drawn from these matches what was said.
started_at – When the matching stretch of speech began, on the moments that end one, so a stretch reads as an interval without pairing it with the moment that opened it.
- class pipecat.observers.speaking_observer.SpeakingObserver(*, time_source: Callable[[], float]=<built-in function time>, **kwargs)[source]
Bases:
BaseObserverReports the speaking lifecycle of a conversation.
Every moment is reported as it happens, and the moments that close a stretch of speech name where it began, so an interval reads whole from one record: a stretch whose closing moment never arrives stays open rather than quietly joining itself to the next one. What a turn is stays with the reader: a turn built here would freeze one definition into every record, where the moments themselves can be grouped again later, differently, over the same history.
- Events:
- on_speech_event(observer, event): Emitted for each moment, as a
Example:
observer = SpeakingObserver() @observer.event_handler("on_speech_event") async def on_speech_event(observer, event): logger.info(event.model_dump_json())
- __init__(*, time_source: Callable[[], float]=<built-in function time>, **kwargs)[source]
Initialize the speaking observer.
- Parameters:
time_source – Reads the current time in seconds. Supplying one lets a test place moments without waiting.
**kwargs – Additional arguments passed to parent class.
- async on_push_frame(data: FramePushed)[source]
Report the moment a frame represents.
- Parameters:
data – Frame push event containing the frame and direction.