MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / cleanTextForTTS

Function cleanTextForTTS

tts/tts.ts:35–63  ·  view source on GitHub ↗

清理文本(emoji/不在白名单的符号;合并连续标点)

(text: string)

Source from the content-addressed store, hash-verified

33 } catch { }
34}
35
36/** 清理文本(emoji/不在白名单的符号;合并连续标点) */
37function cleanTextForTTS(text: string): string {
38 if (!text) return "";
39 let cleanedText = text;
40 // 移除各类 Emoji 和特殊符号
41 const broadSymbolRegex = new RegExp(
42 "[" +
43 "\u{1F600}-\u{1F64F}" + // Emoticons
44 "\u{1F300}-\u{1F5FF}" + // Misc Symbols and Pictographs
45 "\u{1F680}-\u{1F6FF}" + // Transport and Map
46 "\u{2600}-\u{26FF}" + // Misc symbols
47 "\u{2700}-\u{27BF}" + // Dingbats
48 "\u{FE0F}" + // Variation Selectors
49 "\u{200D}" + // Zero-Width Joiner
50 "]",
51 "gu"
52 );
53 cleanedText = cleanedText.replace(broadSymbolRegex, "");
54
55 // 仅保留中文、英文、数字和常见标点
56 // const whitelistRegex = /[^\u4e00-\u9fa5a-zA-Z0-9\s,。?!、,?!.]/g;
57 // cleanedText = cleanedText.replace(whitelistRegex, "");
58
59 // 合并连续标点
60 cleanedText = cleanedText.replace(/([,。?!、,?!.])\1+/g, "$1");
61 // 移除 markdown 链接格式 [text](url) -> text
62 cleanedText = cleanedText.replace(/\[([^\]]+)\]\([^\)]+\)/g, "$1");
63
64 return cleanedText.trim();
65}
66

Callers 1

TTSPluginClass · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected