From 1cff39cec4f57b181cc0c5bf7f077aeb607caf84 Mon Sep 17 00:00:00 2001 From: JianYu Zheng <2375294554@qq.com> Date: Mon, 11 Aug 2025 18:04:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E6=8B=86=E5=88=86te?= =?UTF-8?q?st=5Fpage.html,=E6=8A=8A=E4=B8=80=E9=83=A8=E5=88=86opus?= =?UTF-8?q?=E5=92=8Cdocument=E6=93=8D=E4=BD=9C=E7=9A=84=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=8F=90=E5=8F=96=E5=87=BA=E6=9D=A5=EF=BC=8C=E5=87=8F=E5=B0=91?= =?UTF-8?q?=E5=8D=95=E4=B8=AA=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/test/js/document.js | 11 ++++++ main/xiaozhi-server/test/js/opus.js | 43 ++++++++++++++++++++ main/xiaozhi-server/test/test_page.html | 52 +------------------------ 3 files changed, 55 insertions(+), 51 deletions(-) create mode 100644 main/xiaozhi-server/test/js/opus.js diff --git a/main/xiaozhi-server/test/js/document.js b/main/xiaozhi-server/test/js/document.js index 508a1463..eb23247e 100644 --- a/main/xiaozhi-server/test/js/document.js +++ b/main/xiaozhi-server/test/js/document.js @@ -26,3 +26,14 @@ export function getLogContainer (flan) { return logContainer; } +// 更新Opus库状态显示 +export function updateScriptStatus(message, type) { + const statusElement = document.getElementById('scriptStatus'); + if (statusElement) { + statusElement.textContent = message; + statusElement.className = `script-status ${type}`; + statusElement.style.display = 'block'; + statusElement.style.width = 'auto'; + } +} + diff --git a/main/xiaozhi-server/test/js/opus.js b/main/xiaozhi-server/test/js/opus.js new file mode 100644 index 00000000..9259b9de --- /dev/null +++ b/main/xiaozhi-server/test/js/opus.js @@ -0,0 +1,43 @@ +import { log } from './utils/logger.js'; +import { updateScriptStatus } from './document.js' + + +// 检查Opus库是否已加载 +export function checkOpusLoaded() { + try { + // 检查Module是否存在(本地库导出的全局变量) + if (typeof Module === 'undefined') { + throw new Error('Opus库未加载,Module对象不存在'); + } + + // 尝试先使用Module.instance(libopus.js最后一行导出方式) + if (typeof Module.instance !== 'undefined' && typeof Module.instance._opus_decoder_get_size === 'function') { + // 使用Module.instance对象替换全局Module对象 + window.ModuleInstance = Module.instance; + log('Opus库加载成功(使用Module.instance)', 'success'); + updateScriptStatus('Opus库加载成功', 'success'); + + // 3秒后隐藏状态 + const statusElement = document.getElementById('scriptStatus'); + if (statusElement) statusElement.style.display = 'none'; + return; + } + + // 如果没有Module.instance,检查全局Module函数 + if (typeof Module._opus_decoder_get_size === 'function') { + window.ModuleInstance = Module; + log('Opus库加载成功(使用全局Module)', 'success'); + updateScriptStatus('Opus库加载成功', 'success'); + + // 3秒后隐藏状态 + const statusElement = document.getElementById('scriptStatus'); + if (statusElement) statusElement.style.display = 'none'; + return; + } + + throw new Error('Opus解码函数未找到,可能Module结构不正确'); + } catch (err) { + log(`Opus库加载失败,请检查libopus.js文件是否存在且正确: ${err.message}`, 'error'); + updateScriptStatus('Opus库加载失败,请检查libopus.js文件是否存在且正确', 'error'); + } +} \ No newline at end of file diff --git a/main/xiaozhi-server/test/test_page.html b/main/xiaozhi-server/test/test_page.html index cb711f27..cca6fc35 100644 --- a/main/xiaozhi-server/test/test_page.html +++ b/main/xiaozhi-server/test/test_page.html @@ -102,6 +102,7 @@