mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-25 16:43:55 +08:00
自定义tts接口参数转dict
支持post请求
This commit is contained in:
@@ -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';
|
||||||
@@ -142,3 +142,10 @@ databaseChangeLog:
|
|||||||
- sqlFile:
|
- sqlFile:
|
||||||
encoding: utf8
|
encoding: utf8
|
||||||
path: classpath:db/changelog/202505142037.sql
|
path: classpath:db/changelog/202505142037.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202505151450
|
||||||
|
author: hrz
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202505151450.sql
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class TTSProvider(TTSProviderBase):
|
|||||||
def __init__(self, config, delete_audio_file):
|
def __init__(self, config, delete_audio_file):
|
||||||
super().__init__(config, delete_audio_file)
|
super().__init__(config, delete_audio_file)
|
||||||
self.url = config.get("url")
|
self.url = config.get("url")
|
||||||
|
self.method = config.get("method", "GET")
|
||||||
self.headers = config.get("headers", {})
|
self.headers = config.get("headers", {})
|
||||||
self.params = json.loads(config.get("params"))
|
self.params = json.loads(config.get("params"))
|
||||||
self.format = config.get("format", "wav")
|
self.format = config.get("format", "wav")
|
||||||
@@ -28,7 +29,10 @@ class TTSProvider(TTSProviderBase):
|
|||||||
v = v.replace("{prompt_text}", text)
|
v = v.replace("{prompt_text}", text)
|
||||||
request_params[k] = v
|
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:
|
if resp.status_code == 200:
|
||||||
with open(output_file, "wb") as file:
|
with open(output_file, "wb") as file:
|
||||||
file.write(resp.content)
|
file.write(resp.content)
|
||||||
|
|||||||
Reference in New Issue
Block a user