tagger

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: 30 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 tagger writes expression tags into an LLM's plain replies, one sentence at a time, with the tone tagger model (alpha).

The model (https://huggingface.co/pipecat-ai/tone-models) labels each sentence of a reply as it streams in: a delivery, slow spans for details, stressed words, a sound before or after and, with expressive.GuidanceBreathe, a breath before it, drawn as a light breath, a deep breath or an exhale. It reads the call so far and how the user sounded, and runs on the CPU in about 15 milliseconds a sentence, through the ONNX runtime. The labels are expressive.CoreDelivery, expressive.CoreSounds and the kinds of breath it draws (BreathKinds), written as tags in the names the TTS service performs them by.

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 tagger's release the tagger downloads by default.
	Revision = "tagger-rc1"
)
View Source
const OtherService = "other"

OtherService is the service the model reads for one it was not trained with.

Variables

View Source
var ErrVocabulary = errors.New("tagger: vocabulary")

ErrVocabulary is returned for a vocabulary that names a label the tagger does not write, or names one twice.

Functions

func BreathKinds

func BreathKinds() []expressive.ExpressionSound

BreathKinds is the kinds the tagger draws a breath as, each a universal sound.

Types

type BreathKind

type BreathKind struct {
	Kind  string
	Share float64
}

BreathKind is a kind a breath is drawn as, with its share.

type Config

type Config struct {
	// Name is the processor's name. Empty is "ToneTagger".
	Name string
	// Size is the model's size: Size17M, or Size32M, which agrees with its
	// teacher a little more often and takes nearly three times as long a
	// sentence. Empty is Size17M.
	Size Size `validate:"omitempty,oneof=17m 32m"`
	// Revision is the model's release on Hugging Face, such as "tagger-rc1".
	// Empty is Revision.
	Revision string
	// ModelDir is a folder to load the model from instead of downloading one,
	// laid out as a release's "tagger/17m", such as for a model you trained or
	// keep yourself. Size and Revision are then unused.
	ModelDir string
	// Threads is the CPU threads for one sentence. Zero is 1.
	Threads int `validate:"min=0"`
	// Vocabulary is the names to write first for a delivery, sound or kind of
	// breath (expressive.CoreDelivery, expressive.CoreSounds, BreathKinds),
	// best first, such as {expressive.DeliveryWarm: {"cheerful"}}. A name is
	// written only where the TTS service performs it and the policy offers it;
	// elsewhere the label's universal name stands. A name written for
	// expressive.SoundBreath is written for every breath, rather than its
	// kinds' names. New refuses a label the tagger does not write.
	Vocabulary map[expressive.UniversalName][]string
	// CacheDir is where a downloaded model is kept. Empty is Hugging Face's own
	// cache, ~/.cache/huggingface/hub.
	CacheDir string
}

Config configures a Tagger. The zero value downloads the default release's 17m model and tags with one thread.

type LabelName

type LabelName struct {
	Label string
	Name  string
}

LabelName is a label with the name to write it as.

type LabelSpace

type LabelSpace struct {
	// Deliveries is each delivery label with the name to write, in
	// expressive.CoreDelivery order.
	Deliveries Names
	// Sounds is each sound label with the name to write, in
	// expressive.CoreSounds order.
	Sounds Names
	// Emphasis is whether the service stresses ^^words^^.
	Emphasis bool
	// TTS is the service, by the name the model was trained to read for it.
	// Empty is OtherService.
	TTS string
	// Breaths is each kind of breath with the name to write, in BreathKinds
	// order, where a breath is offered. The model chooses only a breath, and
	// the tagger draws its kind.
	Breaths Names
}

LabelSpace is the labels a call can use, each with the name to write it as.

func ResolveLabelSpace

func ResolveLabelSpace(
	capabilities *expressive.ExpressionCapabilities,
	policy expressive.ExpressionPolicy,
	serviceName string,
	vocabulary map[string][]string,
) LabelSpace

ResolveLabelSpace is the labels the service performs and the policy offers.

A label is written as the first of the developer's names for it, then its own, that the service performs and the policy offers. A breath, and its kinds, are offered only with expressive.GuidanceBreathe in the policy. A breath is offered where the service performs only some of its kinds, written as the first of them for a model that draws no kinds.

serviceName is the service's name, such as "ElevenLabsTTS#0", which says which of the services the model was trained with it is. A service given a name of its own, such as "tts", is read as one the model was not trained with. vocabulary is the names to try first for a label, before its own, by the label.

func (LabelSpace) SoundName

func (s LabelSpace) SoundName(label string) string

SoundName is the name to write for a sound or a kind of breath, or empty if the space holds neither.

type Message

type Message struct {
	// Role is "user" or "assistant".
	Role string
	// Text is the words.
	Text string
	// Heard is how the user sounded, folded into the model's tones, or nil.
	Heard []expressive.PerceptionSignal
	// Speculation is whether it is the turn an early reply answers, not yet
	// confirmed.
	Speculation bool
}

Message is a turn of the call, as plain words.

type Model

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

Model is the tagger's model, on the CPU. One model can serve every call.

func DownloadModel

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

DownloadModel loads the model of a size from a release on Hugging Face, downloading the files of its folder, "tagger/<size>", into cacheDir the first time. An empty cacheDir is Hugging Face's own cache.

The folder holds config.json, tokenizer.json and the ONNX file config.json names, so config.json is fetched first.

func LoadModel

func LoadModel(dir string, 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 sentence.

func (*Model) BreathKinds

func (m *Model) BreathKinds() []BreathKind

BreathKinds is the kinds a breath is drawn as, with their shares, in order; empty for a plain breath.

func (*Model) BreathsPerReply

func (m *Model) BreathsPerReply() (int, bool)

BreathsPerReply is the most breaths a reply takes, and false for no limit.

func (*Model) Tag

func (m *Model) Tag(turn TurnContext, earlier []string, sentence string) (SentenceLabels, error)

Tag labels one sentence of a reply, from the labels the turn's space holds. earlier is the reply's earlier sentences and sentence the sentence, each without tags.

type Names

type Names []LabelName

Names is labels with the names to write them as, in order.

func (Names) Has

func (n Names) Has(label string) bool

Has reports whether the names hold label.

func (Names) Labels

func (n Names) Labels() []string

Labels is the labels, in order.

func (Names) Name

func (n Names) Name(label string) (string, bool)

Name is the name to write label as, and false when the names hold no label.

type SentenceLabels

type SentenceLabels struct {
	// Delivery is the sentence's delivery, or empty for the voice's baseline.
	Delivery string
	// Spans is words in a delivery of their own, mainly slow details.
	Spans []Span
	// Emphasis is words to stress, as [start, end) code-point offsets.
	Emphasis [][2]int
	// SoundBefore is a sound before the sentence, or empty.
	SoundBefore string
	// SoundAfter is a sound after the sentence, or empty.
	SoundAfter string
}

SentenceLabels is what the tagger chose for one sentence, in its labels; usually nothing.

type Size

type Size string

Size is a size the model is released in.

const (
	// Size17M is the smaller model, the default.
	Size17M Size = "17m"
	// Size32M is the larger model, which agrees with its teacher a little more
	// often and takes nearly three times as long a sentence.
	Size32M Size = "32m"
)

type Span

type Span struct {
	// Start is the offset of the first word's first character.
	Start int
	// End is the offset just past the last word.
	End int
	// Delivery is the words' delivery, a label from expressive.CoreDelivery.
	Delivery string
}

Span is a delivery for some words, <<delivery: words>>, by code-point offsets in the sentence.

type Tagger

type Tagger struct {
	*aggregators.LLMText
	// contains filtered or unexported fields
}

Tagger tags an LLM's plain replies with the tone tagger, a sentence at a time.

It goes between the LLM and the TTS service. Each sentence is labeled with the call so far, how the user sounded and the pipeline's expression policy, and sent on with the tags the TTS service performs. The sentence waits for the labeling, about 15 milliseconds.

The model loads while the pipeline is set up, once a process, and every tagger 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. At start, the tagger broadcasts a frames.ExpressionMetadataFrame, so the LLM is taught no tags and writes plain words, and the context keeps them plain. A model that cannot be loaded is reported as an error that leaves the tagger unusable: the LLM writes the tags itself and replies pass through as written.

The policy's guidance presets steer the tagger, its Delivery and Sounds narrow the names it writes, and a breath is written only with expressive.GuidanceBreathe. The developer's own lines are for the LLM.

Turn expressive conversation on with pipeline.Params.EnableExpressiveConversation. Add a tone reader (processor/tone/reader) for the tagger to hear how the user sounded:

pipeline.New(..., userAggregator, llm, toneTagger, tts, ...)

func New

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

New builds a Tagger. It fails on a configuration it cannot use, and with ErrVocabulary on a vocabulary naming a label the tagger does not write.

func (*Tagger) ProcessFrame

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

ProcessFrame tags the LLM's sentences, and keeps the call and the TTS's names to tag them by.

func (*Tagger) Setup

func (t *Tagger) Setup(ctx context.Context, s processor.Setup) error

Setup sets the processor up with the pipeline's expression policy, and loads its model.

type TurnContext

type TurnContext struct {
	// Messages is the call so far.
	Messages []Message
	// Space is the labels the call can use.
	Space LabelSpace
	// Policy is the pipeline's expression policy.
	Policy expressive.ExpressionPolicy
	// Previous is the labels of the bot's previous reply, or nil before the
	// first. A previous reply with no sentences is empty, not nil.
	Previous []SentenceLabels
}

TurnContext is what the model knows when a reply starts.

func (TurnContext) Heard

Heard is how the user sounded in the turn this reply answers.

Jump to

Keyboard shortcuts

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