利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.
Python ai-video-generatorcontent-creationffmpeginstagram-reelsllmpythonshort-videosubtitlestext-to-speechtiktokvideo-automationvideo-workflowworkflow-automationyoutube-shorts
fix(voice): emit signed zero rate for edge-tts
KennyVWS2ac6a7c35463
diff --git a/app/services/voice.py b/app/services/voice.pyindex 9bb8ee58..cff798e7 100644--- a/app/services/voice.py+++ b/app/services/voice.py@@ -1193,13 +1193,14 @@ def tts(def convert_rate_to_percent(rate: float) -> str:- if rate == 1.0:- return "+0%"+ # edge-tts requires a sign-prefixed percentage (e.g. "+0%", "-20%").+ # Rounding can yield 0 for rates near but not equal to 1.0 (e.g. 1.004,+ # 0.997); those must still be returned as "+0%", not the unsigned "0%"+ # which edge-tts rejects with ValueError: Invalid rate '0%'.percent = round((rate - 1.0) * 100)- if percent > 0:+ if percent >= 0:return f"+{percent}%"- else:- return f"{percent}%"+ return f"{percent}%"def ensure_file_path_exists(file_path: str) -> None:diff --git a/test/services/test_voice.py b/test/services/test_voice.pyindex bb59429c..4116fd68 100644--- a/test/services/test_voice.py+++ b/test/services/test_voice.py@@ -378,6 +378,17 @@ class TestVoiceService(unittest.TestCase):self.assertEqual(len(sub_items), len(script_lines))self.assertIn("1,000 years", sub_items[-1])+ def test_convert_rate_to_percent_signs_zero_rate(self):+ # Rates near but not exactly 1.0 round to 0 percent. edge-tts rejects+ # an unsigned "0%" (ValueError: Invalid rate '0%'), so the helper must+ # emit a sign-prefixed "+0%". Regression test for that crash.+ self.assertEqual(vs.convert_rate_to_percent(1.0), "+0%")+ self.assertEqual(vs.convert_rate_to_percent(1.004), "+0%")+ self.assertEqual(vs.convert_rate_to_percent(0.997), "+0%")+ self.assertEqual(vs.convert_rate_to_percent(1.5), "+50%")+ self.assertEqual(vs.convert_rate_to_percent(0.8), "-20%")++if __name__ == "__main__":# python -m unittest test.services.test_voice.TestVoiceService.test_azure_tts_v1# python -m unittest test.services.test_voice.TestVoiceService.test_azure_tts_v2