修复网页对话并接入 SearXNG 搜索
This commit is contained in:
+21
-1
@@ -45,6 +45,23 @@ _CLAUSE = ",,、::"
|
||||
MAX_CHARS_PER_SEGMENT = 30
|
||||
|
||||
|
||||
def text_for_speech(text: str) -> str:
|
||||
"""去掉只适合屏幕阅读的链接/来源标记,避免 TTS 朗读网址。"""
|
||||
text = text or ""
|
||||
# 搜索回答约定把引用放在独立的“来源:”行;语音正文到此结束。
|
||||
text = re.split(
|
||||
r"(?:^|\n)\s*(?:参考来源|资料来源|来源)\s*[::]",
|
||||
text,
|
||||
maxsplit=1,
|
||||
flags=re.IGNORECASE,
|
||||
)[0]
|
||||
# 即使模型偶尔用了 Markdown 链接,也只朗读标题。
|
||||
text = re.sub(r"\[([^\]]+)\]\(https?://[^)]+\)", r"\1", text)
|
||||
text = re.sub(r"https?://\S+", "", text)
|
||||
text = re.sub(r"[*#`|]", "", text)
|
||||
return " ".join(text.split()).strip()
|
||||
|
||||
|
||||
class TTSError(RuntimeError):
|
||||
pass
|
||||
|
||||
@@ -154,4 +171,7 @@ class LocalTTS:
|
||||
return np.concatenate(chunks)
|
||||
|
||||
|
||||
__all__ = ["LocalTTS", "TTSError", "split_sentences", "MAX_CHARS_PER_SEGMENT"]
|
||||
__all__ = [
|
||||
"LocalTTS", "TTSError", "split_sentences", "text_for_speech",
|
||||
"MAX_CHARS_PER_SEGMENT",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user