From a0274e83fb01644eacc946d1651ce34676939d3a Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Sun, 2 Mar 2025 16:58:42 +0800 Subject: [PATCH] =?UTF-8?q?update:=E5=B0=86tts=5F302ai=20tts=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E5=88=B0doubao=20tts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 17 +++++++++--- config.yaml | 13 +++++++-- core/connection.py | 2 +- core/providers/tts/doubao.py | 7 ++--- core/providers/tts/tts_302ai.py | 49 --------------------------------- 5 files changed, 27 insertions(+), 61 deletions(-) delete mode 100644 core/providers/tts/tts_302ai.py diff --git a/README.md b/README.md index 820bb861f..a0f6c4f1c 100644 --- a/README.md +++ b/README.md @@ -75,16 +75,23 @@ - **硬件**:一套兼容 `xiaozhi-esp32` 的硬件设备(具体型号请参考 [此处](https://rcnv1t9vps13.feishu.cn/wiki/DdgIw4BUgivWDPkhMj1cGIYCnRf))。 -- **服务器**:至少 4 核 CPU、8G 内存的电脑。 -- **固件编译**:请将后端服务的接口地址更新至 `xiaozhi-esp32` 项目中,再重新编译固件并烧录到设备上。 + +- **电脑或服务器**:至少 4 核 CPU、8G 内存的电脑。 +- **固件编译**:请将本后端服务的接口地址更新至 `xiaozhi-esp32` 项目中,再重新编译`xiaozhi-esp32`固件并烧录到设备上。 + +如果你没有esp32相关的硬件设备,但是非常想体验该项目,可以使用以下的项目让你的电脑、手机模拟成esp32设备。 + +- [小智安卓端](https://github.com/TOM88812/xiaozhi-android-client) +- [小智电脑端](https://github.com/Huang-junsen/py-xiaozhi) --- ## 警告 ⚠️ -本项目成立时间较短,还未通过网络安全测评,请勿在生产环境中使用。 +1、本项目为开源软件,本软件与对接的任何第三方API服务商(包括但不限于语音识别、大模型、语音合成等平台)均不存在商业合作关系,不为其服务质量及资金安全提供任何形式的担保。 +建议使用者优先选择持有相关业务牌照的服务商,并仔细阅读其服务协议及隐私政策。本软件不托管任何账户密钥、不参与资金流转、不承担充值资金损失风险。 -如果您在公网环境中部署学习本项目,请务必在配置文件 `config.yaml` 中开启防护: +2、本项目成立时间较短,还未通过网络安全测评,请勿在生产环境中使用。 如果您在公网环境中部署学习本项目,请务必在配置文件 `config.yaml` 中开启防护: ```yaml server: @@ -305,9 +312,11 @@ TTS 性能排行: 我们的联系方式放在[百度网盘中,点击前往](https://pan.baidu.com/s/1x6USjvP1nTRsZ45XlJu65Q),提取码是`223y`。 网盘里有“硬件烧录QQ群”、“开源服务端交流群”、“产品建议联系人” 三张图片,请根据需要选择加入。 + - 硬件烧录QQ群:适用于硬件烧录问题 - 开源服务端交流群:适用于服务端问题 - 产品建议联系人:适用于产品功能、产品设计等建议 + --- ## 鸣谢 🙏 diff --git a/config.yaml b/config.yaml index 4214ad98d..ce065b175 100644 --- a/config.yaml +++ b/config.yaml @@ -175,8 +175,10 @@ TTS: # 山引擎语音一定要购买花钱,起步价30元,就有100并发了。如果用免费的只有2个并发,会经常报tts错误 # 购买服务后,购买免费的音色后,可能要等半小时左右,才能使用。 # 地址:https://console.volcengine.com/speech/service/8 + api_url: https://openspeech.bytedance.com/api/v1/tts voice: BV001_streaming output_file: tmp/ + authorization: "Bearer;" appid: 你的火山引擎语音合成服务appid access_token: 你的火山引擎语音合成服务access_token cluster: volcano_tts @@ -308,10 +310,15 @@ TTS: # 添加 302.ai TTS 配置 # token申请地址:https://dash.302.ai/ TTS302AI: - type: tts_302ai # 对应 tts_302ai.py 文件名 - voice: "zh_female_wanwanxiaohe_moon_bigtts" # 默认语音类型 + # 302AI语音合成服务,需要先在302平台创建账户充值,并获取密钥信息 + # 获取api_keyn路径:https://dash.302.ai/apis/list + # 价格,$35/百万字符。火山原版¥450元/万字符 + type: doubao + api_url: https://api.302ai.cn/doubao/tts_hd + authorization: "Bearer " + voice: "zh_female_wanwanxiaohe_moon_bigtts" output_file: tmp/ - access_token: "你的302API密钥" # 您的 302.ai 访问令牌 + access_token: "你的302API密钥" # 模块测试配置 module_test: test_sentences: # 自定义测试语句 diff --git a/core/connection.py b/core/connection.py index e463684bc..5532e3a1a 100644 --- a/core/connection.py +++ b/core/connection.py @@ -234,7 +234,7 @@ class ConnectionHandler: current_text = full_text[processed_chars:] # 从未处理的位置开始 # 查找最后一个有效标点 - punctuations = ("。", "?", "!", ".", "?", "!", ";", ";", ":", ":", ",", ",") + punctuations = ("。", "?", "!", "?", "!", ";", ";", ":", ":", ",") last_punct_pos = -1 for punct in punctuations: pos = current_text.rfind(punct) diff --git a/core/providers/tts/doubao.py b/core/providers/tts/doubao.py index 74ddde2aa..3b812131a 100644 --- a/core/providers/tts/doubao.py +++ b/core/providers/tts/doubao.py @@ -14,10 +14,9 @@ class TTSProvider(TTSProviderBase): self.access_token = config.get("access_token") self.cluster = config.get("cluster") self.voice = config.get("voice") - - self.host = "openspeech.bytedance.com" - self.api_url = f"https://{self.host}/api/v1/tts" - self.header = {"Authorization": f"Bearer;{self.access_token}"} + self.api_url = config.get("api_url") + self.authorization = config.get("authorization") + self.header = {"Authorization": f"{self.authorization}{self.access_token}"} def generate_filename(self, extension=".wav"): return os.path.join(self.output_file, f"tts-{datetime.now().date()}@{uuid.uuid4().hex}{extension}") diff --git a/core/providers/tts/tts_302ai.py b/core/providers/tts/tts_302ai.py deleted file mode 100644 index 599f6d04d..000000000 --- a/core/providers/tts/tts_302ai.py +++ /dev/null @@ -1,49 +0,0 @@ -import os -import uuid -import base64 -import requests -from datetime import datetime -from core.providers.tts.base import TTSProviderBase - - -class TTSProvider(TTSProviderBase): - def __init__(self, config, delete_audio_file): - super().__init__(config, delete_audio_file) - self.access_token = config.get("access_token") - self.voice = config.get("voice", "zh_female_wanwanxiaohe_moon_bigtts") - - # self.api_url = "https://api.302.ai/doubao/tts_hd" 国外 - self.api_url = "https://api.302ai.cn/doubao/tts_hd" #国内中转 - self.header = { - "Content-Type": "application/json", - "Authorization": f"Bearer {self.access_token}" - } - - def generate_filename(self, extension=".wav"): - return os.path.join(self.output_file, f"tts-{datetime.now().date()}@{uuid.uuid4().hex}{extension}") - - async def text_to_speak(self, text, output_file): - - request_json = { - "audio": { - "voice_type": self.voice, - "encoding": "wav", - "speed_ratio": 1.0 - }, - "request": { - "reqid": str(uuid.uuid4()), - "text": text, - "operation": "query" - } - } - print("执行", text,request_json) - try: - resp = requests.post(self.api_url, json=request_json, headers=self.header) - if resp.status_code == 200 and "data" in resp.json(): - data = resp.json()["data"] - with open(output_file, "wb") as file_to_save: - file_to_save.write(base64.b64decode(data)) - else: - raise Exception(f"{__name__} status_code: {resp.status_code} response: {resp.content}") - except Exception as e: - raise Exception(f"{__name__} error: {e}")