mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
update:对齐测试页面唤醒流程与硬件设备
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
// 配置管理模块
|
// 配置管理模块
|
||||||
|
|
||||||
|
// 默认唤醒词列表
|
||||||
|
export const DEFAULT_WAKE_WORDS = '你好小智\n你好小志\n小爱同学\n你好小鑫\n你好小新\n小美同学\n小龙小龙\n喵喵同学\n小滨小滨\n小冰小冰\n嘿你好呀';
|
||||||
|
|
||||||
// 生成随机MAC地址
|
// 生成随机MAC地址
|
||||||
function generateRandomMac() {
|
function generateRandomMac() {
|
||||||
const hexDigits = '0123456789ABCDEF';
|
const hexDigits = '0123456789ABCDEF';
|
||||||
@@ -60,6 +63,8 @@ export function loadConfig() {
|
|||||||
const savedWakewordList = localStorage.getItem('xz_tester_wakewordList');
|
const savedWakewordList = localStorage.getItem('xz_tester_wakewordList');
|
||||||
if (savedWakewordList !== null && wakewordListInput) {
|
if (savedWakewordList !== null && wakewordListInput) {
|
||||||
wakewordListInput.value = savedWakewordList;
|
wakewordListInput.value = savedWakewordList;
|
||||||
|
} else if (wakewordListInput) {
|
||||||
|
wakewordListInput.value = DEFAULT_WAKE_WORDS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -203,17 +203,6 @@ export class AudioRecorder {
|
|||||||
async start() {
|
async start() {
|
||||||
if (this.isRecording) return false;
|
if (this.isRecording) return false;
|
||||||
try {
|
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()) {
|
if (!this.initEncoder()) {
|
||||||
log('无法开始录音: Opus编码器初始化失败', 'error');
|
log('无法开始录音: Opus编码器初始化失败', 'error');
|
||||||
return false;
|
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) {
|
handleTextMessage(message) {
|
||||||
if (message.type === 'hello') {
|
if (message.type === 'hello') {
|
||||||
@@ -77,6 +99,9 @@ export class WebSocketHandler {
|
|||||||
window.cameraAvailable = true;
|
window.cameraAvailable = true;
|
||||||
log('连接成功,摄像头已可用', 'success');
|
log('连接成功,摄像头已可用', 'success');
|
||||||
uiController.updateDialButton(true);
|
uiController.updateDialButton(true);
|
||||||
|
|
||||||
|
this._sendWakeupMessages(message.session_id);
|
||||||
|
|
||||||
uiController.startAIChatSession();
|
uiController.startAIChatSession();
|
||||||
} else if (message.type === 'tts') {
|
} else if (message.type === 'tts') {
|
||||||
this.handleTTSMessage(message);
|
this.handleTTSMessage(message);
|
||||||
|
|||||||
@@ -120,10 +120,25 @@ def load_config(runtime_root: Path) -> RuntimeConfig:
|
|||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_WAKE_WORDS = [
|
||||||
|
"你好小智",
|
||||||
|
"你好小志",
|
||||||
|
"小爱同学",
|
||||||
|
"你好小鑫",
|
||||||
|
"你好小新",
|
||||||
|
"小美同学",
|
||||||
|
"小龙小龙",
|
||||||
|
"喵喵同学",
|
||||||
|
"小滨小滨",
|
||||||
|
"小冰小冰",
|
||||||
|
"嘿你好呀",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def _load_wake_words_from_keywords_file(model_dir: Path) -> list[str]:
|
def _load_wake_words_from_keywords_file(model_dir: Path) -> list[str]:
|
||||||
keywords_file = model_dir / "keywords.txt"
|
keywords_file = model_dir / "keywords.txt"
|
||||||
if not keywords_file.exists():
|
if not keywords_file.exists():
|
||||||
return []
|
return DEFAULT_WAKE_WORDS.copy()
|
||||||
|
|
||||||
wake_words: list[str] = []
|
wake_words: list[str] = []
|
||||||
for line in keywords_file.read_text(encoding="utf-8").splitlines():
|
for line in keywords_file.read_text(encoding="utf-8").splitlines():
|
||||||
@@ -135,4 +150,4 @@ def _load_wake_words_from_keywords_file(model_dir: Path) -> list[str]:
|
|||||||
if wake_word:
|
if wake_word:
|
||||||
wake_words.append(wake_word)
|
wake_words.append(wake_word)
|
||||||
|
|
||||||
return wake_words
|
return wake_words if wake_words else DEFAULT_WAKE_WORDS.copy()
|
||||||
|
|||||||
Reference in New Issue
Block a user