Tutorial on Deploying Xiaozhi Chatbot with Raspberry Pi
I. Preparation Requirements:
- A Raspberry Pi (4B or higher)
- A 32GB memory card
- A microphone
- A speaker
- A camera
II. Burning the Raspberry Pi System Image:
III. Deploy the Xiaozhi Chatbot:
- Execute the following command to download the Xiaozhi Robot code (do not use sudo; use the default “pi” user):
git clone https://github.com/huangjunsen0406/py-xiaozhi.git
- Install system dependencies:
sudo apt-get update
# Essential installations
# Install volume control dependencies and PulseAudio utilities
|
- Python Dependency Installation: Use Miniconda (recommended) because some packages cannot be downloaded directly from the Raspberry Pi system’s repositories, which may lead to installation failures.
Download the Miniconda installation package:
Add execution permissions to the installation script:
Run the installation script:
During the installation process: When the license agreement appears → Press the Type Whether to initialize Miniconda → Type |
- Configure environment variables:
|
- Install project dependencies:
1. Create a py-xiaozhi virtual environment (Python version restriction: It is recommended to use Python 3.9.13+ version, with a maximum recommended version of 3.12)conda create -n py-xiaozhi python=3.10 -y 2. Activate the environment conda activate py-xiaozhi 3. Install Python dependencies cd py-xiaozhi/ pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple Install other dependencies (because installing these two with pip may cause issues with startup. They need to be installed separately in conda) # Still in the px-xiaozhi virtual environment being created # PyQt5 conda install pyqt=5.15.10 -y # OpenCV conda install opencv=4.10.0 -y |
- Start Xiaozhi Robot (remember to connect peripherals such as camera, microphone, and speaker):
python main.py
- Upon first launch, the verification code
xxxxxx
will be printed in the log - Log in to the Xiaozhi Console: https://xiaozhi.me/console
- Register and create an agent, click “
Add Device
“, and enter the verification code:
- Restart the Xiaozhi robot:
python main.py
- Configuration information has been generated under this project:
config/config.json
{
“SYSTEM_OPTIONS”: { “CLIENT_ID”: “a254fb22-f54f-48ca-8e32-29557542cfcf1”, “DEVICE_ID”: “dc:a6:32:7f:db:91”, “NETWORK”: { “OTA_VERSION_URL”: “https://api.tenclass.net/xiaozhi/ota/”, “WEBSOCKET_URL”: “wss://api.tenclass.net/xiaozhi/v1/”, “WEBSOCKET_ACCESS_TOKEN”: “test-token”, “MQTT_INFO”: { “endpoint”: “mqtt.xiaozhi.me”, “client_id”: “GID_test@@@dc_a6_32_7f_db_91@@@a254fb22-f54f-48ca-8e32-29557542cfcf”, “username”: “eyJpcCI6IjExNi4zMS4yNTUuMTIifQ==”, “password”: “ODxGAmYTSPuc5ajG0YpiT+cK5DQATnUCpUeoLY+K4Z8=”, “publish_topic”: “device-server”, “subscribe_topic”: “null” }, “ACTIVATION_VERSION”: “v2”, “AUTHORIZATION_URL”: “https://xiaozhi.me/” } }, “WAKE_WORD_OPTIONS”: { “USE_WAKE_WORD”: true, “MODEL_PATH”: “models/vosk-model-small-cn-0.22”, “WAKE_WORDS”: [ “小智”, “小美”, ] }, “TEMPERATURE_SENSOR_MQTT_INFO”: { “endpoint”: “你的Mqtt连接地址”, “port”: 1883, “username”: “admin”, “password”: “123456”, “publish_topic”: “sensors/temperature/command”, “subscribe_topic”: “sensors/temperature/device_001/state” }, “HOME_ASSISTANT”: { “URL”: “http://localhost:8123”, “TOKEN”: “”, “DEVICES”: [] }, “CAMERA”: { “camera_index”: 1, “frame_width”: 640, “frame_height”: 480, “fps”: 30, “Loacl_VL_url”: “https://open.bigmodel.cn/api/paas/v4/”, “VLapi_key”: “90edcea408a4442295cb5cd2ab1752914.iQLrZg76zUpOJgBJ”, “models”: “glm-4v-flash” } } |
config/efuse.json
{
“serial_number”: “SN-0EA6D7B6-dca6327fdb91”, “hmac_key”: “22143413742b6dc80173abf5ff1d97a488b9cee225092bce94eb56456fcf140d”, “activation_status”: true } |
- When the activation_status changes to true, it indicates that it has been activated.
- Successfully started:
- At this point, the Xiaozhi robot has been successfully activated, and you can now have a normal conversation with Xiaozhi.
IV.Configure the Voice Wake-up Function for Xiaozhi Chatbot
- Open Vosk model address: https://alphacephei.com/vosk/models
- Choose the speech recognition model you need to download (taking vosk-model-small-cn-0.22 as an example):
wget -O vosk-model-small-cn-0.22.zip https://alphacephei.com/vosk/models/vosk-model-small-cn-0.22.zip
Place the downloaded speech model in the specified “models” directory:
Modify configuration: Press |
- Start the Xiaozhi robot, and you can wake it up by voice
V.Configure Visual Recognition Function for Xiaozhi Chatbot
- Open the Zhipu AI console: https://www.bigmodel.cn/usercenter/proj-mgmt/apikeys
Create API keys:
Modify the configuration file config/config.json,copy the created API keys, replace the value of VLapi_key, and select glm-4v-flash for the models model. This visual model is free and can be adjusted for other models as needed.
If there is only one USB camera, camera_index needs to be set to 0,
|
- Start the Xiaozhi Chatbot to use its visual function