refactor: 语音播放时将内容处理成纯文本

This commit is contained in:
CaptainB 2024-09-19 17:18:53 +08:00 committed by 刘瑞斌
parent f2dae7b3e6
commit a1ae3283ec
2 changed files with 26 additions and 1 deletions

View File

@ -118,7 +118,32 @@ function voteHandle(val: string) {
})
}
function markdownToPlainText(md: string) {
return md
// ![alt](url)
.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)

View File

@ -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)