mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-29 11:53:55 +08:00
feat: implement Issue 2896 - Live2D Actions and Microphone Detection
- Add Live2D action tools (smile, wave, generic actions) as MCP tools - Implement microphone availability detection - Handle HTTP non-localhost access scenarios - Update UI to reflect microphone availability state - Translate all comments and messages to proper Chinese/English - Add test files for new functionality
This commit is contained in:
@@ -4,6 +4,7 @@ import { checkOpusLoaded, initOpusEncoder } from './core/audio/opus-codec.js';
|
||||
import { uiController } from './ui/controller.js';
|
||||
import { getAudioPlayer } from './core/audio/player.js';
|
||||
import { initMcpTools } from './core/mcp/tools.js';
|
||||
import { checkMicrophoneAvailability, isHttpNonLocalhost } from './core/audio/recorder.js';
|
||||
|
||||
// 应用类
|
||||
class App {
|
||||
@@ -34,6 +35,9 @@ class App {
|
||||
// 初始化MCP工具
|
||||
initMcpTools();
|
||||
|
||||
// 检查麦克风可用性
|
||||
await this.checkMicrophoneAvailability();
|
||||
|
||||
// 初始化Live2D
|
||||
await this.initLive2D();
|
||||
|
||||
@@ -81,6 +85,36 @@ class App {
|
||||
modelLoading.style.display = isLoading ? 'flex' : 'none';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查麦克风可用性
|
||||
* 在应用初始化时调用,检查麦克风是否可用并更新UI状态
|
||||
*/
|
||||
async checkMicrophoneAvailability() {
|
||||
try {
|
||||
const isAvailable = await checkMicrophoneAvailability();
|
||||
const isHttp = isHttpNonLocalhost();
|
||||
|
||||
// 保存可用性状态到全局变量
|
||||
window.microphoneAvailable = isAvailable;
|
||||
window.isHttpNonLocalhost = isHttp;
|
||||
|
||||
// 更新UI
|
||||
if (this.uiController) {
|
||||
this.uiController.updateMicrophoneAvailability(isAvailable, isHttp);
|
||||
}
|
||||
|
||||
log(`麦克风可用性检查完成: ${isAvailable ? '可用' : '不可用'}`, isAvailable ? 'success' : 'warning');
|
||||
} catch (error) {
|
||||
log(`检查麦克风可用性失败: ${error.message}`, 'error');
|
||||
// 默认设置为不可用
|
||||
window.microphoneAvailable = false;
|
||||
window.isHttpNonLocalhost = isHttpNonLocalhost();
|
||||
if (this.uiController) {
|
||||
this.uiController.updateMicrophoneAvailability(false, window.isHttpNonLocalhost);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 创建并启动应用
|
||||
@@ -95,4 +129,4 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
|
||||
|
||||
export default app;
|
||||
export default app;
|
||||
Reference in New Issue
Block a user