Add XiaoZhi WebSocket server plugin for realtime voice conversations #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements XiaoZhi WebSocket protocol server as a BotSharp plugin to enable realtime voice conversations with xiaozhi-esp32 and compatible clients.
Implementation
Plugin Architecture
XiaoZhiPluginimplementsIBotSharpAppPluginfor automatic middleware registrationXiaoZhiStreamMiddlewarehandles WebSocket connections at/xiaozhi/stream/{agentId}/{conversationId}Protocol Handling
BotSharpRealtimeSessionwhich only supports textIntegration
IRealtimeHubfor LLM realtime API conversationsConfiguration
{ "XiaoZhi": { "EndpointPath": "/xiaozhi/stream", "DefaultProtocolVersion": 3, "AudioFormat": "opus", "SampleRate": 24000, "Channels": 1, "FrameDuration": 60 } }Protocol Example
Client connects and sends hello:
{ "type": "hello", "version": 3, "transport": "websocket", "audio_params": { "format": "opus", "sample_rate": 16000, "channels": 1, "frame_duration": 20 } }Server responds with session:
{ "type": "hello", "transport": "websocket", "session_id": "uuid", "audio_params": { "format": "opus", "sample_rate": 24000, "channels": 1, "frame_duration": 60 } }Binary audio then flows bidirectionally using protocol-specific packet headers.
Compatibility
Works with xiaozhi-esp32, Verdure.Assistant, and py-xiaozhi clients. Reference implementation: xiaozhi-esp32-server.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.