update:对齐测试页面唤醒流程与硬件设备

This commit is contained in:
3030332422
2026-04-17 11:33:28 +08:00
parent 36ea5c5e13
commit 725c562aa1
4 changed files with 47 additions and 13 deletions
@@ -1,5 +1,8 @@
// 配置管理模块
// 默认唤醒词列表
export const DEFAULT_WAKE_WORDS = '你好小智\n你好小志\n小爱同学\n你好小鑫\n你好小新\n小美同学\n小龙小龙\n喵喵同学\n小滨小滨\n小冰小冰\n嘿你好呀';
// 生成随机MAC地址
function generateRandomMac() {
const hexDigits = '0123456789ABCDEF';
@@ -60,6 +63,8 @@ export function loadConfig() {
const savedWakewordList = localStorage.getItem('xz_tester_wakewordList');
if (savedWakewordList !== null && wakewordListInput) {
wakewordListInput.value = savedWakewordList;
} else if (wakewordListInput) {
wakewordListInput.value = DEFAULT_WAKE_WORDS;
}
}
@@ -203,17 +203,6 @@ export class AudioRecorder {
async start() {
if (this.isRecording) return false;
try {
// Check if WebSocketHandler instance exists
const { getWebSocketHandler } = await import('../network/websocket.js?v=0205');
const wsHandler = getWebSocketHandler();
// If machine is speaking, send abort message
if (wsHandler && wsHandler.isRemoteSpeaking && wsHandler.currentSessionId) {
const abortMessage = { session_id: wsHandler.currentSessionId, type: 'abort', reason: 'wake_word_detected' };
if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {
this.websocket.send(JSON.stringify(abortMessage));
log('已发送中止消息', 'info');
}
}
if (!this.initEncoder()) {
log('无法开始录音: Opus编码器初始化失败', 'error');
return false;
@@ -70,6 +70,28 @@ export class WebSocketHandler {
}
}
_sendWakeupMessages(sessionId) {
if (!this.websocket || this.websocket.readyState !== WebSocket.OPEN) return;
// listen detect
this.websocket.send(JSON.stringify({
session_id: sessionId,
type: 'listen',
state: 'detect',
text: '嘿,你好呀'
}));
log('发送listen detect消息,唤醒词: 嘿,你好呀', 'info');
// listen start:开始监听
this.websocket.send(JSON.stringify({
session_id: sessionId,
type: 'listen',
state: 'start',
mode: 'auto'
}));
log('发送listen start消息', 'info');
}
// 处理文本消息
handleTextMessage(message) {
if (message.type === 'hello') {
@@ -77,6 +99,9 @@ export class WebSocketHandler {
window.cameraAvailable = true;
log('连接成功,摄像头已可用', 'success');
uiController.updateDialButton(true);
this._sendWakeupMessages(message.session_id);
uiController.startAIChatSession();
} else if (message.type === 'tts') {
this.handleTTSMessage(message);