voiceagent

package
v0.76.8 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 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

Examples

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.

Example

ExampleNewService wraps a Provider in the embeddable Voice Agent Service: Start opens a session, SendText injects a user turn, agent output arrives through Callbacks, and Stop returns the session record.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/kombifyio/SpeechKit/pkg/speechkit"
	"github.com/kombifyio/SpeechKit/pkg/speechkit/voiceagent"
)

// echoProvider is a minimal in-memory voiceagent.Provider. Real hosts use
// voiceagent/local (in-process realtime providers) or their own backend.
type echoProvider struct {
	cb      voiceagent.Callbacks
	session speechkit.VoiceAgentSession
}

func (p *echoProvider) StartVoiceAgent(_ context.Context, cfg voiceagent.Config, cb voiceagent.Callbacks) error {
	p.cb = cb
	p.session.Locale = cfg.Locale
	return nil
}

func (p *echoProvider) SendText(_ context.Context, text string) error {
	p.cb.OnText("you said: " + text)
	return nil
}

func (p *echoProvider) StopVoiceAgent(context.Context) (speechkit.VoiceAgentSession, error) {
	return p.session, nil
}

func (p *echoProvider) CurrentSession(context.Context) (speechkit.VoiceAgentSession, error) {
	return p.session, nil
}

// ExampleNewService wraps a Provider in the embeddable Voice Agent Service:
// Start opens a session, SendText injects a user turn, agent output arrives
// through Callbacks, and Stop returns the session record.
func main() {
	svc, err := voiceagent.NewService(voiceagent.Options{
		Config:    voiceagent.Config{Locale: "en-US", Instruction: "Be brief."},
		Callbacks: voiceagent.Callbacks{OnText: func(s string) { fmt.Println("agent:", s) }},
		Provider:  &echoProvider{},
	})
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	if err := svc.Start(ctx); err != nil {
		log.Fatal(err)
	}
	if err := svc.SendText(ctx, "hello"); err != nil {
		log.Fatal(err)
	}
	session, err := svc.Stop(ctx)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("locale:", session.Locale)
}
Output:
agent: you said: hello
locale: en-US

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 a2a adapts a registered A2A agent to SpeechKit's cascaded voice pipeline.
Package a2a adapts a registered A2A agent to SpeechKit's cascaded voice pipeline.
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.
allproviders
Package allproviders is the batteries-included realtime Voice Agent assembly layer: it knows every provider SpeechKit ships and resolves a provider id, alias or profile id to a live provider.
Package allproviders is the batteries-included realtime Voice Agent assembly layer: it knows every provider SpeechKit ships and resolves a provider id, alias or profile id to a live provider.
assemblyai
Package assemblyai adapts the AssemblyAI Voice Agent WebSocket API (wss://agents.assemblyai.com/v1/ws) to live.LiveProvider.
Package assemblyai adapts the AssemblyAI Voice Agent WebSocket API (wss://agents.assemblyai.com/v1/ws) to live.LiveProvider.
deepgram
Package deepgram adapts the Deepgram Voice Agent API (wss://agent.deepgram.com/v1/agent/converse) to live.LiveProvider: one WebSocket carries listen (Flux or Nova STT), think (a Deepgram-managed or bring-your-own LLM) and speak (Aura-2 or Flux TTS).
Package deepgram adapts the Deepgram Voice Agent API (wss://agent.deepgram.com/v1/agent/converse) to live.LiveProvider: one WebSocket carries listen (Flux or Nova STT), think (a Deepgram-managed or bring-your-own LLM) and speak (Aura-2 or Flux TTS).
foundry
Package foundry adapts the OpenAI Realtime provider to Microsoft Foundry.
Package foundry adapts the OpenAI Realtime provider to Microsoft Foundry.
gemini
Package gemini adapts the Google Gemini Live API (via the google.golang.org/genai SDK) to live.LiveProvider.
Package gemini adapts the Google Gemini Live API (via the google.golang.org/genai SDK) to live.LiveProvider.
livecontract
Package livecontract provides reusable conformance checks for LiveProvider implementations.
Package livecontract provides reusable conformance checks for LiveProvider implementations.
openai
Package openai adapts the OpenAI Realtime WebSocket API (wss://api.openai.com/v1/realtime, GA session shape) to live.LiveProvider.
Package openai adapts the OpenAI Realtime WebSocket API (wss://api.openai.com/v1/realtime, GA session shape) to live.LiveProvider.
openailive
Package openailive adapts OpenAI's full-duplex Live API (model gpt-live-1, WebSocket wss://api.openai.com/v1/live/sessions) to live.LiveProvider.
Package openailive adapts OpenAI's full-duplex Live API (model gpt-live-1, WebSocket wss://api.openai.com/v1/live/sessions) to live.LiveProvider.
voicelive
Package voicelive adapts the OpenAI Realtime provider to Microsoft Foundry's Voice Live API.
Package voicelive adapts the OpenAI Realtime provider to Microsoft Foundry's Voice Live API.
xai
Package xai adapts xAI's Grok Voice Agent API (speech-to-speech over wss://api.x.ai/v1/realtime?model=grok-voice-3.0) to live.LiveProvider.
Package xai adapts xAI's Grok Voice Agent API (speech-to-speech over wss://api.x.ai/v1/realtime?model=grok-voice-3.0) to live.LiveProvider.
Package local implements voiceagent.Provider on top of an in-process live session — realtime voice agents (Deepgram Voice Agent, Gemini Live, OpenAI Realtime, AssemblyAI, cascaded) without a speechkit-server.
Package local implements voiceagent.Provider on top of an in-process live session — realtime voice agents (Deepgram Voice Agent, Gemini Live, OpenAI Realtime, AssemblyAI, cascaded) without a speechkit-server.
Package responses adapts one explicitly selected own endpoint to SpeechKit's existing cascaded/native conversation pipeline.
Package responses adapts one explicitly selected own endpoint to SpeechKit's existing cascaded/native conversation pipeline.

Jump to

Keyboard shortcuts

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