perception
Perception: how the user said what they said.
Part of expressive conversation, which lets an agent hear how something was
said and answer in kind. A perception producer, such as an STT service or a
processor after it, reads each user turn and sets what it perceives as the
transcription’s perception: signals, such as a tone with the likeliest
labels and how sure it is of each, or a measure such as speech rate. It
declares the signals it reports with PerceptionCapabilities, and
broadcasts them at start in a
PerceptionMetadataFrame, so the LLM can be told
how to read them. A turn read more than once is merged with
merge_perception(), keeping the higher of each signal. A producer after
another adds its reading to the one the transcription carries and declares
both producers’ signals together, so the latest declaration names every signal
a transcription can carry.
Alpha. These types are likely to change between releases.
- class pipecat.expressive.perception.PerceptionSignal(name: str, labels: list[tuple[str, float]]=<factory>, value: float | None = None)[source]
Bases:
objectOne reading of how the user spoke.
A signal is read either as labels or as a value.
- Parameters:
name – What is read, such as
"tone"or"speech_rate".labels – The likeliest labels, likeliest first, each with how sure the reading is, from 0 to 1, such as
[("frustrated", 0.86), ("neutral", 0.10)]. Empty for a signal read as a value.value – The measure, for a signal read as a value, such as words per second. None for a signal read as labels.
- class pipecat.expressive.perception.PerceptionTerm(name: str, description: str = '', labels: list[str] = <factory>)[source]
Bases:
objectOne signal a perception producer reports.
- Parameters:
name – The signal’s name, as in
PerceptionSignal.name.description – A short line on how to read it, such as its unit or range, or empty.
labels – The labels it can report, for a signal read as labels, or empty for a signal read as a value.
- class pipecat.expressive.perception.PerceptionCapabilities(signals: list[PerceptionTerm] = <factory>)[source]
Bases:
objectThe signals a perception producer reports.
- Parameters:
signals – Each signal the producer can report.
- merge(other: PerceptionCapabilities) PerceptionCapabilities[source]
Merge another producer’s signals into these.
A signal both report keeps every label either can report and the first description that isn’t empty.
- Parameters:
other – The other producer’s signals.
- Returns:
The signals of both, these first.
- pipecat.expressive.perception.format_perception(signals: list[PerceptionSignal]) str[source]
Format a reading as written at the head of the user’s message to the LLM.
Each signal is a category in brackets: its labels with their confidences, so the LLM can tell a clear reading from a guess, or its measure as a value.
([tone frustrated=0.86, neutral=0.10],[speech_rate value=4.1]).- Parameters:
signals – The signals read.
- Returns:
The formatted reading.
- pipecat.expressive.perception.merge_perception(merged: list[PerceptionSignal] | None, reading: list[PerceptionSignal]) list[PerceptionSignal][source]
Merge a reading into the readings of the same turn so far, keeping the higher of each.
A signal read as a value keeps its highest value. A signal read as labels keeps every label either reading has, each with its highest confidence, likeliest first. A signal only one of them has is kept as it is, and the signals stay in the order they were first read.
- Parameters:
merged – The readings merged so far, or None before the first.
reading – The reading to merge in.
- Returns:
The merged reading.