From d0694a0e7012877a9a602b61ab09a3ec85e80c38 Mon Sep 17 00:00:00 2001 From: XL Date: Fri, 16 May 2025 11:56:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9yaml=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=92=8C=E7=AE=A1=E7=90=86=E7=AB=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/core/providers/tts/custom.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main/xiaozhi-server/core/providers/tts/custom.py b/main/xiaozhi-server/core/providers/tts/custom.py index 0b7dd04b..a5300a3e 100644 --- a/main/xiaozhi-server/core/providers/tts/custom.py +++ b/main/xiaozhi-server/core/providers/tts/custom.py @@ -15,10 +15,19 @@ class TTSProvider(TTSProviderBase): 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") self.output_file = config.get("output_dir", "tmp/") + self.params = config.get("params") + + if isinstance(self.params, str): + try: + self.params = json.loads(self.params) + except json.JSONDecodeError: + raise ValueError("Custom TTS配置参数出错,无法将字符串解析为对象") + elif not isinstance(self.params, dict): + raise TypeError("Custom TTS配置参数出错, 请参考配置说明") + def generate_filename(self): return os.path.join(self.output_file, f"tts-{datetime.now().date()}@{uuid.uuid4().hex}.{self.format}")