From 26763318045bddbbe048b11b25b17a5f77c67f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A3=E5=8D=97=E7=A7=91=E6=8A=80?= Date: Thu, 6 Mar 2025 10:55:01 +0800 Subject: [PATCH 1/6] Fix docker config bug (#217) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixed:兼容旧版本docker * update:增加前端设计图 * update:dockerfile --------- Co-authored-by: hrz <1710360675@qq.com> --- Dockerfile | 29 +++++++++++++++++++++++++++++ main/README.md | 1 + 2 files changed, 30 insertions(+) create mode 100755 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 000000000..aaa431037 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# 第一阶段:构建Python依赖 +FROM python:3.10-slim AS builder + +WORKDIR /app + +COPY main/xiaozhi-server/requirements.txt . + +# 优化apt安装 +RUN pip install --no-cache-dir -r requirements.txt + +# 第三阶段:生产镜像 +FROM python:3.10-slim + +WORKDIR /opt/xiaozhi-esp32-server + +# 优化apt安装 +RUN apt-get update && \ + apt-get install -y --no-install-recommends libopus0 ffmpeg && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# 从构建阶段复制Python包和前端构建产物 +COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages + +# 复制应用代码 +COPY main/xiaozhi-server/ . + +# 启动应用 +CMD ["python", "app.py"] \ No newline at end of file diff --git a/main/README.md b/main/README.md index 78c5f4a0c..2e1649546 100644 --- a/main/README.md +++ b/main/README.md @@ -20,3 +20,4 @@ xiaozhi-esp32-server [manager前后端接口协议](https://app.apifox.com/invite/project?token=H_8qhgfjUeaAL0wybghgU) +[前端页面设计图](https://codesign.qq.com/app/s/526108506410828) From 1f722477cefbbef798ce8bef200d4dd42e6d78aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A3=E5=8D=97=E7=A7=91=E6=8A=80?= Date: Thu, 6 Mar 2025 13:12:32 +0800 Subject: [PATCH 2/6] Fix docker config bug (#220) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixed:兼容旧版本docker * update:增加前端设计图 * update:dockerfile * fix:修复新版docker目录不对bug * fix: 修复docker快速启动方式中无法读取配置的问题 #207 (#219) Co-authored-by: 欣南科技 --------- Co-authored-by: hrz <1710360675@qq.com> Co-authored-by: yanyige <232218719@qq.com> --- main/xiaozhi-server/Dockerfile | 2 +- main/xiaozhi-server/Dockerfile-pip | 51 -------------------------- main/xiaozhi-server/docker-compose.yml | 4 +- 3 files changed, 3 insertions(+), 54 deletions(-) delete mode 100755 main/xiaozhi-server/Dockerfile-pip diff --git a/main/xiaozhi-server/Dockerfile b/main/xiaozhi-server/Dockerfile index cd1fef9ee..3ca8ed29b 100644 --- a/main/xiaozhi-server/Dockerfile +++ b/main/xiaozhi-server/Dockerfile @@ -1,7 +1,7 @@ # 第一阶段:构建 Python 依赖 FROM kalicyh/poetry:v3.10_xiaozhi AS builder -WORKDIR /app +WORKDIR /opt/xiaozhi-esp32-server # 同时拷贝本地环境.venv COPY . . diff --git a/main/xiaozhi-server/Dockerfile-pip b/main/xiaozhi-server/Dockerfile-pip deleted file mode 100755 index c8f484981..000000000 --- a/main/xiaozhi-server/Dockerfile-pip +++ /dev/null @@ -1,51 +0,0 @@ -# 第一阶段:前端构建 -FROM node:18 AS frontend-builder - -WORKDIR /app/web - -# 配置npm使用淘宝源 -RUN npm config set registry https://registry.npmmirror.com - -COPY web/package*.json ./ - -# 安装axios依赖 -RUN npm install axios -RUN npm install - -COPY web . - -RUN npm run build - -# 第二阶段:构建Python依赖 -FROM python:3.10-slim AS builder - -WORKDIR /app - -COPY requirements.txt . - -# 优化apt安装 -RUN pip install --no-cache-dir -r requirements.txt \ - -i https://mirrors.aliyun.com/pypi/simple/ - -# 第三阶段:生产镜像 -FROM python:3.10-slim - -WORKDIR /opt/xiaozhi-esp32-server - -# 优化apt安装 -RUN echo "deb https://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \ - echo "deb https://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ - apt-get update && \ - apt-get install -y --no-install-recommends libopus0 ffmpeg && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -# 从构建阶段复制Python包和前端构建产物 -COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages -COPY --from=frontend-builder /app/web/dist /opt/xiaozhi-esp32-server/manager/static/webui - -# 复制应用代码 -COPY . . - -# 启动应用 -CMD ["python", "app.py"] \ No newline at end of file diff --git a/main/xiaozhi-server/docker-compose.yml b/main/xiaozhi-server/docker-compose.yml index 32ebcdf69..f9c08ab41 100755 --- a/main/xiaozhi-server/docker-compose.yml +++ b/main/xiaozhi-server/docker-compose.yml @@ -13,6 +13,6 @@ services: - "8002:8002" volumes: # 配置文件目录 - - ./data:/app/data + - ./data:/opt/xiaozhi-esp32-server/data # 模型文件挂接,很重要 - - ./models/SenseVoiceSmall/model.pt:/app/models/SenseVoiceSmall/model.pt \ No newline at end of file + - ./models/SenseVoiceSmall/model.pt:/opt/xiaozhi-esp32-server/models/SenseVoiceSmall/model.pt \ No newline at end of file From 76c16ad16eed609778cf3162b5c06a7f2e263464 Mon Sep 17 00:00:00 2001 From: zhisheng Date: Thu, 6 Mar 2025 23:31:23 +0800 Subject: [PATCH 3/6] fix manager-api bug (#223) --- .../src/main/java/xiaozhi/common/exception/ErrorCode.java | 5 +++++ .../java/xiaozhi/modules/sys/service/SysDictTypeService.java | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/main/manager-api/src/main/java/xiaozhi/common/exception/ErrorCode.java b/main/manager-api/src/main/java/xiaozhi/common/exception/ErrorCode.java index 22fd6100a..ffa78cf56 100644 --- a/main/manager-api/src/main/java/xiaozhi/common/exception/ErrorCode.java +++ b/main/manager-api/src/main/java/xiaozhi/common/exception/ErrorCode.java @@ -35,4 +35,9 @@ public interface ErrorCode { int REDIS_ERROR = 10027; int JOB_ERROR = 10028; int INVALID_SYMBOL = 10029; + + + int PASSWORD_LENGTH_ERROR = 10030; + int PASSWORD_WEAK_ERROR = 10031; + int DEL_MYSELF_ERROR = 10032; } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/sys/service/SysDictTypeService.java b/main/manager-api/src/main/java/xiaozhi/modules/sys/service/SysDictTypeService.java index 0b4b51507..29906afbb 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/sys/service/SysDictTypeService.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/sys/service/SysDictTypeService.java @@ -23,4 +23,8 @@ public interface SysDictTypeService extends BaseService { void update(SysDictTypeDTO dto); void delete(Long[] ids); + + List getAllList(); + + List getDictTypeList(); } \ No newline at end of file From 0b7abfae3a650143e827fff4d54d481bec061309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A3=E5=8D=97=E7=A7=91=E6=8A=80?= Date: Fri, 7 Mar 2025 01:20:39 +0800 Subject: [PATCH 4/6] =?UTF-8?q?update:=E4=BC=98=E5=8C=96docker=E6=97=B6?= =?UTF-8?q?=E5=8C=BA=20(#225)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: hrz <1710360675@qq.com> --- main/xiaozhi-server/docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main/xiaozhi-server/docker-compose.yml b/main/xiaozhi-server/docker-compose.yml index f9c08ab41..80349bb49 100755 --- a/main/xiaozhi-server/docker-compose.yml +++ b/main/xiaozhi-server/docker-compose.yml @@ -6,6 +6,8 @@ services: restart: always security_opt: - seccomp:unconfined + environment: + - TZ=Asia/Shanghai ports: # ws服务端 - "8000:8000" From 9929af617c607b18834f1a95a09af7d87dee74fc Mon Sep 17 00:00:00 2001 From: Ken Date: Fri, 7 Mar 2025 11:31:53 +0800 Subject: [PATCH 5/6] =?UTF-8?q?aliyunTTS=E5=B8=B8=E8=81=94token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/config.yaml | 3 + .../core/providers/tts/aliyun.py | 69 ++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/main/xiaozhi-server/config.yaml b/main/xiaozhi-server/config.yaml index f795d8c79..8b122cb33 100644 --- a/main/xiaozhi-server/config.yaml +++ b/main/xiaozhi-server/config.yaml @@ -298,6 +298,9 @@ TTS: appkey: 你的阿里云智能语音交互服务项目Appkey token: 你的阿里云智能语音交互服务AccessToken voice: xiaoyun + access_key_id: 你的阿里云账号access_key_id + access_key_secret: 你的阿里云账号access_key_secret + # 以下可不用设置,使用默认设置 # format: wav # sample_rate: 16000 diff --git a/main/xiaozhi-server/core/providers/tts/aliyun.py b/main/xiaozhi-server/core/providers/tts/aliyun.py index 854e61280..12f214a2c 100644 --- a/main/xiaozhi-server/core/providers/tts/aliyun.py +++ b/main/xiaozhi-server/core/providers/tts/aliyun.py @@ -1,19 +1,86 @@ import os import uuid import json +import hmac +import hashlib +import base64 import requests from datetime import datetime from core.providers.tts.base import TTSProviderBase import http.client import urllib.parse +import time +import uuid +from urllib import parse +class AccessToken: + @staticmethod + def _encode_text(text): + encoded_text = parse.quote_plus(text) + return encoded_text.replace('+', '%20').replace('*', '%2A').replace('%7E', '~') + + @staticmethod + def _encode_dict(dic): + keys = dic.keys() + dic_sorted = [(key, dic[key]) for key in sorted(keys)] + encoded_text = parse.urlencode(dic_sorted) + return encoded_text.replace('+', '%20').replace('*', '%2A').replace('%7E', '~') + + @staticmethod + def create_token(access_key_id, access_key_secret): + parameters = {'AccessKeyId': access_key_id, + 'Action': 'CreateToken', + 'Format': 'JSON', + 'RegionId': 'cn-shanghai', + 'SignatureMethod': 'HMAC-SHA1', + 'SignatureNonce': str(uuid.uuid1()), + 'SignatureVersion': '1.0', + 'Timestamp': time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), + 'Version': '2019-02-28'} + # 构造规范化的请求字符串 + query_string = AccessToken._encode_dict(parameters) + print('规范化的请求字符串: %s' % query_string) + # 构造待签名字符串 + string_to_sign = 'GET' + '&' + AccessToken._encode_text('/') + '&' + AccessToken._encode_text(query_string) + print('待签名的字符串: %s' % string_to_sign) + # 计算签名 + secreted_string = hmac.new(bytes(access_key_secret + '&', encoding='utf-8'), + bytes(string_to_sign, encoding='utf-8'), + hashlib.sha1).digest() + signature = base64.b64encode(secreted_string) + print('签名: %s' % signature) + # 进行URL编码 + signature = AccessToken._encode_text(signature) + print('URL编码后的签名: %s' % signature) + # 调用服务 + full_url = 'http://nls-meta.cn-shanghai.aliyuncs.com/?Signature=%s&%s' % (signature, query_string) + print('url: %s' % full_url) + # 提交HTTP GET请求 + response = requests.get(full_url) + if response.ok: + root_obj = response.json() + key = 'Token' + if key in root_obj: + token = root_obj[key]['Id'] + expire_time = root_obj[key]['ExpireTime'] + return token, expire_time + print(response.text) + return None, None class TTSProvider(TTSProviderBase): + + def __init__(self, config, delete_audio_file): super().__init__(config, delete_audio_file) + + access_key_id = config.get("access_key_id") # 从环境变量读取 AccessKey ID + access_key_secret = config.get("access_key_secret") # 从环境变量读取 AccessKey Secret + token, expire_time = AccessToken.create_token(access_key_id, access_key_secret) + print('token: %s, expire time(s): %s' % (token, expire_time)) + self.appkey = config.get("appkey") - self.token = config.get("token") + self.token = token self.format = config.get("format", "wav") self.sample_rate = config.get("sample_rate", 16000) self.voice = config.get("voice", "xiaoyun") From dab0b60df93dd452cf32a35524e5e4922e47c53a Mon Sep 17 00:00:00 2001 From: Ken Date: Fri, 7 Mar 2025 13:41:12 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=96=B0=E5=A2=9EaliyunTTS=E9=95=BF?= =?UTF-8?q?=E6=9C=9FToken=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/config.yaml | 2 +- main/xiaozhi-server/core/providers/tts/aliyun.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/main/xiaozhi-server/config.yaml b/main/xiaozhi-server/config.yaml index 8b122cb33..b3bca9329 100644 --- a/main/xiaozhi-server/config.yaml +++ b/main/xiaozhi-server/config.yaml @@ -296,7 +296,7 @@ TTS: type: aliyun output_file: tmp/ appkey: 你的阿里云智能语音交互服务项目Appkey - token: 你的阿里云智能语音交互服务AccessToken + token: 你的阿里云智能语音交互服务AccessToken,临时的24小时,要长期用下方的access_key_id,access_key_secret voice: xiaoyun access_key_id: 你的阿里云账号access_key_id access_key_secret: 你的阿里云账号access_key_secret diff --git a/main/xiaozhi-server/core/providers/tts/aliyun.py b/main/xiaozhi-server/core/providers/tts/aliyun.py index 12f214a2c..ea8627be9 100644 --- a/main/xiaozhi-server/core/providers/tts/aliyun.py +++ b/main/xiaozhi-server/core/providers/tts/aliyun.py @@ -73,10 +73,18 @@ class TTSProvider(TTSProviderBase): def __init__(self, config, delete_audio_file): super().__init__(config, delete_audio_file) - - access_key_id = config.get("access_key_id") # 从环境变量读取 AccessKey ID - access_key_secret = config.get("access_key_secret") # 从环境变量读取 AccessKey Secret - token, expire_time = AccessToken.create_token(access_key_id, access_key_secret) + + # 新增空值判断逻辑 + access_key_id = config.get("access_key_id") + access_key_secret = config.get("access_key_secret") + if access_key_id and access_key_secret: + # 使用密钥对生成临时token + token, expire_time = AccessToken.create_token(access_key_id, access_key_secret) + else: + # 直接使用预生成的长期token + token = config.get("token") + expire_time = None + print('token: %s, expire time(s): %s' % (token, expire_time)) self.appkey = config.get("appkey")