利用 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(subtitle): drop transcription cues beyond script
Rudy Celekliba4c6af8ef0c
diff --git a/app/services/subtitle.py b/app/services/subtitle.pyindex b94746e7..ef62694e 100644--- a/app/services/subtitle.py+++ b/app/services/subtitle.py@@ -328,6 +328,13 @@ def correct(subtitle_file, video_script):script_index += 1corrected = True+ if subtitle_index < len(subtitle_items):+ logger.warning(+ f"Dropping {len(subtitle_items) - subtitle_index} transcription cue(s) "+ "after the script ends"+ )+ corrected = True+if corrected:with open(subtitle_file, "w", encoding="utf-8") as fd:for i, item in enumerate(new_subtitle_items):diff --git a/test/services/test_subtitle.py b/test/services/test_subtitle.pyindex 452c073d..1fdd129a 100644--- a/test/services/test_subtitle.py+++ b/test/services/test_subtitle.py@@ -259,6 +259,22 @@ class TestSubtitleService(unittest.TestCase):self.assertEqual(items[0][1], "00:00:00,100 --> 00:00:02,000")self.assertEqual(items[0][2], "Hello world")+ def test_correct_removes_transcription_after_script_ends(self):+ """Whisper's trailing hallucinations must not appear as final captions."""+ original_srt = (+ "1\n00:00:00,100 --> 00:00:01,000\nHello world\n\n"+ "2\n00:00:01,000 --> 00:00:02,000\nUnspoken words\n\n"+ )++ with tempfile.TemporaryDirectory() as tmp_dir:+ subtitle_file = Path(tmp_dir) / "subtitle.srt"+ subtitle_file.write_text(original_srt, encoding="utf-8")++ subtitle.correct(str(subtitle_file), "Hello world")+ items = subtitle.file_to_subtitles(str(subtitle_file))++ self.assertEqual([item[2] for item in items], ["Hello world"])+def test_correct_replaces_mismatch_and_appends_missing_script_line(self):"""转写结果与脚本完全不一致时仍应以脚本为准;脚本多出的句子没有可复用