huangjunsen0406

py xiaozhi

Built by huangjunsen0406 โ€ข 3,247 stars

What is py xiaozhi?

A Python-based Xiaozhi AI for users who want the full Xiaozhi experience without owning specialized hardware.

How to use py xiaozhi?

1. Install a compatible MCP client (like Claude Desktop). 2. Open your configuration settings. 3. Add py xiaozhi using the following command: npx @modelcontextprotocol/py-xiaozhi 4. Restart the client and verify the new tools are active.
๐Ÿ›ก๏ธ Scoped (Restricted)
npx @modelcontextprotocol/py-xiaozhi --scope restricted
๐Ÿ”“ Unrestricted Access
npx @modelcontextprotocol/py-xiaozhi

Key Features

Native MCP Protocol Support
Real-time Tool Activation & Execution
Verified High-performance Implementation
Secure Resource & Context Handling

Optimized Use Cases

Extending AI models with custom local capabilities
Automating system workflows via natural language
Connecting external data sources to LLM context windows

py xiaozhi FAQ

Q

Is py xiaozhi safe?

Yes, py xiaozhi follows the standardized Model Context Protocol security patterns and only executes tools with explicit user-granted permissions.

Q

Is py xiaozhi up to date?

py xiaozhi is currently active in the registry with 3,247 stars on GitHub, indicating its reliability and community support.

Q

Are there any limits for py xiaozhi?

Usage limits depend on the specific implementation of the MCP server and your system resources. Refer to the official documentation below for technical details.

Official Documentation

View on GitHub

py-xiaozhi

<p align="center" class="trendshift"> <a href="https://trendshift.io/repositories/14130" target="_blank"> <img src="https://trendshift.io/api/badge/repositories/14130" alt="Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/> </a> </p> <p align="center"> <a href="https://github.com/huangjunsen0406/py-xiaozhi/releases/latest"> <img src="https://img.shields.io/github/v/release/huangjunsen0406/py-xiaozhi?style=flat-square&logo=github&color=blue" alt="Release"/> </a> <a href="https://opensource.org/licenses/MIT"> <img src="https://img.shields.io/badge/License-MIT-green.svg?style=flat-square" alt="License: MIT"/> </a> <a href="https://github.com/huangjunsen0406/py-xiaozhi/stargazers"> <img src="https://img.shields.io/github/stars/huangjunsen0406/py-xiaozhi?style=flat-square&logo=github" alt="Stars"/> </a> <a href="https://github.com/huangjunsen0406/py-xiaozhi/releases/latest"> <img src="https://img.shields.io/github/downloads/huangjunsen0406/py-xiaozhi/total?style=flat-square&logo=github&color=52c41a1&maxAge=86400" alt="Download"/> </a> <a href="https://gitee.com/huang-jun-sen/py-xiaozhi"> <img src="https://img.shields.io/badge/Gitee-FF5722?style=flat-square&logo=gitee" alt="Gitee"/> </a> <a href="https://huangjunsen0406.github.io/py-xiaozhi/guide/00_%E6%96%87%E6%A1%A3%E7%9B%AE%E5%BD%95.html"> <img alt="Usage Docs" src="https://img.shields.io/badge/Usage Docs-View-blue?labelColor=2d2d2d" /> </a> <a href="https://atomgit.com/huangjunsen0406/py-xiaozhi"> <img src="./assets/AtomGit.svg" alt="AtomGit" height="20"/> </a> </p>

English | ็ฎ€ไฝ“ไธญๆ–‡

โค๏ธ Sponsors

Want to appear here?

<details open> <summary>Click to collapse</summary>

GitDo.net

Thanks to GitDo.net for sponsoring this project! GitDo.net is an AI API aggregation platform โ€” one API Key for Claude, Gemini, GPT and other major models. Direct connection, no proxy needed, stable and efficient. An ideal choice for enterprise-grade AI programming. Visit GitDo.net


Token่ƒฝ้‡็ซ™Thanks to Token่ƒฝ้‡็ซ™ (Factory.pub) for sponsoring this project! Providing API relay for GPT, Grok, Claude and other major models โ€” stable, reliable, and affordable. Register here
่‰ฏๅฟƒAIThanks to ่‰ฏๅฟƒAI for sponsoring this project! Providing API relay for GPT, Claude, Gemini and other major models โ€” direct connection, stable and high-speed. Register here
</details>

About

py-xiaozhi is a lightweight, cross-platform multi-modal AI interaction framework built on Python's async architecture. It supports real-time voice streaming, vision-language tasks, and IoT device control. Deployable across Windows, macOS, Linux desktops, and ARM embedded platforms (Raspberry Pi, Horizon Robotics RDK, Jetson Nano), it bridges the gap between Large Language Models and physical hardware โ€” out of the box.

Evolved from the xiaozhi-esp32 firmware project. Officially adopted by D-Robotics (xiaozhi-in-rdk) as an upstream dependency.

Related Projects

  • xiaozhi-desktop โ€” Electron desktop client with AEC echo cancellation, Live2D, floating window modes, and Windows / macOS installers

Demo

Image

Key Features

  • Real-time Voice AI โ€” Opus codec with auto frame detection (RFC 6716 TOC parsing), async streaming, sub-20ms latency
  • Multi-modal Vision โ€” Camera capture + vision-language model integration for image understanding and scene perception
  • MCP Tool Ecosystem โ€” Modular JSON-RPC 2.0 tool server: music player, camera, screenshot, app management, weather, volume control
  • Cross-platform Deployment โ€” Windows 10+ / macOS 10.15+ / Linux (x86_64 & ARM), optimized for Raspberry Pi and edge boards
  • Multiple UI Modes โ€” PySide6 + QML GUI / CLI / GPIO, adapting to desktop, headless server, and embedded environments
  • Offline Wake Word โ€” Sherpa-ONNX based on-device keyword spotting with custom wake word support
  • IoT & Embodied AI Ready โ€” GPIO interface for robotics control, hardware actuation, and sensor integration
  • WebSocket / MQTT โ€” Dual protocol communication with WSS/TLS encrypted transmission and auto-reconnection
  • Plugin Architecture โ€” Event-driven async design, clean dependency injection, extensible plugin system

System Requirements

Basic Requirements

  • Python Version: 3.10 - 3.12
  • Operating System: Windows 10+, macOS 10.15+, Linux
  • Audio Devices: Microphone and speaker devices
  • Network Connection: Stable internet connection (for AI services and online features)

Recommended Configuration

  • Memory: At least 4GB RAM (8GB+ recommended)
  • Processor: Modern CPU with AVX instruction set support
  • Storage: At least 2GB available disk space (for model files and cache)
  • Audio: Audio devices supporting 16kHz sampling rate

Optional Feature Requirements

  • Voice Wake-up: Requires downloading Sherpa-ONNX speech recognition models
  • Camera Features: Requires camera device and OpenCV support

Read This First

  • Carefully read ้กน็›ฎๆ–‡ๆกฃ for startup tutorials and file descriptions
  • The main branch has the latest code; manually reinstall pip dependencies after each update to ensure you have new dependencies

Zero to Xiaozhi Client (Video Tutorial)

Technical Architecture

Core Architecture Design

  • Event-Driven Architecture: Based on asyncio asynchronous event loop, supporting high-concurrency processing
  • Layered Design: Clear separation of application layer, protocol layer, and UI layer
  • Dependency Injection: Component lifecycle managed via bootstrap container
  • Plugin System: Audio, UI, MCP tools and other components loaded via plugin system

Key Technical Components

  • Audio Processing: Opus codec, real-time resampling
  • Speech Recognition: Sherpa-ONNX offline models, wake word recognition
  • Protocol Communication: WebSocket/MQTT dual protocol support, encrypted transmission, auto-reconnection
  • Configuration System: Hierarchical configuration, dot notation access, dynamic updates

Performance Optimization

  • Async First: Full system asynchronous architecture, avoiding blocking operations
  • Memory Management: Smart caching, garbage collection
  • Audio Optimization: 5ms low-latency processing, queue management, streaming transmission
  • Concurrency Control: Task pool management, semaphore control, thread safety

Security Mechanisms

  • Encrypted Communication: WSS/TLS encryption, certificate verification
  • Device Authentication: Dual protocol activation, device fingerprint recognition
  • Access Control: Tool permission management, API access control
  • Error Isolation: Exception isolation, fault recovery, graceful degradation

Development Guide

Project Structure

py-xiaozhi/
โ”œโ”€โ”€ main.py                     # Application entry point
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ activation/             # Device activation
โ”‚   โ”œโ”€โ”€ audio_codecs/           # Audio codecs
โ”‚   โ”œโ”€โ”€ audio_processing/       # Wake word detection
โ”‚   โ”œโ”€โ”€ bootstrap/              # Application bootstrap & dependency injection
โ”‚   โ”œโ”€โ”€ constants/              # Constants
โ”‚   โ”œโ”€โ”€ core/                   # Core infrastructure (event bus, state management, task management, etc.)
โ”‚   โ”œโ”€โ”€ logging/                # Logging subsystem
โ”‚   โ”œโ”€โ”€ mcp/                    # MCP tool system
โ”‚   โ”‚   โ”œโ”€โ”€ mcp_server.py       # MCP server
โ”‚   โ”‚   โ””โ”€โ”€ tools/              # Tool modules (music/camera/screenshot/app/weather/volume)
โ”‚   โ”œโ”€โ”€ plugins/                # Plugin system (audio, UI, MCP, wake word, shortcuts)
โ”‚   โ”œโ”€โ”€ protocols/              # Communication protocols (WebSocket/MQTT)
โ”‚   โ”œโ”€โ”€ ui/                     # User interface
โ”‚   โ”‚   โ”œโ”€โ”€ gui/                # PySide6 + QML graphical interface
โ”‚   โ”‚   โ”œโ”€โ”€ cli/                # Command line interface
โ”‚   โ”‚   โ””โ”€โ”€ gpio/               # GPIO embedded interface
โ”‚   โ””โ”€โ”€ utils/                  # Utility functions
โ”œโ”€โ”€ libs/                       # Third-party native libraries
โ”‚   โ”œโ”€โ”€ libopus/                # Opus audio codec library
โ”‚   โ””โ”€โ”€ webrtc_apm/             # WebRTC audio processing module
โ”œโ”€โ”€ models/                     # Wake word models
โ”œโ”€โ”€ assets/                     # Static resources
โ”œโ”€โ”€ scripts/                    # Auxiliary scripts
โ”œโ”€โ”€ documents/                  # VitePress documentation site
โ”œโ”€โ”€ pyproject.toml              # Project configuration
โ””โ”€โ”€ build.json                  # Build configuration

Development Environment Setup

# Clone project
git clone https://github.com/huangjunsen0406/py-xiaozhi.git
cd py-xiaozhi

# Base install (CLI / GPIO mode)
uv sync                                    # Recommended (uv users)
# or: pip install -e .                    # pip users

# GUI mode (extra: PySide6 + qasync)
uv sync --extra gui                        # Recommended (uv users)
# or: pip install -e '.[gui]'             # pip users

# Full development environment (GUI + test / packaging tools)
uv sync --extra gui --group dev

# Code formatting
./format_code.sh

# Run program - GUI mode (default; requires gui extra)
python main.py

# Run program - CLI mode (base install is enough)
python main.py --mode cli

# Specify communication protocol
python main.py --protocol websocket  # WebSocket (default)
python main.py --protocol mqtt       # MQTT protocol

Core Development Patterns

  • Async First: Use async/await syntax, avoid blocking operations
  • Error Handling: Complete exception handling and logging
  • Configuration Management: Use ConfigManager for unified configuration access
  • Test-Driven: Write unit tests to ensure code quality

Extension Development

  • Add MCP Tools: Create new tool modules in src/mcp/tools/ directory
  • Add Protocols: Implement Protocol abstract base class
  • Add Plugins: Extend the plugin system via src/plugins/

State Transition Diagram

                        +----------------+
                        |                |
                        v                |
+------+  Wake/Button  +------------+   |   +------------+
| IDLE | -----------> | CONNECTING | --+-> | LISTENING  |
+------+              +------------+       +------------+
   ^                                            |
   |                                            | Voice Recognition Complete
   |          +------------+                    v
   +--------- |  SPEAKING  | <-----------------+
     Playback +------------+
     Complete

Contributing

Maintainer Workflow

  • Triage incoming work as bug, feature, docs, refactor, or maintenance
  • Prefer focused pull requests with clear validation steps and linked context
  • Require docs updates when behavior, configuration, or public APIs change
  • Merge after CI passes and review feedback is resolved
  • Release through the normal release flow; merge does not imply immediate shipping

Community and Support

Thanks to the Following Open Source Contributors

In no particular order

Xiaoxia zhh827 SmartArduino-Li Honggang HonestQiao vonweller Sun Weigong isamu2025 Rain120 kejily Radio bilibili Jun Cyber Intelligence

Project Statistics

Star History Chart

License

MIT License

Global Ranking

-
Trust ScoreMCPHub Index

Based on codebase health & activity.

Manual Config

{ "mcpServers": { "py-xiaozhi": { "command": "npx", "args": ["py-xiaozhi"] } } }