From dcee1b6d55cc3daafcb2150b863457b337be529a Mon Sep 17 00:00:00 2001
From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com>
Date: Mon, 24 Mar 2025 14:21:29 +0800
Subject: [PATCH] feat: Text to speech support streaming playback (#2661)
---
ui/src/api/type/application.ts | 4 +-
.../operation-button/ChatOperationButton.vue | 472 +++++++++++++-----
.../component/operation-button/index.vue | 2 +-
ui/src/components/ai-chat/index.vue | 1 +
4 files changed, 343 insertions(+), 136 deletions(-)
diff --git a/ui/src/api/type/application.ts b/ui/src/api/type/application.ts
index 6e5bd0b07..a8fac6d1f 100644
--- a/ui/src/api/type/application.ts
+++ b/ui/src/api/type/application.ts
@@ -1,5 +1,6 @@
import { type Dict } from '@/api/type/common'
import { type Ref } from 'vue'
+import bus from '@/bus'
interface ApplicationFormType {
name?: string
desc?: string
@@ -144,8 +145,8 @@ export class ChatRecordManage {
})
}
}
-
this.chat.answer_text = this.chat.answer_text + chunk_answer
+ bus.emit('change:answer', { record_id: this.chat.record_id, is_end: false })
}
get_current_up_node(run_node: any) {
const index = this.node_list.findIndex((item) => item == run_node)
@@ -232,6 +233,7 @@ export class ChatRecordManage {
if (this.loading) {
this.loading.value = false
}
+ bus.emit('change:answer', { record_id: this.chat.record_id, is_end: true })
if (this.id) {
clearInterval(this.id)
}
diff --git a/ui/src/components/ai-chat/component/operation-button/ChatOperationButton.vue b/ui/src/components/ai-chat/component/operation-button/ChatOperationButton.vue
index 48079c8ec..f35cb15b4 100644
--- a/ui/src/components/ai-chat/component/operation-button/ChatOperationButton.vue
+++ b/ui/src/components/ai-chat/component/operation-button/ChatOperationButton.vue
@@ -8,20 +8,35 @@
-
-
-
-
-
-
+
+
+ {
+ bus.emit('play:pause', props.data.record_id)
+ audioManage?.play(props.data.answer_text, true)
+ }
+ "
+ >
+
+
+
+
@@ -82,6 +97,7 @@
+