From 562424b74db9d2e25fab3f69267ed99f33058f4c Mon Sep 17 00:00:00 2001 From: CGD <3030332422@qq.com> Date: Sun, 25 May 2025 00:09:36 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E2=80=9C?= =?UTF-8?q?=E5=B0=8F=E6=99=BA=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=92=AD=E6=94=BE=E8=AF=AD=E9=9F=B3=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/test/test_page.html | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/main/xiaozhi-server/test/test_page.html b/main/xiaozhi-server/test/test_page.html index d9b2eff6..1df5cae2 100644 --- a/main/xiaozhi-server/test/test_page.html +++ b/main/xiaozhi-server/test/test_page.html @@ -879,6 +879,7 @@ // 流已结束且没有更多数据 log("音频播放完成", 'info'); isAudioPlaying = false; + this.endOfStream = false; streamingContext = null; } else { // 等待更多数据 @@ -1409,6 +1410,17 @@ }; websocket.onclose = () => { + + // 清理音频缓冲和播放状态 + audioBufferQueue = []; + isAudioBuffering = false; + isAudioPlaying = false; + streamingContext = null; + if (visualizationRequest) { + cancelAnimationFrame(visualizationRequest); + visualizationRequest = null; + } + log('已断开连接', 'info'); connectionStatus.textContent = 'ws已断开'; connectionStatus.style.color = 'red'; @@ -1563,6 +1575,10 @@ const message = messageInput.value.trim(); if (message === '' || !websocket || websocket.readyState !== WebSocket.OPEN) return; + audioBufferQueue = []; + isAudioBuffering = false; + isAudioPlaying = false; + try { // 直接发送listen消息,不需要重复发送hello const listenMessage = { @@ -2382,6 +2398,8 @@ // 如果收到的是第一个音频包,开始缓冲过程 if (audioBufferQueue.length === 1 && !isAudioBuffering && !isAudioPlaying) { startAudioBuffering(); + } else if (isAudioPlaying && streamingContext) { + streamingContext.decodeOpusFrames([opusData]); } } else { log('收到空音频数据帧,可能是结束标志', 'warning');