From 6bd0a0f2bdd5c0139c4e03b449940bca764138cb Mon Sep 17 00:00:00 2001 From: HUANYU XU Date: Mon, 9 Dec 2024 14:56:09 +0800 Subject: [PATCH] fix: use empty audio as fallback for failed tts tasks --- core/all_tts_functions/tts_main.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/all_tts_functions/tts_main.py b/core/all_tts_functions/tts_main.py index c6c61550..98003892 100644 --- a/core/all_tts_functions/tts_main.py +++ b/core/all_tts_functions/tts_main.py @@ -69,8 +69,13 @@ def tts_main(text, save_as, number, task_df): else: if os.path.exists(save_as): os.remove(save_as) - raise Exception("Generated audio duration is 0") - + if attempt == max_retries - 1: + print(f"Warning: Generated audio duration is 0 for text: {text}") + # Create silent audio file + silence = AudioSegment.silent(duration=100) # 100ms silence + silence.export(save_as, format="wav") + return + print(f"Attempt {attempt + 1} failed, retrying...") except Exception as e: if attempt == max_retries - 1: raise Exception(f"Failed to generate audio after {max_retries} attempts: {str(e)}")