Skip to content

Commit a1ae328

Browse files
committed
refactor: 语音播放时将内容处理成纯文本
1 parent f2dae7b commit a1ae328

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

ui/src/components/ai-chat/OperationButton.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,32 @@ function voteHandle(val: string) {
118118
})
119119
}
120120
121+
function markdownToPlainText(md: string) {
122+
return md
123+
// 移除图片 ![alt](url)
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+
121144
const playAnswerText = (text: string) => {
145+
// text 处理成纯文本
146+
text = markdownToPlainText(text)
122147
if (props.tts_type === 'BROWSER') {
123148
// 创建一个新的 SpeechSynthesisUtterance 实例
124149
const utterance = new SpeechSynthesisUtterance(text)

ui/src/components/ai-chat/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ function handleInputFieldList() {
357357
const record = chatList.value[chatList.value.length - 1]
358358
let default_value: any = {}
359359
if (record) {
360-
record.execution_details[0].global_fields.reduce((pre: any, next: any) => {
360+
record.execution_details[0].global_fields?.reduce((pre: any, next: any) => {
361361
pre[next.key] = next.value
362362
return pre
363363
}, default_value)

0 commit comments

Comments
 (0)