From d03d0d0982df2fef24873a523cbb731e9fa5006f Mon Sep 17 00:00:00 2001 From: henson957 <202114553+henson957@users.noreply.github.com> Date: Wed, 12 Aug 2026 17:37:04 +0800 Subject: [PATCH] fix(tts): add HTTP timeout and error handling to SiliconFlow provider - requests.request() had no timeout: when the SiliconFlow API slows down, the request hangs forever and the device produces no audio intermittently - non-200 responses (rate limit, error page) were written to disk as audio; now the status code is checked and an exception is raised with the body --- main/xiaozhi-server/core/providers/tts/siliconflow.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main/xiaozhi-server/core/providers/tts/siliconflow.py b/main/xiaozhi-server/core/providers/tts/siliconflow.py index b5c618ec1..feefb9ae7 100644 --- a/main/xiaozhi-server/core/providers/tts/siliconflow.py +++ b/main/xiaozhi-server/core/providers/tts/siliconflow.py @@ -39,8 +39,13 @@ class TTSProvider(TTSProviderBase): } try: response = requests.request( - "POST", self.api_url, json=request_json, headers=headers + "POST", self.api_url, json=request_json, headers=headers, + timeout=15, ) + if response.status_code != 200: + raise Exception( + f"{__name__} HTTP {response.status_code}: {response.text[:200]}" + ) data = response.content if output_file: with open(output_file, "wb") as file_to_save: