Xiaozhi AI Assistant
Files Referenced in This Article
esp32s3/firmware/file_system/mpython_v3/ui/voice.pyesp32s3/firmware/file_system/labplus_Ledong_v2/ui/voice.py
Table of Contents
Product Overview
Core Business Flow
Feature Module List
Data and State
Key Constraints and Boundaries
Product Overview
Xiaozhi AI is an ESP32-S3-based voice conversation AI assistant that provides capabilities such as wake-word detection, real-time translation, and responsive interaction, and supports switching the large model and voice timbre in the management backend. The project provides compilation-free firmware that can be flashed directly onto mPython Board 3.0 or mPython Core 2.0 for a quick smart-terminal experience. Its open-source project is developed on ESP-IDF, facilitating secondary development and deployment in educational scenarios.
Target users: makers, teachers and students, AI/IoT beginners and advanced developers
Core value: low-barrier access to cloud large models, combined with local audio capture and playback, delivering a closed-loop “speak-listen-answer” experience
Application scenarios: voice assistants, multilingual translation, classroom interaction, smart-home control prototypes, and edge-AI teaching demonstrations
Section Sources
Core Business Flow
The typical usage flow of Xiaozhi AI is as follows:
Device preparation: connect to a PC via USB-C, use the mPython software to select the corresponding board (mPython Board 3.0 or mPython Core 2.0), and flash the Xiaozhi firmware
Power-on and run: after booting, the device enters the Xiaozhi interface and displays the wake-word prompt
Voice interaction: speak the wake word to trigger recording; the recognition result is uploaded to the cloud large model; the returned text and speech-synthesis result are played on the device
Role and voice timbre: configure the role name, voice timbre, and large model in the management backend; this takes effect on the device’s next conversation
Extension capabilities: a higher-power amplifier speaker can be replaced, or third-party music platforms can be accessed via code
sequenceDiagram
participant User as "User"
participant Device as "ESP32-S3 device"
participant Cloud as "Cloud large model/TTS service"
participant UI as "LVGL interface"
participant Audio as "Audio subsystem"
User->>Device : Speak the wake word
Device->>Audio : Capture microphone audio
Device->>Cloud : Send the speech-recognition request
Cloud-->>Device : Return the recognized text
Device->>Cloud : Send the conversation context and question
Cloud-->>Device : Return the answer text
Device->>Audio : Call TTS to generate speech
Audio-->>Device : Play the reply speech
Device->>UI : Update the interface state and prompt
User-->>Device : Continue or end the conversation
Diagram Sources
esp32s3/firmware/file_system/mpython_v3/ui/voice.py:20-26esp32s3/firmware/file_system/labplus_Ledong_v2/ui/voice.py:20-26
Section Sources
Feature Module List
Device and firmware
Supported boards: mPython Board 3.0, mPython Core 2.0
Flashing method: select the board in the mPython software, then flash the Xiaozhi firmware in one click
Reference paths: esp32s3/docs/4_xiaozhi/2_xiaozhi.rst:19-38, esp32s3/docs/boards/ledong_v2/4_xiaozhi/2_xiaozhi.rst:19-38
Voice interaction and interface
Wake-word detection and command-word recognition: initialize and add commands via the speech-recognition interface, and poll for the latest recognition result on a timer
LVGL interface: displays the wake-word prompt, animations, and the back action
Reference paths:
esp32s3/firmware/file_system/mpython_v3/ui/voice.py:20-26,esp32s3/firmware/file_system/labplus_Ledong_v2/ui/voice.py:20-26
Cloud large model and voice timbre management
Supported models: Qwen 2.5 (real-time), DeepSeek V3, DouBao 1.5 Pro, Qwen Max 2.5
Management backend: switch models and voice timbres on the console/device management/configure role pages
Reference paths: esp32s3/docs/4_xiaozhi/3_xiaozhi-faq.rst:7-15, esp32s3/docs/boards/ledong_v2/4_xiaozhi/3_xiaozhi-faq.rst:7-15
Audio hardware and extension
The default digital amplifier MAX98357 supports about a 3W speaker; higher power requires an I2S amplifier module and independent power supply
Reference paths: esp32s3/docs/4_xiaozhi/3_xiaozhi-faq.rst:18-19, esp32s3/docs/boards/ledong_v2/4_xiaozhi/3_xiaozhi-faq.rst:18-19
Voiceprint recognition
Voice recordings can be added for speakers in the backend to achieve “identify a person by voice”
Reference paths: esp32s3/docs/4_xiaozhi/3_xiaozhi-faq.rst:30-38, esp32s3/docs/boards/ledong_v2/4_xiaozhi/3_xiaozhi-faq.rst:30-38
Section Sources
esp32s3/docs/boards/ledong_v2/4_xiaozhi/3_xiaozhi-faq.rst:7-15
esp32s3/docs/boards/ledong_v2/4_xiaozhi/3_xiaozhi-faq.rst:18-19
esp32s3/docs/boards/ledong_v2/4_xiaozhi/3_xiaozhi-faq.rst:30-38
esp32s3/firmware/file_system/mpython_v3/ui/voice.py:20-26esp32s3/firmware/file_system/labplus_Ledong_v2/ui/voice.py:20-26
Data and State
Speech-recognition state
Initialization: set the wake-word and command-word collections and update the recognizer
Polling: read the latest recognition ID in the timer callback and perform the corresponding action (such as RGB LED control)
Reference paths:
esp32s3/firmware/file_system/mpython_v3/ui/voice.py:20-26,esp32s3/firmware/file_system/labplus_Ledong_v2/ui/voice.py:20-26
Interface state
Container and canvas: create the LVGL container and background color
Labels and layout: display the “wake word” and “command word” prompts and the back button
Animation: loop-draw animation images to indicate the device is listening
Reference paths:
esp32s3/firmware/file_system/mpython_v3/ui/voice.py:61-112,esp32s3/firmware/file_system/labplus_Ledong_v2/ui/voice.py:61-112
Role and voice timbre configuration
Role name: modified in the management backend and takes effect after saving
Voice timbre switching: audition and submit in the backend; the new timbre is used in the next conversation
Reference paths: esp32s3/docs/4_xiaozhi/3_xiaozhi-faq.rst:22-28, esp32s3/docs/boards/ledong_v2/4_xiaozhi/3_xiaozhi-faq.rst:22-28
flowchart TD
Start(["Start"]) --> Init["Initialize speech recognition<br/>Set wake words and command words"]
Init --> Loop{"Timer callback"}
Loop --> Read["Read the latest recognition ID"]
Read --> HasResult{"Valid?"}
HasResult -- No --> Loop
HasResult -- Yes --> Action{"Perform the corresponding action"}
Action --> RGB["Control the RGB LED/other peripherals"]
Action --> Play["Play a prompt tone or music"]
RGB --> Loop
Play --> Loop
Diagram Sources
esp32s3/firmware/file_system/mpython_v3/ui/voice.py:20-26esp32s3/firmware/file_system/labplus_Ledong_v2/ui/voice.py:20-26
Section Sources
esp32s3/firmware/file_system/mpython_v3/ui/voice.py:20-26esp32s3/firmware/file_system/labplus_Ledong_v2/ui/voice.py:20-26esp32s3/docs/boards/ledong_v2/4_xiaozhi/3_xiaozhi-faq.rst:22-28
Key Constraints and Boundaries
Network and service dependencies
Speech recognition and TTS require network access to cloud services; ensure the device is connected to Wi-Fi
Large model and voice timbre configuration is done through the management backend; no manual API key configuration is needed on the device side
Reference paths: esp32s3/docs/4_xiaozhi/2_xiaozhi.rst:19-38, esp32s3/docs/boards/ledong_v2/4_xiaozhi/2_xiaozhi.rst:19-38
Hardware and power consumption
The default amplifier supports about a 3W speaker; higher power requires an I2S amplifier and independent power supply
USB power generally does not exceed 5W; mind the overall power consumption and heat dissipation
Reference paths: esp32s3/docs/4_xiaozhi/3_xiaozhi-faq.rst:18-19, esp32s3/docs/boards/ledong_v2/4_xiaozhi/3_xiaozhi-faq.rst:18-19
Copyright and content restrictions
The built-in test music is subject to copyright restrictions; only test tracks and user-submitted songs may be used
For more music resources, third-party platforms can be accessed via expansion IO or code
Reference paths: esp32s3/docs/4_xiaozhi/3_xiaozhi-faq.rst:4-5, esp32s3/docs/boards/ledong_v2/4_xiaozhi/3_xiaozhi-faq.rst:4-5
Recognition accuracy and personalization
Voiceprint recognition accuracy is affected by the environment, recording quality, and the number of speakers
It is recommended to record longer and clearer speech to improve recognition
Reference paths: esp32s3/docs/4_xiaozhi/3_xiaozhi-faq.rst:30-38, esp32s3/docs/boards/ledong_v2/4_xiaozhi/3_xiaozhi-faq.rst:30-38
Section Sources