From 6bd7f3785595a6f8515dd2658a55ad467ed9a33d Mon Sep 17 00:00:00 2001 From: no99 <17663930442@163.com> Date: Mon, 18 Aug 2025 15:50:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E5=8D=93=E5=88=87=E6=8D=A2=E9=9F=B3?= =?UTF-8?q?=E9=A2=91=E6=97=B6=E6=92=AD=E6=94=BE=E6=B7=B7=E4=B9=B1=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/AIchat.vue | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/views/AIchat.vue b/src/views/AIchat.vue index fcc71e2..c68795b 100644 --- a/src/views/AIchat.vue +++ b/src/views/AIchat.vue @@ -111,7 +111,7 @@ const playNextAudio = () => { src: [audioInfo.url], html5: false, format: ["mp3", "acc"], - // rate: 1.2, + // rate: 2, retryCount: 0, onplay: () => { audioStore.isPlaying = true; @@ -214,7 +214,6 @@ const addToAudioQueue = (url, name) => { "当前队列顺序:", audioQueue.value.map((item) => `${item.name}(${item.order})`) ); - // 只有在确实没有音频在播放且这是第一个音频时才开始播放 if ( !isPlayingAudio.value && @@ -275,6 +274,12 @@ const toggleVoiceForUser = (index) => { chatStore.messages[chatStore.currentUserIndex].audioStatus = false; } + // 强制停止所有音频实例(移动端兼容) + if (audioStore.soundInstance) { + audioStore.soundInstance.stop(); + audioStore.soundInstance = null; + } + audioPreloadStatus.one = { loaded: false, url: null }; audioPreloadStatus.two = { loaded: false, url: null }; audioPreloadStatus.three = { loaded: false, url: null }; @@ -301,20 +306,22 @@ const toggleVoiceForUser = (index) => { audioStore.soundInstance = null; currentPlayIndex = 0; isCallingPlayNext = false; - addToAudioQueue(chatStore.messages[index].audioArray[0], "API1-第一个"); - addToAudioQueue(chatStore.messages[index].audioArray[1], "API2-第二个"); - addToAudioQueue(chatStore.messages[index].audioArray[2], "API3-第三个"); - addToAudioQueue(chatStore.messages[index].audioArray[3], "API4-第四个"); + setTimeout(() => { + addToAudioQueue(chatStore.messages[index].audioArray[0], "API1-第一个"); + addToAudioQueue(chatStore.messages[index].audioArray[1], "API2-第二个"); + addToAudioQueue(chatStore.messages[index].audioArray[2], "API3-第三个"); + addToAudioQueue(chatStore.messages[index].audioArray[3], "API4-第四个"); - if (!audioStore.isVoiceEnabled) { - audioStore.toggleVoice(); - } else { - if (audioStore.currentAudioUrl || audioStore.ttsUrl) { - audioStore.togglePlayPause(); - } else { + if (!audioStore.isVoiceEnabled) { audioStore.toggleVoice(); + } else { + if (audioStore.currentAudioUrl || audioStore.ttsUrl) { + // audioStore.togglePlayPause(); + } else { + audioStore.toggleVoice(); + } } - } + }, 100); // 100ms延迟足够移动端清理音频实例 } else { if (!audioStore.isVoiceEnabled) { console.log("1111");