From 4e9ec23a747ad08bde4bb0e2203f1bbaee0b519f Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 26 May 2025 16:22:49 +0800 Subject: [PATCH] feat: support configuration of emotion detection --- main/xiaozhi-server/config.yaml | 2 ++ main/xiaozhi-server/core/connection.py | 3 ++- main/xiaozhi-server/core/handle/sendAudioHandle.py | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/main/xiaozhi-server/config.yaml b/main/xiaozhi-server/config.yaml index 44845df84..ce9409591 100644 --- a/main/xiaozhi-server/config.yaml +++ b/main/xiaozhi-server/config.yaml @@ -60,6 +60,8 @@ enable_greeting: true enable_stop_tts_notify: false # 说完话是否开启提示音,音效地址 stop_tts_notify_voice: "config/assets/tts_notify.mp3" +# 是否启用情感检测 +enable_emotion_detection: true exit_commands: - "退出" diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py index ea0be02d3..f5ab7eb15 100644 --- a/main/xiaozhi-server/core/connection.py +++ b/main/xiaozhi-server/core/connection.py @@ -871,8 +871,9 @@ class ConnectionHandler: if self.stop_event.is_set(): break continue + enable_emotion_detection = self.config.get("enable_emotion_detection", True) future = asyncio.run_coroutine_threadsafe( - sendAudioMessage(self, audio_datas, text, text_index), self.loop + sendAudioMessage(self, audio_datas, text, text_index, enable_emotion_detection), self.loop ) future.result() except Exception as e: diff --git a/main/xiaozhi-server/core/handle/sendAudioHandle.py b/main/xiaozhi-server/core/handle/sendAudioHandle.py index 89f164263..a133d4b99 100644 --- a/main/xiaozhi-server/core/handle/sendAudioHandle.py +++ b/main/xiaozhi-server/core/handle/sendAudioHandle.py @@ -30,9 +30,9 @@ emoji_map = { } -async def sendAudioMessage(conn, audios, text, text_index=0): +async def sendAudioMessage(conn, audios, text, text_index=0, enable_emotion_detection=True): # 发送句子开始消息 - if text is not None: + if enable_emotion_detection and text is not None: emotion = analyze_emotion(text) emoji = emoji_map.get(emotion, "🙂") # 默认使用笑脸 await conn.websocket.send(