xiaozhi-esp32-server/mydoc/本地启动指南.md
hw045269137 cde989fd47 chore: 移除 Liquibase 依赖,改用手工执行 SQL 初始化脚本
- manager-api 删除 liquibase-core 依赖、@DependsOn 及 changelog-master 配置
- config_loader 拉取远端配置时对密钥字段脱敏后再打印日志
- 新增 test-page 调试页面与 mydoc 文档、全量初始化 SQL
- 更新本地开发数据库/Redis 连接配置与前端 package-lock

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-10-24 22:09:31 +08:00

160 lines
4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 本地启动指南
> xiaozhi-esp32-server(dev 分支)
## 启动顺序
```
MySQL / Redis → manager-api → manager-web(注册管理员、取 server.secret)
→ xiaozhi-server(需 server.secret)
```
| 项目 | 目录 | 端口 |
| --- | --- | --- |
| Java 端 | `main/manager-api` | 8002 |
| 前端 | `main/manager-web` | 8001 |
| Python 端 | `main/xiaozhi-server` | 8000 / 8003 |
| 数字人(可选) | `main/digital-human` | 8006 |
| 移动端(可选) | `main/manager-mobile` | 9000 |
## 环境
- Python 端:Python 3.10、ffmpeg(PATH)、libopus
- Java 端:JDK 21、Maven 3.9+
- 前端:Node.js 18+
- 移动端:Node.js 18+、pnpm 10
## 1. Java 端:manager-api
### 1.1 准备数据库
```sql
CREATE DATABASE xiaozhi_esp32_server CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
```
建表脚本已合并为一个文件:`mydoc/xiaozhi_esp32_server_init.sql`,在空库执行:
```powershell
mysql -uroot -p123456 xiaozhi_esp32_server -e "source mydoc/xiaozhi_esp32_server_init.sql"
```
### 1.2 配置与启动
1. 在 [application-dev.yml](../main/manager-api/src/main/resources/application-dev.yml) 配置 MySQL / Redis(当前指向远程库)
2. 启动:
```powershell
cd main\manager-api
mvn spring-boot:run
```
3. 验证:日志出现 `Started AdminApplication`,且 <http://127.0.0.1:8002/xiaozhi/doc.html> 可访问
## 2. 前端:manager-web
```powershell
cd main\manager-web
npm install
npm run serve
```
访问 <http://127.0.0.1:8001>。代理已配置 `/xiaozhi` → `127.0.0.1:8002`,无需改接口地址。
## 3. 智控台初始化
1. 打开 <http://127.0.0.1:8001>,注册第一个账号(自动成为超级管理员)
2. 「参数管理」→ `server.secret`,复制参数值
3. 「模型配置」→ 大语言模型 → 智谱AI,填入 API 密钥并保存
## 4. Python 端:xiaozhi-server
1. 创建环境:
```powershell
conda create -n xiaozhi-esp32-server python=3.10 -y
conda activate xiaozhi-esp32-server
conda install libopus ffmpeg -y
```
2. 安装依赖:
```powershell
cd main\xiaozhi-server
pip install -r requirements.txt
```
3. 下载 ASR 模型,放到 `models/SenseVoiceSmall/model.pt`(只用云端 ASR 可跳过):
- 魔搭:<https://modelscope.cn/models/iic/SenseVoiceSmall/resolve/master/model.pt>
- 百度网盘:<https://pan.baidu.com/share/init?surl=QlgM58FHhYv1tFnUT_A8Sg> 提取码 `qvna`
4. 配置:
```powershell
mkdir data
copy config_from_api.yaml data\.config.yaml
```
```yaml
manager-api:
url: http://127.0.0.1:8002/xiaozhi
secret: 第3章复制的server.secret值
```
5. 启动:
```powershell
python app.py
```
日志出现 `Websocket地址是 ws://...` 即成功(该地址不能用浏览器访问)。
6. 在智控台「参数管理」回填:
| 参数 | 填写 |
| --- | --- |
| `server.websocket` | `ws://局域网IP:8000/xiaozhi/v1/` |
| `server.ota` | `http://局域网IP:8002/xiaozhi/ota/` |
不要填 `127.0.0.1`,否则 ESP32 无法访问。
## 5. 可选模块
**digital-human(8006)**
```powershell
cd main\digital-human
pip install -r wakeword_runtime\requirements.txt
python start.py
```
访问 <http://127.0.0.1:8006/index.html>。
**manager-mobile(9000)**
```powershell
cd main\manager-mobile
pnpm install
pnpm dev:h5
```
先在 [env/.env](../main/manager-mobile/env/.env) 设置 `VITE_SERVER_BASEURL = 'http://127.0.0.1:8002/xiaozhi'`。
## 端口速查
| 服务 | 地址 |
| --- | --- |
| 智控台 | <http://127.0.0.1:8001> |
| manager-api 文档 | <http://127.0.0.1:8002/xiaozhi/doc.html> |
| WebSocket | `ws://127.0.0.1:8000/xiaozhi/v1/` |
| OTA | <http://127.0.0.1:8002/xiaozhi/ota/> |
| digital-human | <http://127.0.0.1:8006/index.html> |
| manager-mobile | <http://127.0.0.1:9000> |
## 常见问题
- ffmpeg / libopus 报错:`conda install ffmpeg libopus -y`
- 拉不到配置:检查 `data/.config.yaml` 的 `url` 与 `secret`
- 数据库连接失败:确认库已创建、`application-dev.yml` 配置正确
- 页面 404:先确认 8002 已启动
- 端口被占用:`netstat -ano | findstr :8000` 结束对应进程