@@ -118,7 +118,32 @@ function voteHandle(val: string) {
118118 })
119119}
120120
121+ function markdownToPlainText(md : string ) {
122+ return md
123+ // 移除图片 
124+ .replace (/ !\[ . *? \]\( . *? \) / g , ' ' )
125+ // 移除链接 [text](url)
126+ .replace (/ \[ ([^ \] ] + )\]\( [^ )] + \) / g , ' $1' )
127+ // 移除 Markdown 标题符号 (#, ##, ###)
128+ .replace (/ ^ #{1,6} \s + / gm , ' ' )
129+ // 移除加粗 **text** 或 __text__
130+ .replace (/ \*\* (. *? )\*\* / g , ' $1' )
131+ .replace (/ __(. *? )__/ g , ' $1' )
132+ // 移除斜体 *text* 或 _text_
133+ .replace (/ \* (. *? )\* / g , ' $1' )
134+ .replace (/ _(. *? )_/ g , ' $1' )
135+ // 移除行内代码 `code`
136+ .replace (/ `(. *? )`/ g , ' $1' )
137+ // 移除代码块 ```code```
138+ .replace (/ ```[\s\S ] *? ```/ g , ' ' )
139+ // 移除多余的换行符
140+ .replace (/ \n {2,} / g , ' \n ' )
141+ .trim ();
142+ }
143+
121144const playAnswerText = (text : string ) => {
145+ // text 处理成纯文本
146+ text = markdownToPlainText (text )
122147 if (props .tts_type === ' BROWSER' ) {
123148 // 创建一个新的 SpeechSynthesisUtterance 实例
124149 const utterance = new SpeechSynthesisUtterance (text )
0 commit comments