From 8fb1e3c963fb9c8b680b046f53f64487bec6f52f Mon Sep 17 00:00:00 2001 From: Song367 <601337784@qq.com> Date: Tue, 21 Oct 2025 11:10:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=92=AD=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/minimaxi_stream.js | 43 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/src/minimaxi_stream.js b/src/minimaxi_stream.js index 0703758..556150d 100644 --- a/src/minimaxi_stream.js +++ b/src/minimaxi_stream.js @@ -56,56 +56,43 @@ let isFirstChunk = true; // 队列处理器 - 独立运行,按顺序播放音频 async function processAudioQueue() { if (isProcessingQueue) return; - isProcessingQueue = true; - - + while (audioQueue.length > 0 && !isPlaying) { console.log('开始处理音频队列'); - // 如果当前没有音频在播放,且队列中有音频 if (!isPlaying && audioQueue.length > 0) { const audioItem = audioQueue.shift(); - const sayName = '8-4-sh' - const targetVideo = window.webrtcApp.interactionVideo - // 如果是第一个音频片段,触发视频切换 + const sayName = '8-4-sh'; + const targetVideo = window.webrtcApp.interactionVideo; + if (sayName != window.webrtcApp.currentVideoTag && window.webrtcApp && window.webrtcApp.switchVideoStream) { try { - // 检查WebSocket连接状态 + // 检查WebSocket连接状态(仅影响服务端广播,不阻断本地播放) if (window.webrtcApp.checkConnectionStatus && !window.webrtcApp.checkConnectionStatus()) { - console.log('WebSocket连接异常,跳过视频切换'); - return; + console.log('WebSocket连接异常,继续本地播放并切换视频'); + } else { + console.log('--------------触发视频切换:', sayName); + window.webrtcApp.switchVideoStream(targetVideo, 'audio', '8-4-sh'); } - - console.log('--------------触发视频切换:', sayName); - window.webrtcApp.switchVideoStream(targetVideo, 'audio', '8-4-sh'); isFirstChunk = false; window.webrtcApp.currentVideoTag = sayName; } catch (error) { console.error('视频切换失败:', error); } } + await playAudioData(audioItem.audioData); } else { - // 等待一小段时间再检查 await new Promise(resolve => setTimeout(resolve, 50)); } } - + isProcessingQueue = false; - - // 等待当前音频播放完成后再切换回默认视频 - // while (isPlaying) { - // console.log("触发音频等待") - // await new Promise(resolve => setTimeout(resolve, 1000)); - // } - // console.log("触发音频等待") - // await new Promise(resolve => setTimeout(resolve, 300)); - - const text = 'default' - console.log("音频结束------------------------:", window.webrtcApp.currentVideoTag, isPlaying) + const text = 'default'; + console.log("音频结束------------------------:", window.webrtcApp.currentVideoTag, isPlaying); if (window.webrtcApp.currentVideoTag != text && !isPlaying) { - isFirstChunk = true - window.webrtcApp.currentVideoTag = text + isFirstChunk = true; + window.webrtcApp.currentVideoTag = text; window.webrtcApp.switchVideoStream(window.webrtcApp.defaultVideo, 'audio', text); } console.log('音频队列处理完成');