v1

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 6 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 v1 defines the stable OpenRealtime component API.

Experimental engine internals may change independently. Breaking changes to this package require a new semantic import path such as api/v2.

Index

Constants

View Source
const Version = "1.0.0"

Variables

View Source
var ErrNilConsumer = errors.New("stream consumer must not be nil")

Functions

func CarriesSpeech

func CarriesSpeech(text string) bool

CarriesSpeech reports whether text contains anything a person said.

Types

type AudioFrame

type AudioFrame struct {
	Index        uint64 `json:"index"`
	SampleOffset uint64 `json:"sample_offset"`
	SampleRateHz uint32 `json:"sample_rate_hz"`
	PCM16LE      []byte `json:"pcm16le"`
}

func (AudioFrame) EndSample

func (frame AudioFrame) EndSample() (uint64, error)

func (AudioFrame) Validate

func (frame AudioFrame) Validate() error

type Capabilities

type Capabilities map[Capability]bool

func (Capabilities) Has

func (capabilities Capabilities) Has(capability Capability) bool

type Capability

type Capability string
const (
	CapabilityStreamingInput  Capability = "streaming_input"
	CapabilityRevisions       Capability = "revisions"
	CapabilityCancellation    Capability = "cancellation"
	CapabilityDeterministic   Capability = "deterministic"
	CapabilityPCM16Output     Capability = "pcm16_output"
	CapabilityStreamingOutput Capability = "streaming_output"
)

type CognitionProvider

type CognitionProvider interface {
	Descriptor() Descriptor
	Respond(context.Context, PerceptionRevision) (ResponseCandidate, error)
}

type DeliberationProvider

type DeliberationProvider interface {
	Descriptor() Descriptor
	Deliberate(context.Context, GoalSnapshot, func(DeliberationUpdate) error) error
}

type DeliberationStatus

type DeliberationStatus string
const (
	DeliberationProgress DeliberationStatus = "progress"
	DeliberationFinal    DeliberationStatus = "final"
	DeliberationFailed   DeliberationStatus = "failed"
)

type DeliberationUpdate

type DeliberationUpdate struct {
	GoalID       string             `json:"goal_id"`
	RevisionID   uint64             `json:"revision_id"`
	Sequence     uint64             `json:"sequence"`
	Status       DeliberationStatus `json:"status"`
	Text         string             `json:"text"`
	Error        string             `json:"error"`
	ComputeUnits uint64             `json:"compute_units"`
	QualityScore uint32             `json:"quality_score"`
}

func (DeliberationUpdate) ValidateFor

func (update DeliberationUpdate) ValidateFor(goal GoalSnapshot) error

type Descriptor

type Descriptor struct {
	Name         string       `json:"name"`
	Version      string       `json:"version"`
	Capabilities Capabilities `json:"capabilities"`
}

func (Descriptor) Validate

func (descriptor Descriptor) Validate() error

type FastAction

type FastAction string
const (
	FastListen      FastAction = "listen"
	FastAcknowledge FastAction = "acknowledge"
	FastAnswer      FastAction = "answer"
	FastDefer       FastAction = "defer"
	FastYield       FastAction = "yield"
)

type FastDecision

type FastDecision struct {
	GoalID        string        `json:"goal_id"`
	RevisionID    uint64        `json:"revision_id"`
	Action        FastAction    `json:"action"`
	Text          string        `json:"text"`
	ProgressClaim ProgressClaim `json:"progress_claim"`
	StartSlowPath bool          `json:"start_slow_path"`
}

func (FastDecision) ValidateFor

func (decision FastDecision) ValidateFor(goal GoalSnapshot) error

type FastDecisionProvider

type FastDecisionProvider interface {
	Descriptor() Descriptor
	Decide(context.Context, GoalSnapshot) (FastDecision, error)
}

type GoalSnapshot

type GoalSnapshot struct {
	GoalID     string `json:"goal_id"`
	RevisionID uint64 `json:"revision_id"`
	Question   string `json:"question"`
	CreatedNS  uint64 `json:"created_ns"`
	DeadlineNS uint64 `json:"deadline_ns"`
}

func (GoalSnapshot) Validate

func (goal GoalSnapshot) Validate() error

type PerceptionProvider

type PerceptionProvider interface {
	Descriptor() Descriptor
	PushFrame(context.Context, AudioFrame) ([]PerceptionRevision, error)
	Finalize(context.Context, uint64) (PerceptionRevision, error)
}

type PerceptionRevision

type PerceptionRevision struct {
	RevisionID   uint64 `json:"revision_id"`
	SourceSample uint64 `json:"source_sample"`
	// Source optionally names who or what produced the speech. Most ASR
	// providers leave it empty because a single microphone does not identify a
	// speaker. A deployment-owned attribution layer may populate it without
	// changing the transcript or its user authority.
	Source       string `json:"source,omitempty"`
	StableText   string `json:"stable_text"`
	UnstableText string `json:"unstable_text"`
	Delta        string `json:"delta"`
	Final        bool   `json:"final"`
}

PerceptionRevision is what a recogniser heard, so far.

A revision may report that it heard nothing, and reporting nothing is a result rather than an absence of one: a recogniser asked about audio with no words in it has done its job when it says so. There is no field for it because there is no answer every recogniser could give - most cannot distinguish silence from an unintelligible sound - so the report is carried in the text, and CarriesSpeech is how it is read.

The distinction matters more than it sounds. An observation built from a revision is a claim that the user said something, and the log keeps it forever: room tone admitted as a turn gets answered, the answer cancels whatever the agent was already saying, and a caller hears their own reply cut off to make room for nothing.

func (PerceptionRevision) CarriesSpeech

func (revision PerceptionRevision) CarriesSpeech() bool

CarriesSpeech reports whether a transcript contains anything a person said.

It lives here rather than in a consumer because it is part of the contract: every adapter reports "no words" the same way, and every consumer has to read it the same way, or one of them turns punctuation into a turn.

The test is a letter or a digit anywhere in the text. Recognisers answer the empty case differently - SenseVoice returns ".", others return whatever punctuation their language model expects around nothing - and asking Unicode rather than stripping a list of characters somebody once noticed is what makes it hold in scripts nobody tested against.

type ProgressClaim

type ProgressClaim string
const (
	ProgressNone      ProgressClaim = "none"
	ProgressWorking   ProgressClaim = "working"
	ProgressCompleted ProgressClaim = "completed"
)

type ProviderSet

type ProviderSet struct {
	Perception   PerceptionProvider
	Cognition    CognitionProvider
	Speech       SpeechProvider
	Fast         FastDecisionProvider
	Deliberation DeliberationProvider
}

type ResponseCandidate

type ResponseCandidate struct {
	CandidateID     string `json:"candidate_id"`
	SourceRevision  uint64 `json:"source_revision"`
	Text            string `json:"text"`
	Semantic        bool   `json:"semantic"`
	ValiditySummary string `json:"validity_summary"`
}

type SpeechChunk

type SpeechChunk struct {
	ChunkID      string `json:"chunk_id"`
	CandidateID  string `json:"candidate_id"`
	SampleOffset uint64 `json:"sample_offset"`
	SampleRateHz uint32 `json:"sample_rate_hz"`
	PCM16LE      []byte `json:"pcm16le"`
	Final        bool   `json:"final"`
}

func (SpeechChunk) DurationNS

func (chunk SpeechChunk) DurationNS() (uint64, error)

func (SpeechChunk) EndSample

func (chunk SpeechChunk) EndSample() (uint64, error)

func (SpeechChunk) Validate

func (chunk SpeechChunk) Validate() error

type SpeechPlan

type SpeechPlan struct {
	CandidateID string `json:"candidate_id"`
	Text        string `json:"text"`
}

func (SpeechPlan) Validate

func (plan SpeechPlan) Validate() error

type SpeechProvider

type SpeechProvider interface {
	Descriptor() Descriptor
	Synthesize(context.Context, SpeechPlan) ([]SpeechChunk, error)
}

type StreamingSpeechProvider

type StreamingSpeechProvider interface {
	SpeechProvider
	Stream(context.Context, SpeechPlan, func(SpeechChunk) error) error
}

type UtteranceReusable added in v0.2.0

type UtteranceReusable interface {
	EndUtterance() error
}

UtteranceReusable is a perception provider that keeps its connection across utterances. A provider that is one utterance is dropped after Finalize; a provider that is one session's stream is asked to end the utterance instead and handed the next one, so a persistent recogniser is not dialled again at every sentence. EndUtterance must leave the provider ready for a fresh first frame whether or not Finalize ran. Close, where implemented, remains the end of the session.

Jump to

Keyboard shortcuts

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