From effd79b4651af4c7b4d559862232acdd3b1a9967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AC=A3=E5=8D=97=E7=A7=91=E6=8A=80?= Date: Sun, 2 Mar 2025 16:59:25 +0800 Subject: [PATCH] Tts302 (#170) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add 302.ai TTS integration (#166) * update:将tts_302ai tts合并到doubao tts --------- Co-authored-by: Junsen <66542771+Huang-junsen@users.noreply.github.com> Co-authored-by: hrz <1710360675@qq.com> --- README.md | 17 +++++++++++++---- config.yaml | 15 ++++++++++++++- core/connection.py | 2 +- core/providers/tts/doubao.py | 7 +++---- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 820bb861..a0f6c4f1 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 fab43d03..ce065b17 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 @@ -305,7 +307,18 @@ TTS: # volume: 50 # speech_rate: 0 # pitch_rate: 0 - + # 添加 302.ai TTS 配置 + # token申请地址:https://dash.302.ai/ + TTS302AI: + # 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密钥" # 模块测试配置 module_test: test_sentences: # 自定义测试语句 diff --git a/core/connection.py b/core/connection.py index e463684b..5532e3a1 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 74ddde2a..3b812131 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}")