reader

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: BSD-2-Clause Imports: 5 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. The classifier/tone package answers with it; this one reads each turn with that classifier.

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 tone.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 tone.FP16.
	Precision tone.Precision
	// Threads is the CPU threads for one read. Zero is 4.
	Threads int
	// CacheDir is where a downloaded model is kept. Empty is Hugging Face's own
	// cache, ~/.cache/huggingface/hub.
	CacheDir string
	// Timeout is how long a transcription waits for its reading. Nil is
	// perception.DefaultTextTimeout, 0.5 s.
	Timeout *time.Duration
	// ReplacePerception makes the reading replace the one a transcription
	// carries, such as the STT service's, instead of being added to it.
	ReplacePerception bool
}

Config configures a tone reader. The zero value downloads the default release at FP16, reads with four threads and waits 0.5 s for a reading.

type Reader

type Reader = perception.Reader

Reader reads how each user turn was meant: a perception.Reader whose one source is a ToneSource.

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 added to 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, up to Config.Timeout.

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 tone reader. It fails on a configuration it cannot use.

type SourceConfig added in v0.5.0

type SourceConfig struct {
	// Revision is the model's release on Hugging Face, such as "reader-rc2".
	// Empty is tone.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 tone.FP16.
	Precision tone.Precision
	// Threads is the CPU threads for one read. Zero is 4.
	Threads int
	// CacheDir is where a downloaded model is kept. Empty is Hugging Face's own
	// cache, ~/.cache/huggingface/hub.
	CacheDir string
	// Timeout is how long a transcription waits for its reading. Nil is
	// perception.DefaultTextTimeout, 0.5 s.
	Timeout *time.Duration
}

SourceConfig configures a ToneSource. The zero value downloads the default release at FP16, reads with four threads and waits 0.5 s for a reading.

type ToneSource added in v0.5.0

type ToneSource struct {
	*perception.BaseSource
	// contains filtered or unexported fields
}

ToneSource is the tone classifier as one of a perception.Reader's sources.

It reads each final transcription, with the bot's reply before it, and reports the turn's "emotion", its two likeliest labels with their confidences, and its "sarcasm", the chance it is sarcastic. Give it to a reader beside the sources of other classifiers, such as one that hears the user's audio. Another source's signal needs a name other than these two.

toneSource, err := reader.NewSource(reader.SourceConfig{})
r, err := perception.New(perception.Config{Sources: []perception.Source{toneSource, hearing}})

func NewSource added in v0.5.0

func NewSource(cfg SourceConfig) (*ToneSource, error)

NewSource builds a ToneSource. It fails on a configuration it cannot use.

func (*ToneSource) Names added in v0.5.0

func (s *ToneSource) Names() []string

Names is the tone classifier's signals, "emotion" and "sarcasm", named before the model loads.

func (*ToneSource) Questions added in v0.5.0

func (s *ToneSource) Questions() ([]perception.NamedQuestion, error)

Questions is the tone classifier's emotion and sarcasm questions, with the loaded model's options. It fails, with an error wrapping classifier.ErrClassifier, before the model is loaded.

Jump to

Keyboard shortcuts

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