voice

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package voice provides voice processing capabilities for omniagent.

Index

Constants

View Source
const DefaultVoiceSystemPrompt = `` /* 636-byte string literal not displayed */

DefaultVoiceSystemPrompt is the default system prompt for voice conversations.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Enabled indicates whether voice processing is enabled.
	Enabled bool
	// ResponseMode controls when to respond with voice: "auto", "always", "never".
	// "auto" responds with voice when the user sends a voice message.
	ResponseMode string
	// STT configures speech-to-text.
	STT STTConfig
	// TTS configures text-to-speech.
	TTS TTSConfig
}

Config configures voice processing.

type Gateway added in v0.10.0

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

Gateway wraps a voice gateway provider with omniagent integration.

func NewGateway added in v0.10.0

func NewGateway(cfg GatewayConfig) (*Gateway, error)

NewGateway creates a new voice gateway integrated with omniagent.

func (*Gateway) GetSession added in v0.10.0

func (g *Gateway) GetSession(callID string) (gateway.Session, bool)

GetSession retrieves an active session.

func (*Gateway) ListSessions added in v0.10.0

func (g *Gateway) ListSessions() []gateway.Session

ListSessions returns all active sessions.

func (*Gateway) MakeCall added in v0.10.0

func (g *Gateway) MakeCall(ctx context.Context, to string) (gateway.Session, error)

MakeCall initiates an outbound call.

func (*Gateway) OnCall added in v0.10.0

func (g *Gateway) OnCall(handler gateway.CallHandler)

OnCall sets the handler for incoming calls.

func (*Gateway) OnSessionEnd added in v0.10.0

func (g *Gateway) OnSessionEnd(handler func(session gateway.Session))

OnSessionEnd sets the callback for when a session ends.

func (*Gateway) OnSessionStart added in v0.10.0

func (g *Gateway) OnSessionStart(handler func(session gateway.Session))

OnSessionStart sets the callback for when a session starts.

func (*Gateway) ProcessWithAgent added in v0.10.0

func (g *Gateway) ProcessWithAgent(ctx context.Context, session gateway.Session, userText string) (string, error)

ProcessWithAgent processes a conversation turn using the omniagent LLM.

func (*Gateway) Start added in v0.10.0

func (g *Gateway) Start(ctx context.Context) error

Start starts the voice gateway.

func (*Gateway) Stop added in v0.10.0

func (g *Gateway) Stop() error

Stop stops the voice gateway.

type GatewayConfig added in v0.10.0

type GatewayConfig struct {
	// Provider selects the telephony provider ("twilio" or "telnyx").
	Provider string

	// Twilio configuration
	TwilioAccountSID string
	TwilioAuthToken  string
	TwilioPhone      string

	// Telnyx configuration
	TelnyxAPIKey       string
	TelnyxPhone        string
	TelnyxConnectionID string

	// Server configuration
	PublicURL  string
	ListenAddr string
	Listener   net.Listener // Optional external listener (e.g., ngrok)

	// Pipeline mode: "text" (STT→LLM→TTS, ~500-1000ms) or "realtime" (voice-to-voice, ~100-200ms)
	// Default: "text"
	Mode string

	// Voice processing (used when Mode is "text")
	Config Config

	// LLM configuration (used when Mode is "text")
	LLMProvider     string
	LLMModel        string
	LLMSystemPrompt string

	// Realtime configuration (used when Mode is "realtime")
	// RealtimeProvider: "openai" or "gemini"
	RealtimeProvider string
	RealtimeAPIKey   string
	RealtimeModel    string // e.g., "gpt-4o-realtime-preview-2024-12-17", "gemini-2.0-flash-live"
	RealtimeVoice    string // e.g., "alloy", "Puck"

	// Tools available to the voice LLM
	Tools        []ToolDefinition
	ToolHandlers map[string]ToolHandler

	// Greeting is the initial message spoken when a call connects.
	Greeting string

	// Session limits
	MaxSessionDuration time.Duration
	InterruptionMode   string

	// Logger
	Logger *slog.Logger
}

GatewayConfig configures the voice gateway integration.

type Processor

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

Processor handles voice transcription and synthesis using OmniVoice interfaces.

func New

func New(config Config, logger *slog.Logger) (*Processor, error)

New creates a new voice processor with the configured providers.

func (*Processor) Close

func (p *Processor) Close() error

Close releases provider resources.

func (*Processor) ResponseMode

func (p *Processor) ResponseMode() string

ResponseMode returns the voice response mode.

func (*Processor) SynthesizeSpeech

func (p *Processor) SynthesizeSpeech(ctx context.Context, text string) ([]byte, string, error)

SynthesizeSpeech converts text to audio using the configured TTS provider. Returns audio bytes and MIME type.

func (*Processor) TranscribeAudio

func (p *Processor) TranscribeAudio(ctx context.Context, audio []byte, mimeType string) (string, error)

TranscribeAudio converts audio to text using the configured STT provider.

type STTConfig

type STTConfig struct {
	// Provider is the STT provider name (e.g., "deepgram").
	Provider string
	// APIKey is the provider API key.
	APIKey string //nolint:gosec // G117: APIKey loaded from config file
	// Model is the provider-specific model identifier.
	Model string
	// Language is the BCP-47 language code. Empty for auto-detection.
	Language string
}

STTConfig configures the speech-to-text provider.

type TTSConfig

type TTSConfig struct {
	// Provider is the TTS provider name (e.g., "deepgram").
	Provider string
	// APIKey is the provider API key.
	APIKey string //nolint:gosec // G117: APIKey loaded from config file
	// Model is the provider-specific model identifier.
	Model string
	// VoiceID is the provider-specific voice identifier.
	VoiceID string
}

TTSConfig configures the text-to-speech provider.

type ToolDefinition added in v0.10.0

type ToolDefinition struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Parameters  map[string]any `json:"parameters"`
}

ToolDefinition defines a tool available to the voice LLM.

type ToolHandler added in v0.10.0

type ToolHandler func(ctx context.Context, args map[string]any) (string, error)

ToolHandler processes a tool call.

type VoiceAgentLLMProvider added in v0.10.0

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

VoiceAgentLLMProvider implements the gateway.LLMProvider interface using omniagent.

func NewVoiceAgentLLMProvider added in v0.10.0

func NewVoiceAgentLLMProvider(gw *Gateway) *VoiceAgentLLMProvider

NewVoiceAgentLLMProvider creates a new LLM provider that uses omniagent.

func (*VoiceAgentLLMProvider) Generate added in v0.10.0

func (p *VoiceAgentLLMProvider) Generate(ctx context.Context, input string, history []gateway.Turn) (string, []gateway.ToolCall, error)

Generate produces a response using the omniagent LLM.

Jump to

Keyboard shortcuts

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