reader

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: BSD-2-Clause Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package reader reads how each user turn was meant, from its words, with the tone reader model (alpha).

The model (https://huggingface.co/pipecat-ai/tone-models) reads one turn of text, with the turn before it, and returns the speaker's emotion, whether the turn is sarcastic, the move it makes and whether it is only a listening sound, each with a calibrated confidence. It runs on the CPU in a few milliseconds, through the ONNX runtime.

Part of expressive conversation (alpha). These types are likely to change between releases.

Index

Constants

View Source
const (
	// Repo is the Hugging Face repository the tone models are released in.
	Repo = "pipecat-ai/tone-models"
	// Revision is the reader's release the reader downloads by default.
	Revision = "reader-rc2"
)

Variables

View Source
var ErrPrecision = errors.New("reader: unknown precision")

ErrPrecision is returned for a precision the model is not released in.

Functions

This section is empty.

Types

type BackchannelTag

type BackchannelTag struct {
	IsBackchannel bool
	Probability   float64
}

BackchannelTag is whether the turn is only a listening sound.

type Config

type Config struct {
	// Name is the processor's name. Empty is "ToneReader".
	Name string
	// Revision is the model's release on Hugging Face, such as "reader-rc2".
	// Empty is Revision.
	Revision string
	// ModelDir is a folder to load the model from instead of downloading one,
	// laid out as a release's "reader" folder. Revision is then unused.
	ModelDir string
	// Precision is the weights to load. Empty is FP16.
	Precision Precision `validate:"omitempty,oneof=fp16 fp32"`
	// Threads is the CPU threads for one read. Zero is 4.
	Threads int `validate:"min=0"`
	// CacheDir is where a downloaded model is kept. Empty is Hugging Face's own
	// cache, ~/.cache/huggingface/hub.
	CacheDir string
}

Config configures a Reader. The zero value downloads the default release at FP16 and reads with four threads.

type EmotionTag

type EmotionTag struct {
	Label     string
	Intensity string
	// Confidence is the likeliest label's probability.
	Confidence float64
	// Probabilities is every emotion's probability, in the model's order.
	Probabilities []Probability
}

EmotionTag is the feeling the turn's words show.

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model is the reader's model, on the CPU.

func DownloadModel

func DownloadModel(
	ctx context.Context, revision string, precision Precision, threads int, cacheDir string,
) (*Model, error)

DownloadModel loads the model's release from Hugging Face, downloading its files into cacheDir the first time. An empty cacheDir is Hugging Face's own cache.

func LoadModel

func LoadModel(dir string, precision Precision, threads int) (*Model, error)

LoadModel loads the model from a folder holding its config.json, tokenizer.json and ONNX file, using threads CPU threads for one read.

func (*Model) Emotions

func (m *Model) Emotions() []string

Emotions is the emotions the model reads.

func (*Model) Tag

func (m *Model) Tag(text, previous string) (Tags, error)

Tag reads one turn, with the turn before it when there is one.

type MoveTag

type MoveTag struct {
	Label         string
	Confidence    float64
	Probabilities []Probability
}

MoveTag is what the turn does, such as asking or answering.

type Precision

type Precision string

Precision is the weights a model is loaded with.

const (
	// FP16 is the weights in 16 bits, which give the same tags at half the size.
	FP16 Precision = "fp16"
	// FP32 is the weights in 32 bits.
	FP32 Precision = "fp32"
)

type Probability

type Probability struct {
	Label       string
	Probability float64
}

Probability is one label's probability.

type Reader

type Reader struct {
	*processor.Base
	// contains filtered or unexported fields
}

Reader reads how each user turn was meant.

It goes between the STT service and the user aggregator. Each final transcription is read, with the bot's reply before it, and the reading is set as its Perception: the turn's "emotion", its two likeliest labels with their confidences, and its "sarcasm", the chance it is sarcastic. The transcription waits for the read, a few milliseconds.

The model loads while the pipeline is set up, once a process, and every reader shares it. The first load downloads it from Hugging Face, which holds the pipeline's start, so download it ahead, such as when building the image. A model that cannot be loaded is reported as an error that leaves the reader unusable, and transcriptions pass through unread.

Turn expressive conversation on with pipeline.Params.EnableExpressiveConversation for the LLM to read the turns:

pipeline.New(transport.Input(), stt, toneReader, userAggregator, llm, ...)

func New

func New(cfg Config) (*Reader, error)

New builds a Reader. It fails on a configuration it cannot use.

func (*Reader) ProcessFrame

func (r *Reader) ProcessFrame(ctx context.Context, f frames.Frame, dir processor.Direction) error

ProcessFrame reads final transcriptions, and keeps the bot's replies to read them against.

func (*Reader) Setup

func (r *Reader) Setup(ctx context.Context, s processor.Setup) error

Setup sets the processor up and loads its model.

type SarcasmTag

type SarcasmTag struct {
	Sarcastic bool
	// Probability is the calibrated chance it is sarcastic.
	Probability float64
}

SarcasmTag is whether the turn is sarcastic.

type Tags

type Tags struct {
	Emotion     EmotionTag
	Move        MoveTag
	Sarcasm     SarcasmTag
	Backchannel BackchannelTag
}

Tags is what the model reads of one turn.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL