From 7f864eb84d72deefdfca9a09c881bc15da7db00a Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Wed, 28 May 2025 11:23:39 +0800 Subject: [PATCH] =?UTF-8?q?update:=E4=BF=AE=E5=A4=8Dweb=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=B7=A5=E5=85=B7Maximum=20call=20stack=20size=20exceeded=20?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/test/test_page.html | 74 ++++++++++++++----------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/main/xiaozhi-server/test/test_page.html b/main/xiaozhi-server/test/test_page.html index cd55d5fc..fbad025d 100644 --- a/main/xiaozhi-server/test/test_page.html +++ b/main/xiaozhi-server/test/test_page.html @@ -803,7 +803,10 @@ if (frameData && frameData.length > 0) { // 转换为Float32 const floatData = convertInt16ToFloat32(frameData); - decodedSamples.push(...floatData); + // 使用循环替代展开运算符 + for (let i = 0; i < floatData.length; i++) { + decodedSamples.push(floatData[i]); + } } } catch (error) { log("Opus解码失败: " + error.message, 'error'); @@ -811,8 +814,10 @@ } if (decodedSamples.length > 0) { - // 添加到解码队列 - this.queue.push(...decodedSamples); + // 使用循环替代展开运算符 + for (let i = 0; i < decodedSamples.length; i++) { + this.queue.push(decodedSamples[i]); + } this.totalSamples += decodedSamples.length; // 如果累积了至少0.2秒的音频,开始播放 @@ -868,36 +873,39 @@ this.source = null; this.playing = false; - // 如果队列中还有数据或者缓冲区有新数据,继续播放 - if (this.queue.length > 0) { - setTimeout(() => this.startPlaying(), 10); - } else if (audioBufferQueue.length > 0) { - // 缓冲区有新数据,进行解码 - const frames = [...audioBufferQueue]; - audioBufferQueue = []; - this.decodeOpusFrames(frames); - } else if (this.endOfStream) { - // 流已结束且没有更多数据 - log("音频播放完成", 'info'); - isAudioPlaying = false; - this.endOfStream = false; - streamingContext = null; - } else { - // 等待更多数据 - setTimeout(() => { - // 如果仍然没有新数据,但有更多的包到达 - if (this.queue.length === 0 && audioBufferQueue.length > 0) { - const frames = [...audioBufferQueue]; - audioBufferQueue = []; - this.decodeOpusFrames(frames); - } else if (this.queue.length === 0 && audioBufferQueue.length === 0) { - // 真的没有更多数据了 - log("音频播放完成 (超时)", 'info'); - isAudioPlaying = false; - streamingContext = null; - } - }, 500); // 500ms超时 - } + // 使用setTimeout避免递归调用 + setTimeout(() => { + // 如果队列中还有数据,继续播放 + if (this.queue.length > 0) { + this.startPlaying(); + } else if (audioBufferQueue.length > 0) { + // 缓冲区有新数据,进行解码 + const frames = [...audioBufferQueue]; + audioBufferQueue = []; + this.decodeOpusFrames(frames); + } else if (this.endOfStream) { + // 流已结束且没有更多数据 + log("音频播放完成", 'info'); + isAudioPlaying = false; + this.endOfStream = false; + streamingContext = null; + } else { + // 等待更多数据 + setTimeout(() => { + // 如果仍然没有新数据,但有更多的包到达 + if (this.queue.length === 0 && audioBufferQueue.length > 0) { + const frames = [...audioBufferQueue]; + audioBufferQueue = []; + this.decodeOpusFrames(frames); + } else if (this.queue.length === 0 && audioBufferQueue.length === 0) { + // 真的没有更多数据了 + log("音频播放完成 (超时)", 'info'); + isAudioPlaying = false; + streamingContext = null; + } + }, 500); // 500ms超时 + } + }, 10); // 10ms延迟,避免立即递归 }; this.source.start();