Documentation
¶
Overview ¶
Package xiaozhi implements the xiaozhi-esp32 WebSocket voice protocol.
Device / Browser ── xiaozhi WS ──► Server ── dialog WS ──► Dialog (LLM)
Index ¶
- Constants
- func MakeAbortConfirm(sessionID string) []byte
- func MakeError(message string, fatal bool) []byte
- func MakeLLMReply(text string) []byte
- func MakePongReply(sessionID string) []byte
- func MakeSTTReply(sessionID, text string) []byte
- func MakeTTSStateReply(sessionID, state, codec string) []byte
- func MakeTTSStateReplyFrames(sessionID, state, codec string, frameMs int) []byte
- func MakeWelcomeReply(sessionID string, ap AudioParams) []byte
- func MergeHelloAudio(h *AudioParams)
- func ParseTextFrame(raw []byte) (string, error)
- type AudioParams
- type HelloMessage
- type ListenMessage
- type MessageHandler
- type RealtimeAgentFactory
- type Server
- type ServerConfig
Constants ¶
View Source
const ( MsgHello = "hello" MsgListen = "listen" MsgAbort = "abort" MsgPing = "ping" RespHello = "hello" RespPong = "pong" RespSTT = "stt" RespTTS = "tts" RespError = "error" RespAbortConfirm = "abort" )
View Source
const ( ListenStart = "start" ListenStop = "stop" ListenDetect = "detect" )
View Source
const ( AudioFormatOpus = "opus" AudioFormatPCM = "pcm" )
View Source
const ( // ModePipeline: ASR + dialog-plane WebSocket (LLM) + TTS. ModePipeline = "pipeline" // ModeRealtime: pkg/realtime multimodal agent (e.g. Qwen-Omni). ModeRealtime = "realtime" )
Variables ¶
This section is empty.
Functions ¶
func MakeAbortConfirm ¶
func MakeLLMReply ¶
func MakePongReply ¶
func MakeSTTReply ¶
func MakeTTSStateReply ¶
func MakeTTSStateReplyFrames ¶
func MakeWelcomeReply ¶
func MakeWelcomeReply(sessionID string, ap AudioParams) []byte
func MergeHelloAudio ¶
func MergeHelloAudio(h *AudioParams)
func ParseTextFrame ¶
Types ¶
type AudioParams ¶
type AudioParams struct {
Format string `json:"format,omitempty"`
Codec string `json:"codec,omitempty"`
SampleRate int `json:"sample_rate,omitempty"`
Channels int `json:"channels,omitempty"`
FrameDuration int `json:"frame_duration,omitempty"`
BitDepth int `json:"bit_depth,omitempty"`
}
func DefaultHelloAudio ¶
func DefaultHelloAudio() AudioParams
type HelloMessage ¶
type ListenMessage ¶
type MessageHandler ¶ added in v1.3.0
MessageHandler is a custom message handler for extensibility.
type RealtimeAgentFactory ¶
type RealtimeAgentFactory interface {
NewAgent(ctx context.Context, callID string, onEvent func(realtime.Event)) (realtime.Agent, int, int, error)
}
RealtimeAgentFactory builds a started realtime.Agent for one xiaozhi session.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server accepts xiaozhi WebSocket connections.
type ServerConfig ¶
type ServerConfig struct {
SessionFactory transport.SessionFactory
RealtimeFactory RealtimeAgentFactory
DialogWSURL string
CallIDPrefix string
ResolveDevicePayload func(ctx context.Context, deviceID string) ([]byte, error)
ConfigureClient func(*gateway.ClientConfig)
OnSessionStart func(ctx context.Context, callID, deviceID string)
OnSessionEnd func(ctx context.Context, callID, reason string)
// ConfigureSession allows third-party extensions to register custom message handlers
ConfigureSession func(session *wsSession)
}
ServerConfig wires the xiaozhi adapter.
Click to show internal directories.
Click to hide internal directories.