Merge branch 'merge-old-pr' into main

This commit is contained in:
欣南科技 2025-03-07 11:17:55 +08:00 committed by GitHub
commit 29871c2eba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 71 additions and 1 deletions

2
.gitignore vendored
View file

@ -149,4 +149,6 @@ tmp
.private_config.yaml .private_config.yaml
.env.development .env.development
docker-compose.yml docker-compose.yml
main/manager-web/node_modules
main/xiaozhi-server/data
web/vue/node_modules web/vue/node_modules

View file

@ -323,9 +323,22 @@ TTS:
# volume: 50 # volume: 50
# speech_rate: 0 # speech_rate: 0
# pitch_rate: 0 # pitch_rate: 0
OpenAITTS:
# openai官方文本转语音服务,可支持全球大多数语种
type: openai_tts
api_key: 你的openai api key
# 国内需要使用代理
api_url: https://api.openai.com/v1/audio/speech
# 可选tts-1或tts-1-hd,tts-1速度更快tts-1-hd质量更好
model: tts-1
# 演讲者,可选alloy, echo, fable, onyx, nova, shimmer
voice: alloy
# 语速范围0.25-4.0
speed: 1
output_file: tmp/
TTS302AI:
# 添加 302.ai TTS 配置 # 添加 302.ai TTS 配置
# token申请地址:https://dash.302.ai/ # token申请地址:https://dash.302.ai/
TTS302AI:
# 302AI语音合成服务,需要先在302平台创建账户充值,并获取密钥信息 # 302AI语音合成服务,需要先在302平台创建账户充值,并获取密钥信息
# 获取api_keyn路径:https://dash.302.ai/apis/list # 获取api_keyn路径:https://dash.302.ai/apis/list
# 价格,$35/百万字符。火山原版¥450元/万字符 # 价格,$35/百万字符。火山原版¥450元/万字符
@ -335,6 +348,23 @@ TTS:
voice: "zh_female_wanwanxiaohe_moon_bigtts" voice: "zh_female_wanwanxiaohe_moon_bigtts"
output_file: tmp/ output_file: tmp/
access_token: "你的302API密钥" access_token: "你的302API密钥"
ACGNTTS:
#在线网址:https://acgn.ttson.cn/
#token购买:www.ttson.cn
#开发相关疑问请提交至3497689533@qq.com
#角色id获取地址:ctrl+f快速检索角色——网站管理者不允许发布,可询问网站管理者:1069379506
#各参数意义见开发文档:https://www.yuque.com/alexuh/skmti9/wm6taqislegb02gd?singleDoc#
type: ACGNTTS
token: "你的ACGNTTS密钥"
voice_id: 1695
speed_factor: 1
pitch_factor: 0
volume_change_dB: 0
to_lang: ZH
url: https://u95167-bd74-2aef8085.westx.seetacloud.com:8443/flashsummary/tts?token=
format: wav
output_file: tmp/
emotion: 1
# 模块测试配置 # 模块测试配置
module_test: module_test:
test_sentences: # 自定义测试语句 test_sentences: # 自定义测试语句

View file

@ -0,0 +1,38 @@
import os
import uuid
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.api_key = config.get("api_key")
self.api_url = config.get("api_url", "https://api.openai.com/v1/audio/speech")
self.model = config.get("model", "tts-1")
self.voice = config.get("voice", "alloy")
self.response_format = "wav"
self.speed = config.get("speed", 1.0)
self.output_file = config.get("output_file", "tmp/")
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):
headers = {
"Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json"
}
data = {
"model": self.model,
"input": text,
"voice": self.voice,
"response_format": "wav",
"speed": self.speed
}
response = requests.post(self.api_url, json=data, headers=headers)
if response.status_code == 200:
with open(output_file, "wb") as audio_file:
audio_file.write(response.content)
else:
raise Exception(f"OpenAI TTS请求失败: {response.status_code} - {response.text}")