增加麦克风、扬声器同步接口及gui定时同步机制

This commit is contained in:
guo zebin
2026-01-05 19:08:27 +08:00
parent dc39296471
commit b5fffae46c
2 changed files with 49 additions and 1 deletions

View File

@@ -575,6 +575,20 @@ def api_get_system_status():
except Exception as e:
return jsonify({'server': False, 'digital_human': False, 'remote_audio': False, 'error': str(e)}), 500
@__app.route('/api/get-audio-config', methods=['GET'])
def api_get_audio_config():
"""获取麦克风和扬声器的配置状态"""
try:
mic_enabled = config_util.config.get('source', {}).get('record', {}).get('enabled', False)
speaker_enabled = config_util.config.get('interact', {}).get('playSound', False)
return jsonify({
'mic': mic_enabled,
'speaker': speaker_enabled
})
except Exception as e:
return jsonify({'mic': False, 'speaker': False, 'error': str(e)}), 500
@__app.route('/api/adopt-msg', methods=['POST'])
def adopt_msg():
# 采纳消息

View File

@@ -336,6 +336,7 @@ new Vue({
remote_audio: false
},
systemStatusTimer: null,
audioConfigTimer: null,
addUserDialogVisible: false,
newUsername: '',
extraInfoDialogVisible: false,
@@ -353,12 +354,13 @@ new Vue({
// 消息列表变化时的监听(保留用于其他扩展)
},
created() {
this.initFayService();
this.initFayService();
this.getData();
this.startUserListTimer();
this.checkMcpStatus();
this.startMcpStatusTimer();
this.startSystemStatusTimer();
this.startAudioConfigSyncTimer();
},
methods: {
// 检查系统各组件连接状态
@@ -403,6 +405,38 @@ new Vue({
}, 3000);
},
// 同步音频配置(麦克风和扬声器开关状态)
syncAudioConfig() {
const url = `${this.base_url}/api/get-audio-config`;
fetch(url)
.then(response => response.json())
.then(data => {
if (data.mic !== undefined) {
this.source_record_enabled = data.mic;
}
if (data.speaker !== undefined) {
this.play_sound_enabled = data.speaker;
}
})
.catch(error => {
console.warn('同步音频配置失败:', error);
});
},
// 启动音频配置同步定时器(每分钟同步一次)
startAudioConfigSyncTimer() {
// 立即执行一次
this.syncAudioConfig();
if (this.audioConfigTimer) {
clearInterval(this.audioConfigTimer);
}
// 每60秒同步一次
this.audioConfigTimer = setInterval(() => {
this.syncAudioConfig();
}, 60000);
},
initFayService() {
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsHost = window.location.hostname;