Upload tts-server.py
Browse files- tts-server.py +10 -4
tts-server.py
CHANGED
|
@@ -327,9 +327,11 @@ class DoubaoTTS:
|
|
| 327 |
logger.error(f"Doubao API Error (Code {code}): {error_msg}")
|
| 328 |
|
| 329 |
# If blocked or auth failed, report failure to rotate cookie
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
|
|
|
|
|
|
| 333 |
except json.JSONDecodeError:
|
| 334 |
pass
|
| 335 |
|
|
@@ -357,10 +359,14 @@ class DoubaoTTS:
|
|
| 357 |
except Exception as e:
|
| 358 |
logger.error(f"WebSocket error (Attempt {attempt+1}): {e}")
|
| 359 |
self.cookie_manager.report_failure()
|
|
|
|
|
|
|
| 360 |
# Continue to next attempt
|
| 361 |
|
| 362 |
logger.error("All retry attempts failed.")
|
| 363 |
-
raise HTTPException
|
|
|
|
|
|
|
| 364 |
|
| 365 |
# Initialize Engine
|
| 366 |
engine = DoubaoTTS()
|
|
|
|
| 327 |
logger.error(f"Doubao API Error (Code {code}): {error_msg}")
|
| 328 |
|
| 329 |
# If blocked or auth failed, report failure to rotate cookie
|
| 330 |
+
# 710022002: Blocked
|
| 331 |
+
# 671000003: Rate Limited
|
| 332 |
+
if "block" in str(error_msg).lower() or code in [710022002, 671000003]:
|
| 333 |
+
self.cookie_manager.force_rotate() # Force rotate immediately on block/limit
|
| 334 |
+
raise Exception(f"Blocked/Limited by server ({code}): {error_msg}")
|
| 335 |
except json.JSONDecodeError:
|
| 336 |
pass
|
| 337 |
|
|
|
|
| 359 |
except Exception as e:
|
| 360 |
logger.error(f"WebSocket error (Attempt {attempt+1}): {e}")
|
| 361 |
self.cookie_manager.report_failure()
|
| 362 |
+
# Wait a bit before retrying to avoid hammering
|
| 363 |
+
await asyncio.sleep(3)
|
| 364 |
# Continue to next attempt
|
| 365 |
|
| 366 |
logger.error("All retry attempts failed.")
|
| 367 |
+
# Do not raise HTTPException here as it causes RuntimeError if response started
|
| 368 |
+
# Just return to close the stream
|
| 369 |
+
return
|
| 370 |
|
| 371 |
# Initialize Engine
|
| 372 |
engine = DoubaoTTS()
|