companion

package
v0.77.7 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 1 package

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 companion provides small composers for hands-free SpeechKit hosts.

Stability: Stable — no breaking change without a minor version bump and a changelog callout.

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingAssist = errors.New("speechkit companion: assist service is required")

ErrMissingAssist is returned when an Assist turn is requested but no Options.Assist service was configured.

View Source
var ErrMissingContext = errors.New("speechkit companion: context is required")

ErrMissingContext is returned by HandsFree.HandleWake and HandsFree.ProcessAssist when ctx is nil.

View Source
var ErrMissingRuntime = errors.New("speechkit companion: runtime is required")

ErrMissingRuntime is returned by NewHandsFree when Options.Runtime is nil, and by HandsFree methods called on a nil or runtime-less receiver.

Functions

This section is empty.

Types

type HandsFree

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

HandsFree composes wake-word activation with the strict SpeechKit modes on top of a shared speechkit.Runtime. It publishes lifecycle events on the runtime and reports Stage transitions to the host, but owns neither audio playback nor UI. Build it with NewHandsFree; every method tolerates a nil receiver.

func NewHandsFree

func NewHandsFree(opts Options) (*HandsFree, error)

NewHandsFree builds a HandsFree from opts. It returns ErrMissingRuntime when opts.Runtime is nil. A non-empty opts.TargetMode is normalized through the same aliases accepted for wake-event modes (for example "dictate" or "voice-agent"); unrecognized values fall back to TargetAssist.

func (*HandsFree) Assist

func (h *HandsFree) Assist() speechkit.AssistService

Assist returns the configured speechkit.AssistService, or nil when none was set.

func (*HandsFree) Events

func (h *HandsFree) Events() <-chan speechkit.Event

Events returns the runtime's event channel (see speechkit.Runtime.Events), or nil when the composer has no runtime.

func (*HandsFree) HandleWake

func (h *HandsFree) HandleWake(ctx context.Context, ev wakeword.DetectionEvent) error

HandleWake publishes a wake event, forwards it to the optional downstream sink, and starts the configured hands-free target. Assist and Voice Agent can run without a visible UI; Dictation is UI-assisted and dispatches into the host command bus so the host can choose the text target and commit surface.

func (*HandsFree) ProcessAssist

ProcessAssist runs a one-shot Assist request through the configured service and, when TTS is present, synthesizes the spoken response.

func (*HandsFree) Runtime

func (h *HandsFree) Runtime() *speechkit.Runtime

Runtime returns the shared speechkit.Runtime the composer publishes on, or nil for a nil receiver.

func (*HandsFree) Start

func (h *HandsFree) Start(ctx context.Context) error

Start publishes speechkit.EventCompanionSessionStarted and then starts the underlying runtime. It returns ErrMissingRuntime when no runtime is bound.

func (*HandsFree) Stop

func (h *HandsFree) Stop(ctx context.Context) error

Stop stops the underlying runtime, publishes speechkit.EventCompanionSessionEnded even when stopping failed, and returns the runtime's error. It returns ErrMissingRuntime when no runtime is bound.

func (*HandsFree) TTS

func (h *HandsFree) TTS() *tts.Service

TTS returns the configured tts.Service, or nil when none was set.

func (*HandsFree) VoiceAgent

func (h *HandsFree) VoiceAgent() speechkit.VoiceAgentService

VoiceAgent returns the configured speechkit.VoiceAgentService, or nil when none was set.

func (*HandsFree) WakeSink

func (h *HandsFree) WakeSink() wakeword.Sink

WakeSink adapts the composer to a wakeword.Sink so a wake-word pipeline can drive it directly. Each detection runs HandsFree.HandleWake with a background context; failures are published as speechkit.EventErrorRaised rather than returned. It returns nil for a nil receiver.

type HandsFreeTarget added in v0.40.7

type HandsFreeTarget string

HandsFreeTarget identifies which strict SpeechKit mode a hands-free activation should start. Hands-free is a capability layer, not a fourth SpeechKit mode.

const (
	// TargetAssist runs a one-shot Assist request and may synthesize spoken
	// output. This is the Siri/Alexa-style Voice-Companion path.
	TargetAssist HandsFreeTarget = "assist"
	// TargetVoiceAgent starts a realtime Voice Agent session for continuous
	// dialogue such as companion or game-moderator flows.
	TargetVoiceAgent HandsFreeTarget = "voice_agent"
	// TargetDictationUIAssisted starts Dictation through the host command bus.
	// It intentionally does not synthesize audio: text output still belongs to
	// a visible target or explicit commit surface owned by the host UI.
	TargetDictationUIAssisted HandsFreeTarget = "dictation_ui_assisted"
)

type Options

type Options struct {
	Runtime     *speechkit.Runtime
	TargetMode  HandsFreeTarget
	WakeSink    wakeword.Sink
	WakeRequest WakeRequestFunc
	Assist      speechkit.AssistService
	VoiceAgent  speechkit.VoiceAgentService
	TTS         *tts.Service
	// OnResult, when set, receives the AssistResult (including any synthesized
	// Audio) produced by a wake-triggered Assist turn, so the host can play it
	// back. It runs synchronously inside HandleWake after ProcessAssist
	// succeeds; hosts that want async playback should spawn their own goroutine.
	OnResult func(context.Context, speechkit.AssistResult)
	// OnStage, when set, receives turn-lifecycle stages so hosts can drive a
	// status UI (e.g. an LED ring on a satellite) from the canonical flow instead of
	// scraping logs or events. Called synchronously — keep handlers fast.
	OnStage func(Stage)
}

Options configures a HandsFree composer. Runtime is required. TargetMode, when set, overrides the mode carried by each wake event. WakeSink, when set, receives every detection after the wake event is published. WakeRequest turns a detection into the Assist request; without it a wake never starts an Assist turn. Assist, VoiceAgent, and TTS are the services the respective targets use; TTS is optional and only synthesizes when the result has SpeakText but no Audio.

type Stage added in v0.50.0

type Stage string

Stage identifies a coarse phase of a hands-free turn. Stages are a UI vocabulary (status ring, tray icon, LED), deliberately smaller than the runtime event stream: one linear wake → listening → thinking → speaking → idle sequence per Assist turn, with error as the terminal failure stage.

const (
	// StageWake follows the published wake event, before dispatch.
	StageWake Stage = "wake"
	// StageListening marks the host capturing the utterance through
	// [Options.WakeRequest].
	StageListening Stage = "listening"
	// StageThinking marks the Assist request being processed.
	StageThinking Stage = "thinking"
	// StageSpeaking is reported only when the result carries audio or
	// SpeakText for the host to play.
	StageSpeaking Stage = "speaking"
	// StageIdle ends a turn, including one whose capture was aborted.
	StageIdle Stage = "idle"
	// StageError is terminal: the Assist service is missing or failed.
	StageError Stage = "error"
)

Stage values reported to Options.OnStage. A hands-free Assist turn emits them in the order listed, ending in StageIdle or StageError; the Voice Agent and Dictation targets report only StageWake.

type WakeRequestFunc

WakeRequestFunc converts a wake detection into an Assist request. Hosts use it to attach their transcript/capture result to the framework composer.

Jump to

Keyboard shortcuts

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