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");