diff --git a/main/manager-api/src/main/resources/db/changelog/202504112044.sql b/main/manager-api/src/main/resources/db/changelog/202504112044.sql index 9fd2257da..b0223a93d 100644 --- a/main/manager-api/src/main/resources/db/changelog/202504112044.sql +++ b/main/manager-api/src/main/resources/db/changelog/202504112044.sql @@ -43,6 +43,7 @@ INSERT INTO `ai_model_config` VALUES ('TTS_ACGNTTS', 'TTS', 'ACGNTTS', 'ACGN语 INSERT INTO `ai_model_config` VALUES ('TTS_OpenAITTS', 'TTS', 'OpenAITTS', 'OpenAI语音合成', 0, 1, '{\"type\": \"openai\", \"api_key\": \"你的api_key\", \"api_url\": \"https://api.openai.com/v1/audio/speech\", \"model\": \"tts-1\", \"voice\": \"onyx\", \"speed\": 1, \"output_dir\": \"tmp/\"}', NULL, NULL, 13, NULL, NULL, NULL, NULL); INSERT INTO `ai_model_config` VALUES ('TTS_CustomTTS', 'TTS', 'CustomTTS', '自定义语音合成', 0, 1, '{\"type\": \"custom\", \"url\": \"http://127.0.0.1:9880/tts\", \"params\": {}, \"headers\": {}, \"format\": \"wav\", \"output_dir\": \"tmp/\"}', NULL, NULL, 14, NULL, NULL, NULL, NULL); INSERT INTO `ai_model_config` VALUES ('TTS_TencentTTS', 'TTS', 'TencentTTS', '腾讯语音合成', 0, 1, '{\"type\": \"tencent\", \"appid\": \"\", \"secret_id\": \"\", \"secret_key\": \"\", \"region\": \"ap-guangzhou\", \"voice\": \"101001\", \"output_dir\": \"tmp/\"}', NULL, NULL, 3, NULL, NULL, NULL, NULL); +INSERT INTO `ai_model_config` VALUES ('TTS_PaddleSpeechTTS', 'TTS', 'PaddleSpeechTTS', '百度PaddleSpeech语音合成', 0, 1, '{\"type\": \"paddle_speech\", \"url\": \"请输入您的服务器地址\", \"spk_id\": \"0\", \"speed\": \"1.0\", \"volume\": \"1.0\", \"sample_rate\": \"0\", \"save_path\": \"./streaming_tts.wav\"}', NULL, NULL, 18, NULL, NULL, NULL, NULL); -- Memory模型配置 INSERT INTO `ai_model_config` VALUES ('Memory_nomem', 'Memory', 'nomem', '无记忆', 1, 1, '{\"type\": \"nomem\"}', NULL, NULL, 1, NULL, NULL, NULL, NULL); diff --git a/main/manager-api/src/main/resources/db/changelog/202507151826.sql b/main/manager-api/src/main/resources/db/changelog/202507151826.sql new file mode 100644 index 000000000..c4e36b504 --- /dev/null +++ b/main/manager-api/src/main/resources/db/changelog/202507151826.sql @@ -0,0 +1,22 @@ + +-- 增加PaddleSpeechTTS模型配置 +delete from `ai_model_provider` where id = 'TTS_PaddleSpeechTTS'; +INSERT INTO `ai_model_provider` (`id`, `model_type`, `provider_code`, `name`, `fields`, `sort`, `creator`, `create_date`, `updater`, `update_date`) VALUES +('TTS_PaddleSpeechTTS', 'TTS', 'PaddleSpeechTTS', '百度PaddleSpeech语音合成', '[{\"type\": \"paddle_speech\", \"url\": \"请输入您的服务器地址\", \"spk_id\": \"0\", \"speed\": \"1.0\", \"volume\": \"1.0\", \"sample_rate\": \"0\", \"save_path\": \"./streaming_tts.wav\"}]', 18, 0, NOW(), 1, NOW()); + +delete from `ai_model_config` where id = 'TTS_PaddleSpeechTTS'; +INSERT INTO `ai_model_config` VALUES ('TTS_PaddleSpeechTTS', 'TTS', 'PaddleSpeechTTS', '百度PaddleSpeech语音合成', 0, 1, '{\"type\": \"paddle_speech\", \"url\": \"请输入您的服务器地址\", \"spk_id\": \"0\", \"speed\": \"1.0\", \"volume\": \"1.0\", \"sample_rate\": \"0\", \"save_path\": \"./streaming_tts.wav\"}', NULL, NULL, 18, NULL, NULL, NULL, NULL); + +-- 增加PaddleSpeechTTS模型配置 +UPDATE `ai_model_config` SET +`doc_link` = 'https://github.com/PaddlePaddle/PaddleSpeech', +`remark` = 'PaddleSpeech语音合成服务配置说明: + #框架地址 https://www.paddlepaddle.org.cn/ + #项目地址 https://github.com/PaddlePaddle/PaddleSpeech + #SpeechServerDemo https://github.com/PaddlePaddle/PaddleSpeech/tree/develop/demos/speech_server +1. 访问 https://github.com/PaddlePaddle/PaddleSpeech 测试部署 +2. SpeechServerDemo服务可参考https://github.com/PaddlePaddle/PaddleSpeech/tree/develop/demos/speech_server' WHERE `id` = 'TTS_PaddleSpeechTTS'; + + +delete from `ai_tts_voice` where tts_model_id = 'TTS_PaddleSpeechTTS'; +INSERT INTO `ai_tts_voice` VALUES ('TTS_LinkeraiTTS_0046', 'TTS_PaddleSpeechTTS', '小浆', '', '中文', NULL, NULL, 1, NULL, NULL, NULL, NULL); diff --git a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml index 2a520d164..16db1c92d 100755 --- a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml @@ -260,4 +260,11 @@ databaseChangeLog: changes: - sqlFile: encoding: utf8 - path: classpath:db/changelog/202507081646.sql \ No newline at end of file + path: classpath:db/changelog/202507081646.sql + - changeSet: + id: 202507151826 + author: mxf + changes: + - sqlFile: + encoding: utf8 + path: classpath:db/changelog/202507151826.sql \ No newline at end of file diff --git a/main/xiaozhi-server/config.yaml b/main/xiaozhi-server/config.yaml index 2ae718962..334e6a9fb 100644 --- a/main/xiaozhi-server/config.yaml +++ b/main/xiaozhi-server/config.yaml @@ -781,3 +781,16 @@ TTS: access_token: "U4YdYXVfpwWnk2t5Gp822zWPCuORyeJL" voice: "OUeAo1mhq6IBExi" output_dir: tmp/ + PaddleSpeechTTS: + #百度飞浆 PaddleSpeech + #框架地址 https://www.paddlepaddle.org.cn/ + #项目地址 https://github.com/PaddlePaddle/PaddleSpeech + #SpeechServerDemo https://github.com/PaddlePaddle/PaddleSpeech/tree/develop/demos/speech_server + type: paddle_speech + url: http://127.0.0.1:8090/paddlespeech/tts # TTS 服务的 URL 地址,指向本地服务器 + spk_id: 0 # 发音人 ID,0 通常表示默认的发音人 + speed: 1.0 # 语速,1.0 表示正常语速,>1 表示加快,<1 表示减慢 + volume: 1.0 # 音量,1.0 表示正常音量,>1 表示增大,<1 表示减小 + sample_rate: 0 # 采样率,0 表示自动选择系统默认的采样率 + save_path: ./streaming_tts.wav # 服务器生成的语音文件保存路径 + diff --git a/main/xiaozhi-server/core/providers/tts/paddle_speech.py b/main/xiaozhi-server/core/providers/tts/paddle_speech.py new file mode 100644 index 000000000..2ca5386bc --- /dev/null +++ b/main/xiaozhi-server/core/providers/tts/paddle_speech.py @@ -0,0 +1,48 @@ +import base64 +import aiohttp +from core.providers.tts.base import TTSProviderBase +from config.logger import setup_logging + +TAG = __name__ +logger = setup_logging() + + +class TTSProvider(TTSProviderBase): + def __init__(self, config, delete_audio_file): + super().__init__(config, delete_audio_file) + self.url = config.get("url") + self.spk_id = config.get("spk_id", 0) + self.speed = config.get("speed", 1.0) + self.volume = config.get("volume", 1.0) + self.sample_rate = config.get("sample_rate", 0) + self.save_path = config.get("save_path", "./streaming_tts.wav") + + async def text_to_speak(self, text, output_file): + request_json = { + "text": text, + "spk_id": self.spk_id, + "speed": self.speed, + "volume": self.volume, + "sample_rate": self.sample_rate, + "save_path": self.save_path + } + + try: + async with aiohttp.ClientSession() as session: + async with session.post(self.url, json=request_json) as resp: + if resp.status == 200: + resp_json = await resp.json() + if resp_json.get("success"): + data = resp_json["result"] + audio_bytes = base64.b64decode(data["audio"]) + if output_file: + with open(output_file, "wb") as file_to_save: + file_to_save.write(audio_bytes) + else: + return audio_bytes + else: + raise Exception(f"Error: {resp_json.get('message', 'Unknown error')}") + else: + raise Exception(f"HTTP Error: {resp.status} - {await resp.text()}") + except Exception as e: + raise Exception(f"Error during TTS request: {e}")