Poker commited on
Commit
68c4618
·
1 Parent(s): a6b7b01

fix: use fresh asyncio event loop to avoid gunicorn thread conflicts

Browse files
Files changed (1) hide show
  1. utils/audio_engine.py +11 -3
utils/audio_engine.py CHANGED
@@ -243,9 +243,17 @@ def generate_speech(text: str, voice: str, output_path: str,
243
  lang = parts[1]
244
  gender = parts[2]
245
  return generate_speech_gtts(text, lang, output_path, gender, rate, pitch)
246
-
247
- asyncio.run(_tts_async(text, voice, output_path,
248
- rate, pitch, style, style_degree))
 
 
 
 
 
 
 
 
249
  return os.path.exists(output_path) and os.path.getsize(output_path) > 0
250
  except Exception as e:
251
  print(f"[TTS Error] {e}")
 
243
  lang = parts[1]
244
  gender = parts[2]
245
  return generate_speech_gtts(text, lang, output_path, gender, rate, pitch)
246
+
247
+ # Use a fresh event loop to avoid conflicts with gunicorn threads
248
+ loop = asyncio.new_event_loop()
249
+ asyncio.set_event_loop(loop)
250
+ try:
251
+ loop.run_until_complete(_tts_async(text, voice, output_path,
252
+ rate, pitch, style, style_degree))
253
+ finally:
254
+ loop.close()
255
+ asyncio.set_event_loop(None)
256
+
257
  return os.path.exists(output_path) and os.path.getsize(output_path) > 0
258
  except Exception as e:
259
  print(f"[TTS Error] {e}")