voices

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 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 voices tells the person the agent is talking to from another voice in the room.

A cascade hears one microphone, transcribes it, and works in text from there. That discards the one fact separating a question put to the agent from a question put to somebody else standing nearby: whose voice it was. Without it the situation handed to the interaction model says the user asked about the milk, and a model told the user asked about the milk answers about the milk. It is not a failure of judgement; it is a correct answer to a false premise.

So the premise is checked. The first voice of a session is the person the session is with, and every utterance after it is compared against that.

Index

Constants

View Source
const DefaultEnrolment = 2 * time.Second

DefaultEnrolment is how much speech is needed before deciding whose session this is.

It used to be three seconds, on the reasoning that a comparison that goes wrong costs one utterance while a reference that goes wrong is wrong about every utterance after it. The asymmetry is real. The number was measured against segments of one recording, though, which is the easy case: the same speaker in the same breath, in the same acoustic conditions, saying words that follow on. Measured the way it is actually used - a reference built from one utterance, compared against different utterances later in the conversation - it plateaus far earlier:

enrolment   same speaker   another speaker
   1000ms   0.415..0.429      0.093..0.114
   1500ms   0.509..0.563      0.060..0.097
   2000ms   0.571..0.616      0.114..0.168
   3000ms   0.576..0.667      0.091..0.147

Three seconds buys nothing over two. One and a half seconds usually clears the threshold, but a short phrase is still content-dominated: in the live correction scenario, enrolling from "Right. So" scored only 0.359 against a later utterance by the same speaker. Waiting for two seconds moved the same-speaker comparison to 0.531 while the other speaker remained at 0.154.

What three seconds cost is the whole mechanism, because the buffer is per utterance and nobody speaks in three-second sentences on purpose. A person who opened with "I'm just going to get on with this for a bit" - 2.09 seconds - never enrolled at all, and the failure is not that identification degrades. It is that the prior takes over: with no reference, whoever is talking is the person whose session this is. So the stranger who asked somebody else about the milk was read as the user, twice, and the agent answered a question that was not addressed to it in every run.

Failing to enrol is worse than waiting indefinitely, but two seconds is reached by the next substantive utterance in that conversation and gives a stable reference instead of permanently enrolling from a filler phrase.

View Source
const DefaultMinimum = 1500 * time.Millisecond

DefaultMinimum is how much speech is needed before asking who is talking.

Under a second and a half the embedding is dominated by whatever phonemes happened to be in it, and a wrong answer here is worse than no answer: no answer leaves the prior in place, and a wrong one tells the agent the person it is talking to is a stranger.

A second was an estimate of where that stops being true, and measurement put it exactly on the line. One voice against itself, and against another, at the threshold above:

window   same voice   another voice
 300ms        0.219           0.145
 500ms        0.321           0.177
 750ms        0.301           0.243
1000ms        0.430           0.219
1500ms        0.584           0.202
3000ms        0.722           0.246

At a second the same speaker scores 0.430 against a threshold of 0.40, which is a coin toss, and every toss that lands wrong relabels the person mid sentence. Measured in the suite, a speaker telling one uninterrupted story was reported as somebody else in the room 122 times. At a second and a half there is a third of a point of clearance on both sides of the threshold.

The cost of waiting is that a genuine second speaker is recognised half a second later, which is affordable: somebody else in the room talks for seconds at a time, and until the verdict arrives the prior stands rather than a guess.

View Source
const DefaultThreshold = 0.40

DefaultThreshold is the cosine similarity above which two utterances are the same person.

Two corpora, deliberately, because a threshold read off the benchmark it is then scored on is a property of the benchmark rather than of the embedder.

same speaker, unrelated corpus, whole recordings   0.796 to 0.950
same speaker, unrelated corpus, halves of one      0.571 to 0.782
same speaker, the benchmark's voices               0.60 and 0.77
different speakers, the benchmark's voices         0.15 to 0.17

The first two rows come from audio that has nothing to do with any scenario here, measured by tools/speakerid/calibrate.py, which needs no labels: the two halves of one recording are the same speaker by construction. They put the same-speaker floor at about 0.57 even for segments only a second or two long, which is the hard case. The benchmark supplies the other side.

Nothing observed falls between 0.18 and 0.56. A threshold in the middle of a gap that wide is a reading of a bimodal measurement rather than a tuned constant, and the calibrator is checked in so the reading can be repeated on any corpus - including one that disagrees.

View Source
const FinalAttributionWait = 250 * time.Millisecond

FinalAttributionWait is the maximum extra latency added at a terminal transcript. Partial revisions never wait. Finalization only joins a speaker comparison that Hear already started; it never starts new embedding work.

View Source
const OtherSpeakerSource = "someone else in the room"

OtherSpeakerSource is the canonical source label for a voice that differs from the person who opened the session. It is deliberately human-readable: interaction situations and model context render observation sources as evidence, not as an opaque classifier enum.

Variables

This section is empty.

Functions

This section is empty.

Types

type Embedder

type Embedder interface {
	Embed(ctx context.Context, pcm []byte, rateHz uint32) ([]float32, error)
}

Embedder turns speech into a unit-length vector that depends on the speaker and not much on what they said.

type Evidence

type Evidence struct {
	Verdict        Verdict
	Buffered       time.Duration
	Asked          bool
	Pending        bool
	ReferenceReady bool
	Compared       bool
	Similarity     float64
	Error          string
}

Evidence is the inspectable state behind a speaker verdict. It is intended for opt-in diagnostic traces, not as another policy input: the interaction model should receive the attribution, while operators need enough evidence to tell a model decision from missing or failed speaker perception.

type Provider

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

Provider adds per-utterance speaker attribution to an existing ASR provider. A single Recogniser is shared by all Provider instances in one session so the first utterance can enrol the session's user and later utterances can be compared with it.

func WrapProvider

func WrapProvider(
	session context.Context, inner v1.PerceptionProvider, recogniser *Recogniser, utterance string,
) (*Provider, error)

WrapProvider starts one attribution utterance around an exact ASR provider.

func (*Provider) Close

func (provider *Provider) Close() error

Close releases the wrapped ASR provider when it owns resources.

func (*Provider) Descriptor

func (provider *Provider) Descriptor() v1.Descriptor

func (*Provider) Finalize

func (provider *Provider) Finalize(
	ctx context.Context, sourceSample uint64,
) (v1.PerceptionRevision, error)

func (*Provider) PushFrame

func (provider *Provider) PushFrame(
	ctx context.Context, frame v1.AudioFrame,
) ([]v1.PerceptionRevision, error)

func (*Provider) SpeechEndpointed

func (provider *Provider) SpeechEndpointed() bool

SpeechEndpointed preserves the optional streaming-ASR endpoint contract.

type Recogniser

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

Recogniser watches one session.

func New

func New(embedder Embedder, threshold float64, minimum time.Duration) *Recogniser

New returns a recogniser, or nil when there is nobody to ask. A nil recogniser answers Unknown to everything, which is what a caller with no embedder should see.

func (*Recogniser) Await

func (recogniser *Recogniser) Await(ctx context.Context) Verdict

Await returns the best verdict available after an in-flight comparison has settled or the caller's bound has expired. It never starts a comparison: a short utterance that did not meet the evidence minimum remains Unknown.

Partial transcript decisions stay non-blocking. A final transcript is different: it is the authorization boundary that can open ordinary cognition, and letting it overtake a speaker comparison already in flight turns "unknown for another few milliseconds" into "the user asked this".

func (*Recogniser) Begin

func (recogniser *Recogniser) Begin(utterance string)

Begin starts a new utterance. What was heard of the last one is not evidence about this one.

func (*Recogniser) Evidence

func (recogniser *Recogniser) Evidence() Evidence

Evidence returns one consistent snapshot of speaker recognition state.

func (*Recogniser) Hear

func (recogniser *Recogniser) Hear(ctx context.Context, frames []perception.Frame)

Hear takes the audio admitted for the current utterance.

The embedding is asked for once, as soon as there is enough speech, and off the caller's goroutine: this sits on the path between hearing a word and deciding whether to answer it, and a verdict that arrives a moment late costs nothing while a request that blocks costs every turn.

func (*Recogniser) Verdict

func (recogniser *Recogniser) Verdict() Verdict

Verdict is what is known about the current utterance.

type Verdict

type Verdict string

Verdict is what is known about who is speaking.

const (
	// Unknown covers both "not enough audio yet" and "nobody could be asked".
	// The two are the same to a caller: there is no evidence, so the prior
	// stands, and the prior is that the person talking is the one whose
	// session this is.
	Unknown Verdict = "unknown"
	// Familiar is the voice the session was opened with.
	Familiar Verdict = "familiar"
	// Different is somebody else.
	Different Verdict = "different"
)

Jump to

Keyboard shortcuts

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