mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-23 23:53:55 +08:00
+2








dd5fecdf5a
* 新增openai tts (#137) On branch openai_tts Changes to be committed: modified: config.yaml new file: core/providers/tts/openai_tts.py Co-authored-by: 欣南科技 <huangrongzhuang@xin-nan.com> * Update config.yaml (#201) * 修改了coze的实现方式,使用了v3接口,修复了只能对话一次的bug * 使用mem0ai api实现记忆功能 * Fix docker space (#179) * update:调试docker编译缓存 * update:调试docker编译 * update:调试docker编译容量 * update:调试docker编译 --------- Co-authored-by: hrz <1710360675@qq.com> * TTS处理增加index信息,完善TTS出错时的处理 (#177) * TTS处理增加index信息,完善TTS出错时的处理 * 第一句语音index处理,歌曲播放index处理 * update:去掉了无用变量,修复continuebug --------- Co-authored-by: hrz <1710360675@qq.com> * update:更新demo (#180) Co-authored-by: hrz <1710360675@qq.com> * 优化chat中异步调用方式 * 记忆增加时间,以便大模型判断先后关系 * 记忆对时间戳排序,便于梳理前后关系 * add: 不跟踪music下的文件的更改 (#187) * Mem0ai (#199) * update:增加mem0ai包依赖 * update:文档增加mem0ai的描述 --------- Co-authored-by: hrz <1710360675@qq.com> * Update config.yaml * Update config.yaml * Update config.yaml * Update config.yaml --------- Co-authored-by: strix214 <a1425699467@gmail.com> Co-authored-by: 玄凤科技 <eric230308@gmail.com> Co-authored-by: HonestQiao <honestqiao@163.com> Co-authored-by: 欣南科技 <huangrongzhuang@xin-nan.com> Co-authored-by: hrz <1710360675@qq.com> Co-authored-by: TOM88812 <ttangxs0808@163.com> Co-authored-by: 香草味的纳西妲 <151599587+NyaOH-Nahida@users.noreply.github.com> * update:添加忽略文件 * feat: 增加fastgpt适配:支持think、variables参数 (#213) * 修改了coze的实现方式,使用了v3接口,修复了只能对话一次的bug * 使用mem0ai api实现记忆功能 * Fix docker space (#179) * update:调试docker编译缓存 * update:调试docker编译 * update:调试docker编译容量 * update:调试docker编译 --------- Co-authored-by: hrz <1710360675@qq.com> * TTS处理增加index信息,完善TTS出错时的处理 (#177) * TTS处理增加index信息,完善TTS出错时的处理 * 第一句语音index处理,歌曲播放index处理 * update:去掉了无用变量,修复continuebug --------- Co-authored-by: hrz <1710360675@qq.com> * update:更新demo (#180) Co-authored-by: hrz <1710360675@qq.com> * 优化chat中异步调用方式 * 记忆增加时间,以便大模型判断先后关系 * 记忆对时间戳排序,便于梳理前后关系 * add: 不跟踪music下的文件的更改 (#187) * Mem0ai (#199) * update:增加mem0ai包依赖 * update:文档增加mem0ai的描述 --------- Co-authored-by: hrz <1710360675@qq.com> * feat: 增加fastgpt适配:支持think、variables参数 --------- Co-authored-by: strix214 <a1425699467@gmail.com> Co-authored-by: 玄凤科技 <eric230308@gmail.com> Co-authored-by: HonestQiao <honestqiao@163.com> Co-authored-by: 欣南科技 <huangrongzhuang@xin-nan.com> Co-authored-by: hrz <1710360675@qq.com> Co-authored-by: TOM88812 <ttangxs0808@163.com> Co-authored-by: 香草味的纳西妲 <151599587+NyaOH-Nahida@users.noreply.github.com> Co-authored-by: pt <ptsghs@163.com> * update:合并最新代码 * update:合并群友pr * update:openaitts 测试通过 * update:ACGNTTS测试完成 --------- Co-authored-by: Chris <119588753+Chris-websketch@users.noreply.github.com> Co-authored-by: ikun441 <3497689533@qq.com> Co-authored-by: strix214 <a1425699467@gmail.com> Co-authored-by: 玄凤科技 <eric230308@gmail.com> Co-authored-by: HonestQiao <honestqiao@163.com> Co-authored-by: hrz <1710360675@qq.com> Co-authored-by: TOM88812 <ttangxs0808@163.com> Co-authored-by: 香草味的纳西妲 <151599587+NyaOH-Nahida@users.noreply.github.com> Co-authored-by: ptisnoob <49125305+ptisnoob@users.noreply.github.com> Co-authored-by: pt <ptsghs@163.com>
63 lines
2.2 KiB
Python
63 lines
2.2 KiB
Python
import os
|
|
import uuid
|
|
import json
|
|
import base64
|
|
import requests
|
|
from datetime import datetime
|
|
from core.utils.util import check_model_key
|
|
from core.providers.tts.base import TTSProviderBase
|
|
|
|
|
|
class TTSProvider(TTSProviderBase):
|
|
def __init__(self, config, delete_audio_file):
|
|
super().__init__(config, delete_audio_file)
|
|
self.appid = config.get("appid")
|
|
self.access_token = config.get("access_token")
|
|
self.cluster = config.get("cluster")
|
|
self.voice = config.get("voice")
|
|
self.api_url = config.get("api_url")
|
|
self.authorization = config.get("authorization")
|
|
self.header = {"Authorization": f"{self.authorization}{self.access_token}"}
|
|
check_model_key("TTS", 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 = {
|
|
"app": {
|
|
"appid": f"{self.appid}",
|
|
"token": "access_token",
|
|
"cluster": self.cluster
|
|
},
|
|
"user": {
|
|
"uid": "1"
|
|
},
|
|
"audio": {
|
|
"voice_type": self.voice,
|
|
"encoding": "wav",
|
|
"speed_ratio": 1.0,
|
|
"volume_ratio": 1.0,
|
|
"pitch_ratio": 1.0,
|
|
},
|
|
"request": {
|
|
"reqid": str(uuid.uuid4()),
|
|
"text": text,
|
|
"text_type": "plain",
|
|
"operation": "query",
|
|
"with_frontend": 1,
|
|
"frontend_type": "unitTson"
|
|
}
|
|
}
|
|
|
|
try:
|
|
resp = requests.post(self.api_url, json.dumps(request_json), headers=self.header)
|
|
if "data" in resp.json():
|
|
data = resp.json()["data"]
|
|
file_to_save = open(output_file, "wb")
|
|
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}")
|