update:增加docker

This commit is contained in:
hrz
2025-02-06 02:08:58 +08:00
parent 62752a3fc7
commit f72656b3b9
5 changed files with 246 additions and 30 deletions
+7 -10
View File
@@ -1,21 +1,18 @@
FROM python:3.9.21-slim
FROM python:3.10-slim
ENV LC_ALL=zh_CN.UTF-8 \
LANG=zh_CN.UTF-8 \
LANGUAGE=zh_CN.UTF-8
# Replace single RUN commands with a single RUN command to reduce layers
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y libgomp1 libgl1-mesa-glx libglib2.0-0 \
&& apt-get install -y libopus-dev ffmpeg \
&& apt-get clean \
&& apt-get autoremove -y
# Set working directory
WORKDIR /opt/xiaozhi-es32-server
COPY . /opt/xiaozhi-es32-server
# Clean unnecessary files to reduce image size
RUN pip install -r requirements.txt
#
RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
## Start the application
CMD ["python", "Application.py"]
CMD ["python", "app.py"]
+111 -8
View File
@@ -52,15 +52,113 @@
# 部署方式
本项目暂时只支持本地源码运行,未来将支持docker快速部署。
本项目支持docker快速部署和本地源码运行。如果您主要是想快速体验,推荐使用docker部署。如果想深入了解本项目,推荐本地源码运行
## 本地源码运行
## 方式一:docker快速部署
如果你的电脑是`arm`架构的电脑,请暂时使用`方式二:本地源码运行``arm`架构需要再等几天,因为目前还没有适配arm架构的镜像。
1. 安装docker
如果您的电脑还没安装docker,可以按照这里的教程安装:[docker安装](https://www.runoob.com/docker/ubuntu-docker-install.html)
2. 创建目录
安装完后,你需要为这个项目找一个安放配置文件的目录,我们暂且称它为`项目目录`,这个目录最好是一个新建的空的目录。
3. 下载配置文件
用浏览器打开[这个链接](https://github.com/xinnan-tech/xiaozhi-esp32-server/blob/main/config.yaml)。
在页面的右侧找到名称为`RAW`按钮,在`RAW`按钮的旁边,找到下载的图标,点击下载按钮,下载`config.yaml`文件。 把文件下载到你的`项目目录`
4. 修改配置文件
修改刚才你下载的`config.yaml`文件,配置本项目所需的各种参数。默认的LLM使用的是`ChatGLMLLM`,你需要配置密钥,才能启动。
默认的TTS使用的是`EdgeTTS`,这个无需配置,如果你需要更换成`豆包TTS`,则需要配置密钥。
配置说明:这里是各个功能使用的默认组件,例如LLM默认使用`ChatGLMLLM`模型。如果需要切换模型,就是改对应的名称。
本项目的默认配置原则是成本最低配置原则(`glm-4-flash``EdgeTTS`都是免费的),如果需要更优的更快的搭配,需要自己结合部署环境切换各组件的使用。
```
selected_module:
ASR: FunASR
VAD: SileroVAD
LLM: ChatGLMLLM
TTS: EdgeTTS
```
比如修改`LLM`使用的组件,就看本项目支持哪些`LLM`,如下就是支持`DeepSeekLLM``ChatGLMLLM`。你们在`selected_module`修改成对应的LLM
```
LLM:
DeepSeekLLM:
...
ChatGLMLLM:
...
DifyLLM:
...
```
有些服务,比如如果你使用`Dify``豆包的TTS`,是需要密钥的,记得在配置文件加上哦!
5. 执行docker命令
打开命令行工具,`cd` 进入到你的`项目目录`,执行以下命令
```
#如果你是linux,执行
ls
#如果你是windows,执行
dir
```
如果你能看到`config.yaml`文件,确确实实进入到了`项目目录`,接着执行以下命令:
```
docker run -d --name xiaozhi-esp32-server --restart always -p 8000:8000 -v ./config.yaml:/opt/xiaozhi-es32-server/config.yaml ccr.ccs.tencentyun.com/xinnan/xiaozhi-esp32-server:latest
```
如果首次执行,可能需要几分钟时间,你要耐心等待他完成拉取。正常拉取完成后,你可以在命令行执行以下命令查看服务是否启动成功
```
docker ps
```
如果你能看到`xiaozhi-server`,说明服务启动成功。那你还可以进一步执行以下命令,查看服务的日志
```
docker logs -f xiaozhi-esp32-server
```
如果你能看到,类似以下日志,则是本项目服务启动成功的标志。
```
2025-xx-xx xx:51:59,492 - core.server - INFO - Server is running at ws://xx.xx.xx.xxx:8000
2025-xx-xx xx:51:59,516 - websockets.server - INFO - server listening on 0.0.0.0:8000
```
接下来,你就可以开始 `编译esp32固件`了,请往下翻,翻到编译`esp32固件`相关章节。那么由于你是用docker部署,你要自己查看自己本机电脑的ip是多少。
正常来说,假设你的ip是`192.168.1.25`,那么你的接口地址就是:`ws://192.168.1.25:8000`。这个信息很有用的,后面`编译esp32固件`需要用到。
后期如果想升级版本,可以这么操作
1、备份好`config.yaml`文件,一些关键的配置到时复制到新的`config.yaml`文件里。
2、执行以下命令
```
docker stop xiaozhi-esp32-server
docker rm xiaozhi-esp32-server
docker rmi ccr.ccs.tencentyun.com/xinnan/xiaozhi-esp32-server:latest
```
3.按本教程重新来一遍
## 方式二:本地源码运行
### 1.安装基础环境
本项目使用`python`语言开发,依赖`python``conda`环境,运行本项目需安装`python``conda`
安装后使用`conda`创建以下环境
本项目依赖`ffmpeg``libopus-dev``conda`,安装好后开始执行以下命令
```
conda remove -n xiaozhi-esp32-server --all -y
@@ -119,6 +217,8 @@ LLM:
启动项目
```
# 确保在本项目的根目录下执行
conda activate xiaozhi-esp32-server
python app.py
```
@@ -131,13 +231,13 @@ python app.py
其中上面的`ws://192.168.1.25:8000`就是本项目提供的接口地址了,当然你自己的机器和我的是不一样的,记得要找到自己的地址。
### 6.编译esp32固件
# 编译esp32固件
1. 下载`xiaozhi-esp32`
项目,按照这个教程配置项目环境[《Windows搭建 ESP IDF 5.3.2开发环境以及编译小智》](https://icnynnzcwou8.feishu.cn/wiki/JEYDwTTALi5s2zkGlFGcDiRknXf)
2. 打开`xiaozhi-esp32/main/Kconfig.projbuild`文件,找到`WEBSOCKET_URL``default`的内容,把`wss://api.tenclass.net`
改成你自己的地址,例如
改成你自己的地址,例如,我的接口地址是`ws://192.168.1.25:8000`,就把内容改成这个。
修改前:
@@ -171,6 +271,7 @@ idf.py set-target esp32s3
# 进入菜单配置
idf.py menuconfig
```
![图片](docs/images/build_setting01.png)
进入菜单配置后,再进入`Xiaozhi Assistant`,将`CONNECTION_TYPE`设置为`Websocket`
@@ -210,6 +311,7 @@ https://espressif.github.io/esp-launchpad/
## 1、TTS 经常失败,经常超时
建议:如果`EdgeTTS`慢或经常失败,可以更换成`火山引擎的豆包TTS`,如果两个都慢,可能所处的网络环境需要优化一下。
有部分网友反馈,使用`EdgeTTS`时,最好不要使用梯子,容易失败。
## 2、大模型回复有点慢
@@ -226,12 +328,13 @@ https://espressif.github.io/esp-launchpad/
## 5、我说话很慢,我停顿一下,小智老是抢我的话,咋办。
建议:在配置文件里,找到这一段,将`min_silence_duration_ms`值改大一点,比如改成`1000`
```
VAD:
SileroVAD:
threshold: 0.5
model_dir: models/snakers4_silero-vad
min_silence_duration_ms: 300 # 如果说话停顿比较长,可以把这个值设置大一些
min_silence_duration_ms: 700 # 如果说话停顿比较长,可以把这个值设置大一些
```
## 6、更多问题,可联系我们反馈
+121 -6
View File
@@ -57,13 +57,123 @@ To fully experience this project, follow these steps:
# Deployment
Currently supports local source code execution. Docker deployment coming soon.
This project supports rapid deployment of docker and local source code operation. If you want to have a quick
experience, it is recommended to use docker to deploy. If you want to have an in-depth understanding of this project, it
is recommended to run the local source code.
## Local Source Code Deployment
## Method 1: Quick deployment of docker
If your computer is an `arm` architecture computer, please use `Method 2: Run local source code`. The `arm` architecture
needs to wait for a few more days, because there is currently no mirror that is suitable for the arm architecture.
1. Install docker
If your computer has not installed docker, you can follow the tutorial here to install
it:[Install docker](https://www.runoob.com/docker/ubuntu-docker-install.html)
2. Create a directory
After installation, you need to find a directory for the configuration file for this project. Let's call it the
`project directory` for the time being. This directory is preferably a newly created empty directory.
3. Download the configuration file
Open with a browser[This link](https://github.com/xinnan-tech/xiaozhi-esp32-server/blob/main/config.yaml)。
On the right side of the page, find the button named `RAW`, next to the `RAW` button, find the download icon, click the
Download button, and download the `config.yaml` file. Download the file to your `project directory`.
4. Configure Project
Modify the `config.yaml` file to configure the various parameters required for this project. The default LLM uses
`ChatGLMLLM`, you need to configure the key to start.
The default TTS uses `EdgeTTS`. This does not require configuration. If you need to replace it with`Doubao TTS`, you
need to
configure the key.
Configuration description: This is the default component of each function, such as LLM default to use the `ChatGLMLLM`
model. If you need to switch the model, it is the corresponding name.
The default configuration of this project is only the lowest operating cost configuration`glm-4-flash`and`EdgeTTS`are
free),If you need to be better and faster, you need to combine the use of the deployment environment to switch the use
of each component。
```
selected_module:
ASR: FunASR
VAD: SileroVAD
LLM: ChatGLMLLM
TTS: EdgeTTS
```
For example, modify the components used by `llm`, depending on which` llm` supports this project, as follows, it
supports `Deepseekllm` and` Chatglmllm`. You are modified to the corresponding LLM in `selectd_module`
```
LLM:
DeepSeekLLM:
...
ChatGLMLLM:
...
DifyLLM:
...
```
Some services, for example, if you use the TTS` of the `dify` and` bean bags, you need a key, remember to add the
configuration file!
5. Execute the docker command
Open the command line tool, `cd` enter your `project directory`, and execute the following command
```
#If you are Linux, execute
ls
#If you are Windows, execute
dir
```
If you can see the `config.yaml` file, you have indeed entered the `project directory`, and then execute the following
command:
```
docker run -d --name xiaozhi-esp32-server --restart always -p 8000:8000 -v ./config.yaml:/opt/xiaozhi-es32-server/config.yaml ccr.ccs.tencentyun.com/xinnan/xiaozhi-esp32-server:latest
```
If executed for the first time, it may take several minutes, and you have to be patient to wait for it to complete the
pull. After normal pulling is completed, you can execute the following command on the command line to see if the service
is started successfully.
```
docker ps
```
If you can see `xiaozhi-server`, it means that the service starts successfully. Then you can further execute the
following command to view the service log
```
docker logs -f xiaozhi-esp32-server
```
If you can see, similar to the following logs, it is a sign that the service of this project is successfully launched.
```
2025-xx-xx xx:51:59,492 - core.server - INFO - Server is running at ws://xx.xx.xx.xxx:8000
2025-xx-xx xx:51:59,516 - websockets.server - INFO - server listening on 0.0.0.0:8000
```
Next, you can start `compiling esp32 firmware`. Please go down and turn to the relevant chapter on
`compiling esp32 firmware`. So since you are deploying with docker, you have to check the IP of your native computer by
yourself.
Normally, assuming your ip is `192.168.1.25`, then your interface address is: `ws://192.168.1.25:8000`. This information
is very useful, and it is required to `compile esp32 firmware` later.
## Method 2 : Local Source Code Deployment
### 1.Install Prerequisites
Requires `Python` and `Conda` environments:
This project relies on `ffmpeg`, `libopus-dev`, and `conda`. After installation, it starts executing the following
commands.
```
conda remove -n xiaozhi-esp32-server --all -y
@@ -74,6 +184,7 @@ conda activate xiaozhi-esp32-server
### 2.Install Dependencies
```
# Clone the project
cd xiaozhi-esp32-server
conda activate xiaozhi-esp32-server
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
@@ -129,6 +240,8 @@ configuration file!
Run the Project
```
# Make sure to execute in the root directory of this project
conda activate xiaozhi-esp32-server
python app.py
```
@@ -142,7 +255,7 @@ You'll see the WebSocket endpoint in logs:
Among them, the `ws://192.168.1.25:8000` is the interface address provided by this project. Of course, your own machine
is different from mine. Remember to find your own address.
### 6.Compile ESP32 Firmware
# Compile ESP32 Firmware
1. Download `xiaozhi-esp32` project, configure the project environment according to this
tutorial [" Windows builds ESP IDF 5.3.2 Development Environment and Compiles Xiaozhi "](https://icnynnzcwou8.feishu.cn/wiki/JEYDwTTALi5s2zkGlFGcDiRknXf)
@@ -240,13 +353,15 @@ Suggestion: In the configuration file, set the `LLM` to`DifyLLM`, and then arran
## 5、I said very slowly, I paused, Xiaozhi always grabbed me, what to do.
Suggestion: In the configuration file, find this section, change the `min_silence_duration_ms` value, such as change to` 1000`.
Suggestion: In the configuration file, find this section, change the `min_silence_duration_ms` value, such as change to
` 1000`.
```
VAD:
SileroVAD:
threshold: 0.5
model_dir: models/snakers4_silero-vad
min_silence_duration_ms: 300 # 如果说话停顿比较长,可以把这个值设置大一些
min_silence_duration_ms: 700 # 如果说话停顿比较长,可以把这个值设置大一些
```
## 6、For more questions, contact us to feedback
+1
View File
@@ -54,6 +54,7 @@ LLM:
api_key: 你的bigmodel api key
DifyLLM:
# 建议使用本地部署的dify接口,国内部分区域访问dify公有云接口可能会受限
# 如果使用DifyLLM,配置文件里prompt(提示词)是无效的,需要在dify控制台设置提示词
base_url: 你的私有化部署的dify接口地址
api_key: 你的dify api key
TTS:
+6 -6
View File
@@ -5,7 +5,7 @@ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin
```
2、编译docker镜像
```
# 普通运行
# 普通编译
docker build -t xiaozhi-esp32-server:local -f ./Dockerfile .
```
3、测试本地镜像
@@ -13,9 +13,11 @@ docker build -t xiaozhi-esp32-server:local -f ./Dockerfile .
docker stop xiaozhi-esp32-server
docker rm xiaozhi-esp32-server
docker run -d --name xiaozhi-esp32-server -p 8000:8000 xiaozhi-esp32-server:local
# 或者挂载本地目录,方便更新代码
docker run -d --name xiaozhi-esp32-server -p 8000:8000 -v /home/system/xiaozhi-esp32-server:/opt/xiaozhi-esp32-server xiaozhi-esp32-server:local
cp /Users/hrz/myworkspace/esp32/xiaozhi-esp32-server/config.yaml ./
docker run -d --name xiaozhi-esp32-server --restart always -p 8000:8000 -v ./config.yaml:/opt/xiaozhi-es32-server/config.yaml xiaozhi-esp32-server:local
docker logs -f xiaozhi-esp32-server
```
5、发布腾讯云镜像
```
@@ -42,6 +44,4 @@ docker manifest push ccr.ccs.tencentyun.com/xinnan/xiaozhi-esp32-server:latest
6、运行线上镜像
```
docker run -d --name xiaozhi-esp32-server --restart unless-stopped -p 8000:8000 ccr.ccs.tencentyun.com/xinnan/xiaozhi-esp32-server:latest-amd64
# 或者挂载本地目录,方便更新代码
docker run -d --name xiaozhi-esp32-server --restart unless-stopped -p 8000:8000 -v /home/system/xiaozhi-esp32-server:/opt/xiaozhi-esp32-server ccr.ccs.tencentyun.com/xinnan/xiaozhi-esp32-server:latest-amd64
```