feat: support configuration of emotion detection

This commit is contained in:
ed 2025-05-26 16:22:49 +08:00
parent ed144177bf
commit 4e9ec23a74
3 changed files with 6 additions and 3 deletions

View file

@ -60,6 +60,8 @@ enable_greeting: true
enable_stop_tts_notify: false enable_stop_tts_notify: false
# 说完话是否开启提示音,音效地址 # 说完话是否开启提示音,音效地址
stop_tts_notify_voice: "config/assets/tts_notify.mp3" stop_tts_notify_voice: "config/assets/tts_notify.mp3"
# 是否启用情感检测
enable_emotion_detection: true
exit_commands: exit_commands:
- "退出" - "退出"

View file

@ -871,8 +871,9 @@ class ConnectionHandler:
if self.stop_event.is_set(): if self.stop_event.is_set():
break break
continue continue
enable_emotion_detection = self.config.get("enable_emotion_detection", True)
future = asyncio.run_coroutine_threadsafe( 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() future.result()
except Exception as e: except Exception as e:

View file

@ -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) emotion = analyze_emotion(text)
emoji = emoji_map.get(emotion, "🙂") # 默认使用笑脸 emoji = emoji_map.get(emotion, "🙂") # 默认使用笑脸
await conn.websocket.send( await conn.websocket.send(