mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
update:将tts_302ai tts合并到doubao tts
This commit is contained in:
parent
781a24516f
commit
a0274e83fb
5 changed files with 27 additions and 61 deletions
17
README.md
17
README.md
|
|
@ -75,16 +75,23 @@
|
||||||
|
|
||||||
- **硬件**:一套兼容 `xiaozhi-esp32`
|
- **硬件**:一套兼容 `xiaozhi-esp32`
|
||||||
的硬件设备(具体型号请参考 [此处](https://rcnv1t9vps13.feishu.cn/wiki/DdgIw4BUgivWDPkhMj1cGIYCnRf))。
|
的硬件设备(具体型号请参考 [此处](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
|
```yaml
|
||||||
server:
|
server:
|
||||||
|
|
@ -305,9 +312,11 @@ TTS 性能排行:
|
||||||
我们的联系方式放在[百度网盘中,点击前往](https://pan.baidu.com/s/1x6USjvP1nTRsZ45XlJu65Q),提取码是`223y`。
|
我们的联系方式放在[百度网盘中,点击前往](https://pan.baidu.com/s/1x6USjvP1nTRsZ45XlJu65Q),提取码是`223y`。
|
||||||
|
|
||||||
网盘里有“硬件烧录QQ群”、“开源服务端交流群”、“产品建议联系人” 三张图片,请根据需要选择加入。
|
网盘里有“硬件烧录QQ群”、“开源服务端交流群”、“产品建议联系人” 三张图片,请根据需要选择加入。
|
||||||
|
|
||||||
- 硬件烧录QQ群:适用于硬件烧录问题
|
- 硬件烧录QQ群:适用于硬件烧录问题
|
||||||
- 开源服务端交流群:适用于服务端问题
|
- 开源服务端交流群:适用于服务端问题
|
||||||
- 产品建议联系人:适用于产品功能、产品设计等建议
|
- 产品建议联系人:适用于产品功能、产品设计等建议
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 鸣谢 🙏
|
## 鸣谢 🙏
|
||||||
|
|
|
||||||
13
config.yaml
13
config.yaml
|
|
@ -175,8 +175,10 @@ TTS:
|
||||||
# 山引擎语音一定要购买花钱,起步价30元,就有100并发了。如果用免费的只有2个并发,会经常报tts错误
|
# 山引擎语音一定要购买花钱,起步价30元,就有100并发了。如果用免费的只有2个并发,会经常报tts错误
|
||||||
# 购买服务后,购买免费的音色后,可能要等半小时左右,才能使用。
|
# 购买服务后,购买免费的音色后,可能要等半小时左右,才能使用。
|
||||||
# 地址:https://console.volcengine.com/speech/service/8
|
# 地址:https://console.volcengine.com/speech/service/8
|
||||||
|
api_url: https://openspeech.bytedance.com/api/v1/tts
|
||||||
voice: BV001_streaming
|
voice: BV001_streaming
|
||||||
output_file: tmp/
|
output_file: tmp/
|
||||||
|
authorization: "Bearer;"
|
||||||
appid: 你的火山引擎语音合成服务appid
|
appid: 你的火山引擎语音合成服务appid
|
||||||
access_token: 你的火山引擎语音合成服务access_token
|
access_token: 你的火山引擎语音合成服务access_token
|
||||||
cluster: volcano_tts
|
cluster: volcano_tts
|
||||||
|
|
@ -308,10 +310,15 @@ TTS:
|
||||||
# 添加 302.ai TTS 配置
|
# 添加 302.ai TTS 配置
|
||||||
# token申请地址:https://dash.302.ai/
|
# token申请地址:https://dash.302.ai/
|
||||||
TTS302AI:
|
TTS302AI:
|
||||||
type: tts_302ai # 对应 tts_302ai.py 文件名
|
# 302AI语音合成服务,需要先在302平台创建账户充值,并获取密钥信息
|
||||||
voice: "zh_female_wanwanxiaohe_moon_bigtts" # 默认语音类型
|
# 获取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/
|
output_file: tmp/
|
||||||
access_token: "你的302API密钥" # 您的 302.ai 访问令牌
|
access_token: "你的302API密钥"
|
||||||
# 模块测试配置
|
# 模块测试配置
|
||||||
module_test:
|
module_test:
|
||||||
test_sentences: # 自定义测试语句
|
test_sentences: # 自定义测试语句
|
||||||
|
|
|
||||||
|
|
@ -234,7 +234,7 @@ class ConnectionHandler:
|
||||||
current_text = full_text[processed_chars:] # 从未处理的位置开始
|
current_text = full_text[processed_chars:] # 从未处理的位置开始
|
||||||
|
|
||||||
# 查找最后一个有效标点
|
# 查找最后一个有效标点
|
||||||
punctuations = ("。", "?", "!", ".", "?", "!", ";", ";", ":", ":", ",", ",")
|
punctuations = ("。", "?", "!", "?", "!", ";", ";", ":", ":", ",")
|
||||||
last_punct_pos = -1
|
last_punct_pos = -1
|
||||||
for punct in punctuations:
|
for punct in punctuations:
|
||||||
pos = current_text.rfind(punct)
|
pos = current_text.rfind(punct)
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,9 @@ class TTSProvider(TTSProviderBase):
|
||||||
self.access_token = config.get("access_token")
|
self.access_token = config.get("access_token")
|
||||||
self.cluster = config.get("cluster")
|
self.cluster = config.get("cluster")
|
||||||
self.voice = config.get("voice")
|
self.voice = config.get("voice")
|
||||||
|
self.api_url = config.get("api_url")
|
||||||
self.host = "openspeech.bytedance.com"
|
self.authorization = config.get("authorization")
|
||||||
self.api_url = f"https://{self.host}/api/v1/tts"
|
self.header = {"Authorization": f"{self.authorization}{self.access_token}"}
|
||||||
self.header = {"Authorization": f"Bearer;{self.access_token}"}
|
|
||||||
|
|
||||||
def generate_filename(self, extension=".wav"):
|
def generate_filename(self, extension=".wav"):
|
||||||
return os.path.join(self.output_file, f"tts-{datetime.now().date()}@{uuid.uuid4().hex}{extension}")
|
return os.path.join(self.output_file, f"tts-{datetime.now().date()}@{uuid.uuid4().hex}{extension}")
|
||||||
|
|
|
||||||
|
|
@ -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}")
|
|
||||||
Loading…
Reference in a new issue