From 8f979f5478d3483bfc18b84df2f440ac9f2ed6fd Mon Sep 17 00:00:00 2001 From: weipengfei <2187978347@qq.com> Date: Wed, 17 Jan 2024 18:12:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/chat/components/Message/index.vue | 2 ++ src/views/chat/index.vue | 37 +++++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/views/chat/components/Message/index.vue b/src/views/chat/components/Message/index.vue index 0bca241..12e8e07 100644 --- a/src/views/chat/components/Message/index.vue +++ b/src/views/chat/components/Message/index.vue @@ -152,6 +152,8 @@ async function loadTTS() { // 监听到文本数据改变 const watchTTS = watch(() => props.tts, async (n: any, o: any) => { + console.log('文本变化', n); + if (props.tts == '') { for (let i = 0; i < audioElements.length; i++) { audioElements[i].pause() diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index a3f24c0..130e454 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -438,26 +438,51 @@ async function onConversation() { // } // } - socket.onmessage = (event: any)=>{ - console.log(event.data); - lastText+=event.data; + socket.onmessage = (e: any)=>{ + console.log(e.data); + let event = { + data: { + event: '', + text: '', + tts_text: '' + } + }; + event.data = JSON.parse(e.data); const loading = false; nowStart.value = false; - if(!event.data.includes('[finish]')) updateChat( + event.data.tts_text != '' ? tts.push(event.data.tts_text) : null + if(!event.data.event.includes('finish')) { + lastText+=event.data.text; + updateChat( +uuid, dataSources.value.length - 1, { dateTime: new Date().toLocaleString(), text: lastText, inversion: false, - tts: JSON.stringify(+uuid), + tts: JSON.stringify(tts), error: false, loading, conversationOptions: { conversationId: uuid, parentMessageId: uuid }, requestOptions: { prompt: message, options: { ...options } }, }, ) - else{ + } else if(event.data.tts_text){ + updateChat( + +uuid, + dataSources.value.length - 1, + { + dateTime: new Date().toLocaleString(), + text: lastText, + inversion: false, + tts: JSON.stringify(tts), + error: false, + loading, + conversationOptions: { conversationId: uuid, parentMessageId: uuid }, + requestOptions: { prompt: message, options: { ...options } }, + }, + ) + } else{ // 关闭连接 nowStatus.value = 'input' socket.close()