From d7564a65f7a15760a36f2c485583f552b6a58448 Mon Sep 17 00:00:00 2001 From: Minamiyama Date: Sun, 25 May 2025 15:24:06 +0800 Subject: [PATCH] =?UTF-8?q?refactor(test=5Fpage.html):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96UI=E5=B8=83=E5=B1=80=E5=92=8C=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在OTA和WebSocket服务器地址输入框中添加更详细的占位符提示 - 增加本地存储功能,保存并恢复OTA和WebSocket服务器地址 --- main/xiaozhi-server/test/test_page.html | 40 ++++++++++++++++--------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/main/xiaozhi-server/test/test_page.html b/main/xiaozhi-server/test/test_page.html index d9b2eff6..d2151acc 100644 --- a/main/xiaozhi-server/test/test_page.html +++ b/main/xiaozhi-server/test/test_page.html @@ -14,7 +14,7 @@ } .container { - max-width: 800px; + max-width: 1000px; margin: 0 auto; background-color: white; border-radius: 10px; @@ -482,9 +482,10 @@
- + + placeholder="WebSocket服务器地址,如:ws://127.0.0.1:8000/xiaozhi/v1/" />
@@ -1061,7 +1062,7 @@ } } - // 初始化音频录制和处理 + // 初始化音频录制和处理 async function initAudio() { try { // 请求麦克风权限 @@ -1306,7 +1307,8 @@ // 先检查OTA状态 log('正在检查OTA状态...', 'info'); const otaUrl = document.getElementById('otaUrl').value.trim(); - + localStorage.setItem('otaUrl', otaUrl); + localStorage.setItem('wsUrl', url); try { const otaResponse = await fetch(otaUrl, { method: 'POST', @@ -1633,6 +1635,16 @@ // 初始更新显示值 updateDisplayValues(); + const savedOtaUrl = localStorage.getItem('otaUrl'); + if (savedOtaUrl) { + document.getElementById('otaUrl').value = savedOtaUrl; + } + + const savedWsUrl = localStorage.getItem('wsUrl'); + if (savedWsUrl) { + document.getElementById('serverUrl').value = savedWsUrl; + } + // 切换面板显示 toggleButton.addEventListener('click', () => { const isExpanded = configPanel.classList.contains('expanded'); @@ -1954,7 +1966,7 @@ this.buffer = new Int16Array(this.frameSize); this.bufferIndex = 0; this.isRecording = false; - + // 监听来自主线程的消息 this.port.onmessage = (event) => { if (event.data.command === 'start') { @@ -1962,7 +1974,7 @@ this.port.postMessage({ type: 'status', status: 'started' }); } else if (event.data.command === 'stop') { this.isRecording = false; - + // 发送剩余的缓冲区 if (this.bufferIndex > 0) { const finalBuffer = this.buffer.slice(0, this.bufferIndex); @@ -1972,18 +1984,18 @@ }); this.bufferIndex = 0; } - + this.port.postMessage({ type: 'status', status: 'stopped' }); } }; } - + process(inputs, outputs, parameters) { if (!this.isRecording) return true; - + const input = inputs[0][0]; // 获取第一个输入通道 if (!input) return true; - + // 将浮点采样转换为16位整数并存储 for (let i = 0; i < input.length; i++) { if (this.bufferIndex >= this.frameSize) { @@ -1994,15 +2006,15 @@ }); this.bufferIndex = 0; } - + // 转换为16位整数 (-32768到32767) this.buffer[this.bufferIndex++] = Math.max(-32768, Math.min(32767, Math.floor(input[i] * 32767))); } - + return true; } } - + registerProcessor('audio-recorder-processor', AudioRecorderProcessor); `;