利用 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(subtitles): match canonically equivalent Unicode cue text
Rudy Celekli4231f1e6bbdd
diff --git a/app/services/voice.py b/app/services/voice.pyindex 0e93e2ae..efce0750 100644--- a/app/services/voice.py+++ b/app/services/voice.py@@ -3461,18 +3461,20 @@ def _match_script_line(script_lines: list[str], current_text: str, sub_index: inreturn ""target_line = script_lines[sub_index]- if current_text == target_line:+ comparison_target = unicodedata.normalize("NFC", target_line)+ current_text = unicodedata.normalize("NFC", current_text)+ if current_text == comparison_target:return target_line.strip()current_text_normalized = re.sub(r"[_\W]+", "", current_text)- target_line_normalized = re.sub(r"[_\W]+", "", target_line)+ target_line_normalized = re.sub(r"[_\W]+", "", comparison_target)if current_text_normalized == target_line_normalized:return target_line.strip()# 最后一层阿拉伯语容错:edge-tts 返回的字母形态、变音符号或 Tatweel# 可能和脚本不同。只在常规匹配失败后归一化比较,非阿拉伯语文本不会受影响。current_ar = re.sub(r"[_\W]+", "", _normalize_arabic(current_text))- target_ar = re.sub(r"[_\W]+", "", _normalize_arabic(target_line))+ target_ar = re.sub(r"[_\W]+", "", _normalize_arabic(comparison_target))if current_ar and current_ar == target_ar:return target_line.strip()diff --git a/test/services/test_subtitle_canonical_unicode_matching.py b/test/services/test_subtitle_canonical_unicode_matching.pynew file mode 100644index 00000000..f842fb8c--- /dev/null+++ b/test/services/test_subtitle_canonical_unicode_matching.py@@ -0,0 +1,28 @@+import unicodedata+from datetime import timedelta+from types import SimpleNamespace++import pytest+from edge_tts.srt_composer import Subtitle++from app.services import voice+from app.utils.subtitle_reader import file_to_subtitles++[email protected]("script,cue", [+ ("Café", unicodedata.normalize("NFD", "Café")),+ (unicodedata.normalize("NFD", "Café"), "Café"),+ (unicodedata.normalize("NFD", "한글"), "한글"),+])+def test_canonically_equivalent_cues_publish_requested_caption(tmp_path, script, cue):+ maker = SimpleNamespace(cues=[Subtitle(index=1, start=timedelta(seconds=0.1), end=timedelta(seconds=0.9), content=cue)])+ destination = tmp_path / "captions.srt"+ voice.create_subtitle(maker, script, str(destination))+ captions = file_to_subtitles(str(destination))+ assert len(captions) == 1+ assert captions[0][2] == script+ assert captions[0][1] == "00:00:00,100 --> 00:00:00,900"+++def test_distinct_accented_text_is_not_treated_as_equivalent():+ assert voice._match_script_line(["Café"], "Cafe", 0) == ""