Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

fix(tts): handle non-finite voice rates

Sushanth012b463291b4658
diff --git a/app/services/voice.py b/app/services/voice.py
index 22c31401..3b559333 100644
--- a/app/services/voice.py
+++ b/app/services/voice.py
@@ -638,7 +638,7 @@ def convert_rate_to_percent(rate: float) -> str:
rate = float(rate)
except (TypeError, ValueError):
rate = 1.0
- if rate <= 0:
+ if not math.isfinite(rate) or rate <= 0:
rate = 1.0
percent = round((rate - 1.0) * 100)
if percent >= 0:
diff --git a/test/services/test_voice.py b/test/services/test_voice.py
index 9b65b3ad..915c000d 100644
--- a/test/services/test_voice.py
+++ b/test/services/test_voice.py
@@ -1352,6 +1352,8 @@ class TestVoiceService(unittest.TestCase):
self.assertEqual(vs.convert_rate_to_percent(0.0), "+0%")
self.assertEqual(vs.convert_rate_to_percent(None), "+0%")
self.assertEqual(vs.convert_rate_to_percent(""), "+0%")
+ self.assertEqual(vs.convert_rate_to_percent(float("nan")), "+0%")
+ self.assertEqual(vs.convert_rate_to_percent(float("inf")), "+0%")
class TestElevenLabsVoice(unittest.TestCase):