From 6dd66dbae99bc4fd01d0453c0473044f1b89ad1d Mon Sep 17 00:00:00 2001 From: XL Date: Thu, 15 May 2025 15:35:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89tts=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=8F=82=E6=95=B0=E8=BD=ACdict=20=E6=94=AF=E6=8C=81po?= =?UTF-8?q?st=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/db/changelog/202505151450.sql | 4 ++++ .../main/resources/db/changelog/db.changelog-master.yaml | 7 +++++++ main/xiaozhi-server/core/providers/tts/custom.py | 6 +++++- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 main/manager-api/src/main/resources/db/changelog/202505151450.sql diff --git a/main/manager-api/src/main/resources/db/changelog/202505151450.sql b/main/manager-api/src/main/resources/db/changelog/202505151450.sql new file mode 100644 index 00000000..16c6a79b --- /dev/null +++ b/main/manager-api/src/main/resources/db/changelog/202505151450.sql @@ -0,0 +1,4 @@ +-- 修改自定义TTS接口请求定义 +update `ai_model_provider` set `fields` = +'[{"key":"url","label":"服务地址","type":"string"},{"key":"method","label":"请求方式","type":"string"},{"key":"params","label":"请求参数","type":"dict","dict_name":"params"},{"key":"headers","label":"请求头","type":"dict","dict_name":"headers"},{"key":"format","label":"音频格式","type":"string"},{"key":"output_dir","label":"输出目录","type":"string"}]' +where `id` = 'SYSTEM_TTS_custom'; \ No newline at end of file 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 ae81fd14..a350b76a 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 @@ -142,3 +142,10 @@ databaseChangeLog: - sqlFile: encoding: utf8 path: classpath:db/changelog/202505142037.sql + - changeSet: + id: 202505151450 + author: hrz + changes: + - sqlFile: + encoding: utf8 + path: classpath:db/changelog/202505151450.sql diff --git a/main/xiaozhi-server/core/providers/tts/custom.py b/main/xiaozhi-server/core/providers/tts/custom.py index 1efd7d7f..0b7dd04b 100644 --- a/main/xiaozhi-server/core/providers/tts/custom.py +++ b/main/xiaozhi-server/core/providers/tts/custom.py @@ -13,6 +13,7 @@ class TTSProvider(TTSProviderBase): def __init__(self, config, delete_audio_file): super().__init__(config, delete_audio_file) self.url = config.get("url") + self.method = config.get("method", "GET") self.headers = config.get("headers", {}) self.params = json.loads(config.get("params")) self.format = config.get("format", "wav") @@ -28,7 +29,10 @@ class TTSProvider(TTSProviderBase): v = v.replace("{prompt_text}", text) request_params[k] = v - resp = requests.get(self.url, params=request_params, headers=self.headers) + if self.method.upper() == "POST": + resp = requests.post(self.url, json=request_params, headers=self.headers) + else: + resp = requests.get(self.url, params=request_params, headers=self.headers) if resp.status_code == 200: with open(output_file, "wb") as file: file.write(resp.content)