voiceagent

package
v0.81.12 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 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 voiceagent provides an embeddable Voice Agent service.

Voice Agent is the realtime audio-to-audio mode: a duplex WebSocket session with the underlying live model (for example OpenAI Realtime, or a pipeline fallback) where the user and the agent take audio turns in sequence. Use this when the host needs brainstorming, support, or follow-up dialogue rather than a one-shot result.

For tool registration, lifecycle hooks, and session memory, build on top of this with github.com/kombifyio/SpeechKit/pkg/speechkit/agentkit.

Construct an instance with NewService, passing a provider and the strict- mode policy fields from the host config.

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

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingProvider = errors.New("speechkit voiceagent: provider is required")

ErrMissingProvider is returned by NewService when Options.Provider is nil, and by every Service method called on a nil receiver or on a Service without a provider.

Functions

This section is empty.

Types

type Callbacks

type Callbacks struct {
	// OnAudio receives a chunk of agent audio to play back; SpeechKit
	// providers deliver 24 kHz 16-bit little-endian mono PCM.
	OnAudio func([]byte)
	// OnText receives agent text (an answer or output transcript) to display.
	OnText func(string)
	// OnError receives session errors, including the failure that ends a
	// session.
	OnError func(error)
	// OnTurnError receives safe guidance for a failed turn. The session remains
	// available for another turn; this is separate from a terminal OnError.
	OnTurnError func(error)
}

Callbacks are the host handlers a Provider invokes during a session. Every field is optional; nil handlers are skipped. Providers may call them from a background goroutine, so handlers must return quickly and guard their own state.

type Config

type Config struct {
	// ProviderProfileID is the public realtime profile to run, for example
	// "realtime.openai.gpt-realtime-2".
	ProviderProfileID string
	// Model is the provider-specific realtime model id.
	Model string
	// Locale is the BCP-47 dialogue locale, for example "de-DE".
	Locale string
	// Instruction is the system prompt the agent follows.
	Instruction string
}

Config carries the per-session settings a Service hands to its Provider on Start. Empty fields keep the provider's own configuration.

type Options

type Options struct {
	Config    Config
	Callbacks Callbacks
	Provider  Provider
}

Options are the inputs to NewService. Provider is required; Config and Callbacks are forwarded unchanged on every Start.

type Provider

type Provider interface {
	// StartVoiceAgent opens a session configured by the given Config and
	// reports events through the Callbacks until the session ends.
	StartVoiceAgent(context.Context, Config, Callbacks) error
	// StopVoiceAgent ends the session and returns its record.
	StopVoiceAgent(context.Context) (speechkit.VoiceAgentSession, error)
	// SendText injects a user text turn into the running session.
	SendText(context.Context, string) error
	// CurrentSession returns a snapshot of the running or most recent
	// session.
	CurrentSession(context.Context) (speechkit.VoiceAgentSession, error)
}

Provider is the backend a Service delegates to. SpeechKit's in-process implementation lives in the voiceagent/local subpackage; hosts may supply their own.

type Service

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

Service implements speechkit.VoiceAgentService by delegating to a Provider with a fixed Config and Callbacks. It keeps no session state of its own, and a nil *Service is safe to call: every method then reports ErrMissingProvider.

func NewService

func NewService(opts Options) (*Service, error)

NewService builds a Service from opts. It returns ErrMissingProvider when opts.Provider is nil.

func (*Service) CurrentSession

func (s *Service) CurrentSession(ctx context.Context) (speechkit.VoiceAgentSession, error)

CurrentSession returns the provider's snapshot of the running or most recent session.

func (*Service) SendText

func (s *Service) SendText(ctx context.Context, text string) error

SendText injects text as a user turn into the running session.

func (*Service) Start

func (s *Service) Start(ctx context.Context) error

Start opens a Voice Agent session through the provider with the configured Config and Callbacks.

func (*Service) Stop

Stop ends the current session and returns its speechkit.VoiceAgentSession record.

Directories

Path Synopsis
Package cascaded implements a turn-based STT -> LLM -> TTS voice agent provider.
Package cascaded implements a turn-based STT -> LLM -> TTS voice agent provider.
Package live exposes the low-level Voice Agent realtime-protocol types.
Package live exposes the low-level Voice Agent realtime-protocol types.

Jump to

Keyboard shortcuts

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