mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
refactor: 语音播放时将内容处理成纯文本
This commit is contained in:
parent
f2dae7b3e6
commit
a1ae3283ec
|
|
@ -118,7 +118,32 @@ function voteHandle(val: string) {
|
|||
})
|
||||
}
|
||||
|
||||
function markdownToPlainText(md: string) {
|
||||
return md
|
||||
// 移除图片 
|
||||
.replace(/!\[.*?\]\(.*?\)/g, '')
|
||||
// 移除链接 [text](url)
|
||||
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
|
||||
// 移除 Markdown 标题符号 (#, ##, ###)
|
||||
.replace(/^#{1,6}\s+/gm, '')
|
||||
// 移除加粗 **text** 或 __text__
|
||||
.replace(/\*\*(.*?)\*\*/g, '$1')
|
||||
.replace(/__(.*?)__/g, '$1')
|
||||
// 移除斜体 *text* 或 _text_
|
||||
.replace(/\*(.*?)\*/g, '$1')
|
||||
.replace(/_(.*?)_/g, '$1')
|
||||
// 移除行内代码 `code`
|
||||
.replace(/`(.*?)`/g, '$1')
|
||||
// 移除代码块 ```code```
|
||||
.replace(/```[\s\S]*?```/g, '')
|
||||
// 移除多余的换行符
|
||||
.replace(/\n{2,}/g, '\n')
|
||||
.trim();
|
||||
}
|
||||
|
||||
const playAnswerText = (text: string) => {
|
||||
// text 处理成纯文本
|
||||
text = markdownToPlainText(text)
|
||||
if (props.tts_type === 'BROWSER') {
|
||||
// 创建一个新的 SpeechSynthesisUtterance 实例
|
||||
const utterance = new SpeechSynthesisUtterance(text)
|
||||
|
|
|
|||
|
|
@ -357,7 +357,7 @@ function handleInputFieldList() {
|
|||
const record = chatList.value[chatList.value.length - 1]
|
||||
let default_value: any = {}
|
||||
if (record) {
|
||||
record.execution_details[0].global_fields.reduce((pre: any, next: any) => {
|
||||
record.execution_details[0].global_fields?.reduce((pre: any, next: any) => {
|
||||
pre[next.key] = next.value
|
||||
return pre
|
||||
}, default_value)
|
||||
|
|
|
|||
Loading…
Reference in New Issue