Merge pull request #1377 from xinnan-tech/py_test_page.html_fix

Py test page.html fix
This commit is contained in:
Sakura-RanChen
2025-05-26 15:43:12 +08:00
committed by GitHub
2 changed files with 32 additions and 15 deletions
+1 -1
View File
@@ -467,7 +467,7 @@ export default {
.main-wrapper { .main-wrapper {
margin: 5px 22px; margin: 5px 22px;
border-radius: 15px; border-radius: 15px;
min-height: calc(100vh - 24vh); min-height: calc(100vh - 26vh);
height: auto; height: auto;
max-height: 80vh; max-height: 80vh;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1); box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
+31 -14
View File
@@ -14,7 +14,7 @@
} }
.container { .container {
max-width: 800px; max-width: 1000px;
margin: 0 auto; margin: 0 auto;
background-color: white; background-color: white;
border-radius: 10px; border-radius: 10px;
@@ -482,9 +482,10 @@
</span> </span>
</h2> </h2>
<div class="connection-controls"> <div class="connection-controls">
<input type="text" id="otaUrl" value="http://127.0.0.1:8002/xiaozhi/ota/" placeholder="OTA服务器地址" /> <input type="text" id="otaUrl" value="http://127.0.0.1:8002/xiaozhi/ota/"
placeholder="OTA服务器地址,如:http://127.0.0.1:8002/xiaozhi/ota/" />
<input type="text" id="serverUrl" value="ws://127.0.0.1:8000/xiaozhi/v1/" <input type="text" id="serverUrl" value="ws://127.0.0.1:8000/xiaozhi/v1/"
placeholder="WebSocket服务器地址" /> placeholder="WebSocket服务器地址,如:ws://127.0.0.1:8000/xiaozhi/v1/" />
<button id="connectButton">连接</button> <button id="connectButton">连接</button>
<button id="authTestButton">测试认证</button> <button id="authTestButton">测试认证</button>
</div> </div>
@@ -879,6 +880,7 @@
// 流已结束且没有更多数据 // 流已结束且没有更多数据
log("音频播放完成", 'info'); log("音频播放完成", 'info');
isAudioPlaying = false; isAudioPlaying = false;
this.endOfStream = false;
streamingContext = null; streamingContext = null;
} else { } else {
// 等待更多数据 // 等待更多数据
@@ -1061,7 +1063,7 @@
} }
} }
// 初始化音频录制和处理 // 初始化音频录制和处理
async function initAudio() { async function initAudio() {
try { try {
// 请求麦克风权限 // 请求麦克风权限
@@ -1306,7 +1308,8 @@
// 先检查OTA状态 // 先检查OTA状态
log('正在检查OTA状态...', 'info'); log('正在检查OTA状态...', 'info');
const otaUrl = document.getElementById('otaUrl').value.trim(); const otaUrl = document.getElementById('otaUrl').value.trim();
localStorage.setItem('otaUrl', otaUrl);
localStorage.setItem('wsUrl', url);
try { try {
const otaResponse = await fetch(otaUrl, { const otaResponse = await fetch(otaUrl, {
method: 'POST', method: 'POST',
@@ -1563,6 +1566,10 @@
const message = messageInput.value.trim(); const message = messageInput.value.trim();
if (message === '' || !websocket || websocket.readyState !== WebSocket.OPEN) return; if (message === '' || !websocket || websocket.readyState !== WebSocket.OPEN) return;
audioBufferQueue = [];
isAudioBuffering = false;
isAudioPlaying = false;
try { try {
// 直接发送listen消息,不需要重复发送hello // 直接发送listen消息,不需要重复发送hello
const listenMessage = { const listenMessage = {
@@ -1633,6 +1640,16 @@
// 初始更新显示值 // 初始更新显示值
updateDisplayValues(); 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', () => { toggleButton.addEventListener('click', () => {
const isExpanded = configPanel.classList.contains('expanded'); const isExpanded = configPanel.classList.contains('expanded');
@@ -1954,7 +1971,7 @@
this.buffer = new Int16Array(this.frameSize); this.buffer = new Int16Array(this.frameSize);
this.bufferIndex = 0; this.bufferIndex = 0;
this.isRecording = false; this.isRecording = false;
// 监听来自主线程的消息 // 监听来自主线程的消息
this.port.onmessage = (event) => { this.port.onmessage = (event) => {
if (event.data.command === 'start') { if (event.data.command === 'start') {
@@ -1962,7 +1979,7 @@
this.port.postMessage({ type: 'status', status: 'started' }); this.port.postMessage({ type: 'status', status: 'started' });
} else if (event.data.command === 'stop') { } else if (event.data.command === 'stop') {
this.isRecording = false; this.isRecording = false;
// 发送剩余的缓冲区 // 发送剩余的缓冲区
if (this.bufferIndex > 0) { if (this.bufferIndex > 0) {
const finalBuffer = this.buffer.slice(0, this.bufferIndex); const finalBuffer = this.buffer.slice(0, this.bufferIndex);
@@ -1972,18 +1989,18 @@
}); });
this.bufferIndex = 0; this.bufferIndex = 0;
} }
this.port.postMessage({ type: 'status', status: 'stopped' }); this.port.postMessage({ type: 'status', status: 'stopped' });
} }
}; };
} }
process(inputs, outputs, parameters) { process(inputs, outputs, parameters) {
if (!this.isRecording) return true; if (!this.isRecording) return true;
const input = inputs[0][0]; // 获取第一个输入通道 const input = inputs[0][0]; // 获取第一个输入通道
if (!input) return true; if (!input) return true;
// 将浮点采样转换为16位整数并存储 // 将浮点采样转换为16位整数并存储
for (let i = 0; i < input.length; i++) { for (let i = 0; i < input.length; i++) {
if (this.bufferIndex >= this.frameSize) { if (this.bufferIndex >= this.frameSize) {
@@ -1994,15 +2011,15 @@
}); });
this.bufferIndex = 0; this.bufferIndex = 0;
} }
// 转换为16位整数 (-32768到32767) // 转换为16位整数 (-32768到32767)
this.buffer[this.bufferIndex++] = Math.max(-32768, Math.min(32767, Math.floor(input[i] * 32767))); this.buffer[this.bufferIndex++] = Math.max(-32768, Math.min(32767, Math.floor(input[i] * 32767)));
} }
return true; return true;
} }
} }
registerProcessor('audio-recorder-processor', AudioRecorderProcessor); registerProcessor('audio-recorder-processor', AudioRecorderProcessor);
`; `;