maltose1 commited on
Commit
5cfa541
·
verified ·
1 Parent(s): 52efce2

Upload tts-server.py

Browse files
Files changed (1) hide show
  1. 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
- if "block" in str(error_msg).lower() or code == 710022002:
331
- self.cookie_manager.force_rotate() # Force rotate immediately on block
332
- raise Exception(f"Blocked by server (Risk Control): {error_msg}")
 
 
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(status_code=500, detail="Failed to generate audio after retries.")
 
 
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()