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:
henson957 2026-08-12 17:37:04 +08:00
parent 545979873b
commit d03d0d0982

View file

@ -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: