Skip to content

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

fix(voice): recognize pause tags with digits right after CJK keywords

Rudy Celeklid83b98af7133
diff --git a/app/utils/utils.py b/app/utils/utils.py
index ae5066ff..5f148e9d 100644
--- a/app/utils/utils.py
+++ b/app/utils/utils.py
@@ -321,9 +321,12 @@ PAUSE_TAG_KEYWORDS = (
r"пауза|тишина|停顿|暂停|静音|ポーズ|一時停止|無音|일시중지|정지"
)
# 匹配所有包含停顿关键词的标签(方括号或圆括号),无论其参数合法与否均匹配,
-# 以确保非法标签(如 [pause: -2s]、[pause: nope]、[pause: 0s])在合成前被彻底清除而不会泄漏给 TTS
+# 以确保非法标签(如 [pause: -2s]、[pause: nope]、[pause: 0s])在合成前被彻底清除而不会泄漏给 TTS。
+# 关键词后不能用 `\b`:中日韩文字和数字都属于 `\w`,`[停顿3秒]` 这种不写冒号的
+# 常见写法会因为没有词边界而漏匹配,标签原文被直接朗读。这里只禁止关键词后
+# 紧跟字母(允许数字),`[paused]`、`[暂停一下]` 这类普通文字仍不会被误判。
PAUSE_TAG_PATTERN = re.compile(
- rf"[\[\(]\s*(?:{PAUSE_TAG_KEYWORDS})\b(?:\s*[::]?\s*([^\]\)]*?))?\s*[\]\)]",
+ rf"[\[\(]\s*(?:{PAUSE_TAG_KEYWORDS})(?![^\W\d])(?:\s*[::]?\s*([^\]\)]*?))?\s*[\]\)]",
re.IGNORECASE,
)
diff --git a/test/services/test_voice.py b/test/services/test_voice.py
index 118b4e3e..8604cc87 100644
--- a/test/services/test_voice.py
+++ b/test/services/test_voice.py
@@ -1899,6 +1899,29 @@ class TestElevenLabsVoice(unittest.TestCase):
self.assertNotIn("(pausa", flex_cleaned)
self.assertNotIn("[pause", flex_cleaned)
+ def test_pause_tags_accept_duration_directly_after_cjk_keyword(self):
+ """中日文习惯不写冒号或空格,`[停顿3秒]` 也必须识别为停顿而不是被朗读。"""
+ script = "大家好。[停顿3秒]今天聊聊理财。[ポーズ2秒]最後。[pause2s]End."
+
+ self.assertTrue(utils.has_pause_tags("[暂停2秒]"))
+ self.assertEqual(
+ utils.parse_script_with_pauses(script),
+ [
+ ("speech", "大家好。"),
+ ("pause", 3.0),
+ ("speech", "今天聊聊理财。"),
+ ("pause", 2.0),
+ ("speech", "最後。"),
+ ("pause", 2.0),
+ ("speech", "End."),
+ ],
+ )
+ self.assertNotIn("停顿", utils.remove_pause_tags(script))
+
+ # 关键词后紧跟字母的普通文字仍不是停顿标签。
+ for text in ("[paused]", "(pauses)", "[暂停一下]"):
+ self.assertFalse(utils.has_pause_tags(text), text)
+
def test_concat_audio_files_reads_pcm_in_bounded_chunks(self):
"""Long pause-aware narration should not load each WAV into memory."""
real_wave_open = vs.wave.open