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
@@ -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);