From 2636c555ec8e68aea76f80c346fdc12e49098d7b Mon Sep 17 00:00:00 2001 From: no99 <17663930442@163.com> Date: Thu, 14 Aug 2025 10:46:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E9=87=8D=E5=A4=8D=E6=92=AD=E6=94=BE?= =?UTF-8?q?=EF=BC=8C=E5=B7=AE=E9=9F=B3=E9=A2=91=E6=8C=89=E9=92=AE=E7=9A=84?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/AIchat.vue | 67 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/src/views/AIchat.vue b/src/views/AIchat.vue index 48814cf..d1773ab 100644 --- a/src/views/AIchat.vue +++ b/src/views/AIchat.vue @@ -67,10 +67,25 @@ const playNextAudio = () => { } if (currentPlayIndex >= audioQueue.value.length) { - console.log("所有音频播放完成"); - isPlayingAudio.value = false; + console.log("所有音频播放完成,重置到第一个音频"); + // 播放完成后重置到第一个音频,但不自动播放 + currentPlayIndex = 0; + audioStore.isPlaying = false; + audioStore.isPaused = false; + audioStore.playbackPosition = 0; + // 清除音频实例,确保下次点击从头开始 + audioStore.soundInstance = null; + audioStore.nowSound = null; + if (audioQueue.value.length > 0) { + audioStore.setCurrentAudioUrl(audioQueue.value[0]); + } return; } + // if (currentPlayIndex >= audioQueue.value.length) { + // console.log("所有音频播放完成"); + // isPlayingAudio.value = false; + // return; + // } isCallingPlayNext = true; const audioInfo = audioQueue.value[currentPlayIndex]; @@ -138,6 +153,11 @@ const playNextAudio = () => { audioStore.soundInstance = null; // currentPlayIndex = 0; isCallingPlayNext = false; + + // setTimeout(() => { + // isCallingPlayNext = false; + // playNextAudio(); + // }, 500); // 间隔500ms播放下一个 } }, onstop: () => { @@ -194,7 +214,11 @@ const addToAudioQueue = (url, name) => { !audioStore.isPlaying && audioQueue.value.length === 1 ) { - console.log("✅ 条件满足:没有音频在播放且这是第一个音频,立即开始播放"); + console.log("✅ 条件满足:没有音频在播放且这是第一个音频,立即开始播放", { + isPlayingAudio: isPlayingAudio.value, + audioStoreIsPlaying: audioStore.isPlaying, + queueLength: audioQueue.value.length, + }); playNextAudio(); } else { console.log("⏳ 等待条件:", { @@ -231,13 +255,16 @@ const toggleVoiceForUser = (index) => { ) { return; } + // 先把当前按钮状态修改 chatStore.messages[index].audioStatus = !chatStore.messages[index].audioStatus; // 如果当前按钮和之前的按钮不是同一个则再修改之前的按钮的状态 if (chatStore.currentUserIndex != index) { if (chatStore.currentUserIndex != null) { - audioStore.togglePlayPause(); + if (audioStore.isPlaying) { + audioStore.togglePlayPause(); + } chatStore.messages[chatStore.currentUserIndex].audioStatus = false; } @@ -245,6 +272,22 @@ const toggleVoiceForUser = (index) => { audioPreloadStatus.two = { loaded: false, url: null }; audioPreloadStatus.three = { loaded: false, url: null }; audioPreloadStatus.four = { loaded: false, url: null }; + if (chatStore.messages[index].audioArray[0]) { + audioPreloadStatus.one.loaded = true; + audioPreloadStatus.one.url = chatStore.messages[index].audioArray[0]; + } + if (chatStore.messages[index].audioArray[1]) { + audioPreloadStatus.two.loaded = true; + audioPreloadStatus.two.url = chatStore.messages[index].audioArray[1]; + } + if (chatStore.messages[index].audioArray[2]) { + audioPreloadStatus.three.loaded = true; + audioPreloadStatus.three.url = chatStore.messages[index].audioArray[2]; + } + if (chatStore.messages[index].audioArray[3]) { + audioPreloadStatus.four.loaded = true; + audioPreloadStatus.four.url = chatStore.messages[index].audioArray[3]; + } chatStore.currentUserIndex = index; audioQueue.value = []; isPlayingAudio.value = false; @@ -270,7 +313,17 @@ const toggleVoiceForUser = (index) => { console.log("1111"); audioStore.toggleVoice(); } else { - if (audioStore.currentAudioUrl || audioStore.ttsUrl) { + if (currentPlayIndex >= audioQueue.value.length) { + console.log("重新开始播放音频序列"); + currentPlayIndex = 0; + isPlayingAudio.value = false; + isCallingPlayNext = false; + audioStore.soundInstance = null; + // 重新开始播放 + if (audioQueue.value.length > 0) { + playNextAudio(); + } + } else if (audioStore.currentAudioUrl || audioStore.ttsUrl) { console.log("2222"); audioStore.togglePlayPause(); } else { @@ -540,7 +593,7 @@ const playAudioSequence = (audioUrls) => { // 重写togglePlayPause方法以支持音频序列控制 const originalTogglePlayPause = audioStore.togglePlayPause; audioStore.togglePlayPause = () => { - console.log("音频控制按钮被点击"); + console.log("音频控制按钮被点击 11111111111"); console.log("当前播放状态:", audioStore.isPlaying); console.log("当前暂停状态:", audioStore.isPaused); console.log("当前音频实例:", audioStore.soundInstance); @@ -1225,7 +1278,7 @@ watch( // 重写audioStore的togglePlayPause方法以支持队列播放控制 const originalTogglePlayPause = audioStore.togglePlayPause; audioStore.togglePlayPause = () => { - console.log("主页音频控制按钮被点击22222"); + console.log("主页音频控制按钮被点击22222222222222"); console.log( "当前音频状态 - isPlaying:", audioStore.isPlaying,