mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-23 03:19:41 +00:00
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
This commit is contained in:
parent
545979873b
commit
d03d0d0982
1 changed files with 6 additions and 1 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue