diff --git a/.gitignore b/.gitignore
index 1f018d373..c195e9f4f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -146,6 +146,7 @@ tmp
.history
.DS_Store
main/xiaozhi-server/data
+main/xiaozhi-server/config/assets/wakeup_words.*
main/manager-web/node_modules
.config.yaml
.secrets.yaml
diff --git a/main/manager-web/src/apis/module/user.js b/main/manager-web/src/apis/module/user.js
index bf3eea34d..2e9bc6e29 100755
--- a/main/manager-web/src/apis/module/user.js
+++ b/main/manager-web/src/apis/module/user.js
@@ -206,5 +206,20 @@ export default {
});
}).send();
},
+ // 删除智能体
+ deleteAgent(agentId, callback) {
+ RequestService.sendRequest()
+ .url(`${getServiceUrl()}/api/v1/user/agent/${agentId}`)
+ .method('DELETE')
+ .success((res) => {
+ RequestService.clearRequestTime();
+ callback(res);
+ })
+ .fail(() => {
+ RequestService.reAjaxFun(() => {
+ this.deleteAgent(agentId, callback);
+ });
+ }).send();
+ },
}
diff --git a/main/manager-web/src/components/DeviceItem.vue b/main/manager-web/src/components/DeviceItem.vue
index 912fd9d5d..cb8783886 100644
--- a/main/manager-web/src/components/DeviceItem.vue
+++ b/main/manager-web/src/components/DeviceItem.vue
@@ -6,7 +6,7 @@

+ style="width: 18px;height: 18px;margin-right: 10px;" @click.stop="handleDelete" />
@@ -44,6 +44,11 @@ export default {
},
data() {
return { switchValue: false }
+ },
+ methods: {
+ handleDelete() {
+ this.$emit('delete', this.device.agentId)
+ }
}
}
diff --git a/main/manager-web/src/components/EditVoiceDialog.vue b/main/manager-web/src/components/EditVoiceDialog.vue
new file mode 100644
index 000000000..b7feb78d0
--- /dev/null
+++ b/main/manager-web/src/components/EditVoiceDialog.vue
@@ -0,0 +1,149 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/main/manager-web/src/components/HeaderBar.vue b/main/manager-web/src/components/HeaderBar.vue
index afd1e1bb8..a8dff30cb 100644
--- a/main/manager-web/src/components/HeaderBar.vue
+++ b/main/manager-web/src/components/HeaderBar.vue
@@ -8,13 +8,11 @@
智能体管理
-
-
- 控制台
+
+ 用户管理
-
- 设备管理
-

+
+ 模型配置
@@ -27,7 +25,7 @@
- {{ userInfo.username || '加载中...' }}
+ {{ userInfo.username }}
个人中心
@@ -64,10 +62,19 @@ export default {
// 跳转到首页
this.$router.push('/')
},
+ goUserManagement() {
+ this.$router.push('/user-management')
+ },
+ goModelConfig() {
+ this.$router.push('/model-config')
+ },
// 获取用户信息
fetchUserInfo() {
userApi.getUserInfo(({data}) => {
- this.userInfo = data.data
+ this.userInfo = {
+ username: data.data.mobile, // 暂时先使用手机号作为用户名
+ mobile: data.data.mobile
+ }
})
},
@@ -117,18 +124,24 @@ export default {
}
.equipment-management2 {
- width: 87px;
- height: 22px;
- border-radius: 11px;
+ width: 82px;
+ height: 24px;
+ border-radius: 12px;
background: #fff;
display: flex;
justify-content: center;
- font-size: 9px;
- font-weight: 400;
+ font-size: 10px;
+ font-weight: 500;
gap: 7px;
color: #3d4566;
- margin-left: 2px;
+ margin-left: 1px;
align-items: center;
+ transition: all 0.3s ease;
+}
+
+.equipment-management2.active-tab {
+ background: #5778ff !important;
+ color: #fff !important;
}
.header {
@@ -168,28 +181,4 @@ export default {
color: #3d4566;
}
-.console {
- width: 90px;
- height: 22px;
- border-radius: 11px;
- background: radial-gradient(50% 50% at 50% 50%, #fff 0%, #e8f0ff 100%);
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 9px;
- color: #979db1;
- font-weight: 400;
- gap: 7px;
- margin-left: 15px;
-}
-
-.el-dropdown-link {
- cursor: pointer;
- color: #5778ff;
-}
-
-.el-icon-arrow-down {
- font-size: 12px;
-}
-
diff --git a/main/manager-web/src/components/ModelEditDialog.vue b/main/manager-web/src/components/ModelEditDialog.vue
new file mode 100644
index 000000000..09e5570c5
--- /dev/null
+++ b/main/manager-web/src/components/ModelEditDialog.vue
@@ -0,0 +1,159 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 设成默认
+
+ 是否启用
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/main/manager-web/src/components/TtsModel.vue b/main/manager-web/src/components/TtsModel.vue
new file mode 100644
index 000000000..92b107ed6
--- /dev/null
+++ b/main/manager-web/src/components/TtsModel.vue
@@ -0,0 +1,194 @@
+
+
+
+
+
+
+
+
+
+
+ 查询
+ 添加音色
+ 批量删除
+
+
+
+
+
+
+
+
+
+ 修改
+ 删除
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/main/manager-web/src/router/index.js b/main/manager-web/src/router/index.js
index d3add00ae..6bc588230 100644
--- a/main/manager-web/src/router/index.js
+++ b/main/manager-web/src/router/index.js
@@ -39,15 +39,30 @@ const routes = [
return import('../views/register.vue')
}
},
- // 新增设备管理页面路由
+ // 设备管理页面路由
{
path: '/device-management',
name: 'DeviceManagement',
component: function () {
return import('../views/DeviceManagement.vue')
}
+ },
+ // 添加用户管理路由
+ {
+ path: '/user-management',
+ name: 'UserManagement',
+ component: function () {
+ return import('../views/UserManagement.vue')
+ }
+ },
+ {
+ path: '/model-config',
+ name: 'ModelConfig',
+ component: function () {
+ return import('../views/ModelConfig.vue')
+ }
+ },
- }
]
const router = new VueRouter({
diff --git a/main/manager-web/src/views/DeviceManagement.vue b/main/manager-web/src/views/DeviceManagement.vue
index 06c4317c6..03939a283 100644
--- a/main/manager-web/src/views/DeviceManagement.vue
+++ b/main/manager-web/src/views/DeviceManagement.vue
@@ -9,11 +9,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -85,7 +85,7 @@ export default {
remark: '生产环境设备',
isEdit: false,
otaSwitch: false
- }
+ },
]
};
},
diff --git a/main/manager-web/src/views/ModelConfig.vue b/main/manager-web/src/views/ModelConfig.vue
new file mode 100644
index 000000000..720b7c362
--- /dev/null
+++ b/main/manager-web/src/views/ModelConfig.vue
@@ -0,0 +1,199 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 模型设置
+ 导入导出配置
+
+
+
+
+
+
+
+
+ 查询
+ 增加模型
+ 批量删除
+
+
+
+
+
+
+
+
+ {{ scope.row.isApplied ? '是' : '否' }}
+
+
+
+
+
+
+ 修改
+ 删除
+
+
+
+
+
+
+
+
+ ©2025 xiaozhi-esp32-server
+
+
+
+
+
+
+
+
+
+
diff --git a/main/manager-web/src/views/UserManagement.vue b/main/manager-web/src/views/UserManagement.vue
new file mode 100644
index 000000000..9ccc5989d
--- /dev/null
+++ b/main/manager-web/src/views/UserManagement.vue
@@ -0,0 +1,145 @@
+
+
+
+
+
+
+
+ 查询
+ 批量删除
+ 批量禁用
+
+
+
+
+
+
+
+
+
+ 重置密码
+ 禁用
+ 恢复
+ 删除用户
+
+
+
+
+
+
+
+
+ ©2025 xiaozhi-esp32-server
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main/manager-web/src/views/home.vue b/main/manager-web/src/views/home.vue
index 0c914e772..9b8e6949d 100644
--- a/main/manager-web/src/views/home.vue
+++ b/main/manager-web/src/views/home.vue
@@ -31,7 +31,11 @@
-
+
@@ -83,16 +87,37 @@ export default {
fetchAgentList() {
import('@/apis/module/user').then(({ default: userApi }) => {
userApi.getAgentList(({data}) => {
- this.originalDevices = data.data;
- this.devices = data.data;
+ this.originalDevices = data.data.map(item => ({
+ ...item,
+ agentId: item.id // 字段映射
+ }));
+ this.devices = this.originalDevices;
});
});
},
// 搜索更新智能体列表
handleSearchResult(filteredList) {
this.devices = filteredList; // 更新设备列表
+ },
+ // 删除智能体
+ handleDeleteAgent(agentId) {
+ this.$confirm('确定要删除该智能体吗?', '提示', {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ type: 'warning'
+ }).then(() => {
+ import('@/apis/module/user').then(({ default: userApi }) => {
+ userApi.deleteAgent(agentId, (res) => {
+ if (res.data.code === 0) {
+ this.$message.success('删除成功');
+ this.fetchAgentList(); // 刷新列表
+ } else {
+ this.$message.error(res.data.msg || '删除失败');
+ }
+ });
+ });
+ }).catch(() => {});
}
-
}
}
diff --git a/main/manager-web/src/views/roleConfig.vue b/main/manager-web/src/views/roleConfig.vue
index 77ecc85fd..d0f0000e4 100644
--- a/main/manager-web/src/views/roleConfig.vue
+++ b/main/manager-web/src/views/roleConfig.vue
@@ -125,11 +125,11 @@ export default {
],
models: [
{ label: '大语言模型(LLM)', key: 'llm' },
- { label: '语音转文本模型(ASR)', key: 'asr' },
+ { label: '语音识别(ASR)', key: 'asr' },
{ label: '语音活动检测模型(VAD)', key: 'vad' },
- { label: '语音生成模型(TTS)', key: 'tts' },
- { label: '意图分类模型(Intent)', key: 'intent' },
- { label: '记忆增强模型(Memory)', key: 'memory' }
+ { label: '语音合成模型(TTS)', key: 'tts' },
+ { label: '意图识别模型(Intent)', key: 'intent' },
+ { label: '记忆模型(Memory)', key: 'memory' }
],
templates: ['台湾女友', '土豆子', '英语老师', '好奇小男孩', '汪汪队队长']
diff --git a/main/xiaozhi-server/config.yaml b/main/xiaozhi-server/config.yaml
index 9221b4714..2fe438cf4 100644
--- a/main/xiaozhi-server/config.yaml
+++ b/main/xiaozhi-server/config.yaml
@@ -57,6 +57,14 @@ delete_audio: true
close_connection_no_voice_time: 120
# TTS请求超时时间(秒)
tts_timeout: 10
+# 开启唤醒词加速
+enable_wakeup_words_response_cache: true
+# 开场是否回复唤醒词
+enable_greeting: true
+# 说完话是否开启提示音
+enable_stop_tts_notify: false
+# 说完话是否开启提示音,音效地址
+stop_tts_notify_voice: "config/assets/tts_notify.mp3"
CMD_exit:
- "退出"
@@ -127,6 +135,13 @@ plugins:
- 卧室,台灯,switch.iot_cn_831898993_socn1_on_p_2_1
base_url: http://homeassistant.local:8123
api_key: 你的home assistant api访问令牌
+ play_music:
+ music_dir: "./music" # 音乐文件存放路径,将从该目录及子目录下搜索音乐文件
+ music_ext: # 音乐文件类型,p3格式效率最高
+ - ".mp3"
+ - ".wav"
+ - ".p3"
+ refresh_time: 300 # 刷新音乐列表的时间间隔,单位为秒
Memory:
@@ -507,3 +522,16 @@ module_test:
- "你好,请介绍一下你自己"
- "What's the weather like today?"
- "请用100字概括量子计算的基本原理和应用前景"
+
+# 唤醒词,用于识别唤醒词还是讲话内容
+wakeup_words:
+ - "你好小智"
+ - "你好小志"
+ - "小爱同学"
+ - "你好小鑫"
+ - "你好小新"
+ - "小美同学"
+ - "小龙小龙"
+ - "喵喵同学"
+ - "小滨小滨"
+ - "小冰小冰"
\ No newline at end of file
diff --git a/main/xiaozhi-server/config/assets/tts_notify.mp3 b/main/xiaozhi-server/config/assets/tts_notify.mp3
new file mode 100644
index 000000000..ff071501d
Binary files /dev/null and b/main/xiaozhi-server/config/assets/tts_notify.mp3 differ
diff --git a/main/xiaozhi-server/config/assets/wakeup_words.wav b/main/xiaozhi-server/config/assets/wakeup_words.wav
new file mode 100644
index 000000000..e5422555c
Binary files /dev/null and b/main/xiaozhi-server/config/assets/wakeup_words.wav differ
diff --git a/main/xiaozhi-server/core/connection.py b/main/xiaozhi-server/core/connection.py
index 0483f48c2..4d33f5bc2 100644
--- a/main/xiaozhi-server/core/connection.py
+++ b/main/xiaozhi-server/core/connection.py
@@ -8,7 +8,7 @@ import traceback
import websockets
from typing import Dict, Any
-import plugins_func.loadplugins
+from plugins_func.loadplugins import auto_import_modules
from config.logger import setup_logging
from core.utils.dialogue import Message, Dialogue
from core.handle.textHandle import handleTextMessage
@@ -23,6 +23,8 @@ from core.utils.auth_code_gen import AuthCodeGenerator
TAG = __name__
+auto_import_modules('plugins_func.functions')
+
class TTSException(RuntimeError):
pass
@@ -107,11 +109,15 @@ class ConnectionHandler:
# 进行认证
await self.auth.authenticate(self.headers)
-
device_id = self.headers.get("device-id", None)
- self.memory.init_memory(device_id, self.llm)
- self.intent.set_llm(self.llm)
+ # 认证通过,继续处理
+ self.websocket = ws
+ self.session_id = str(uuid.uuid4())
+
+ self.welcome_msg = copy.deepcopy(self.config["xiaozhi"])
+ self.welcome_msg["session_id"] = self.session_id
+ await self.websocket.send(json.dumps(self.welcome_msg))
# Load private configuration if device_id is provided
bUsePrivateConfig = self.config.get("use_private_config", False)
self.logger.bind(tag=TAG).info(f"bUsePrivateConfig: {bUsePrivateConfig}, device_id: {device_id}")
@@ -139,14 +145,6 @@ class ConnectionHandler:
self.private_config = None
raise
- # 认证通过,继续处理
- self.websocket = ws
- self.session_id = str(uuid.uuid4())
-
- self.welcome_msg = copy.deepcopy(self.config["xiaozhi"])
- self.welcome_msg["session_id"] = self.session_id
- await self.websocket.send(json.dumps(self.welcome_msg))
-
# 异步初始化
await self.loop.run_in_executor(None, self._initialize_components)
@@ -187,16 +185,26 @@ class ConnectionHandler:
await handleAudioMessage(self, message)
def _initialize_components(self):
+ """加载插件"""
+ self.func_handler = FunctionHandler(self)
+
+ """加载提示词"""
self.prompt = self.config["prompt"]
if self.private_config:
self.prompt = self.private_config.private_config.get("prompt", self.prompt)
-
- self.client_ip_info = get_ip_info(self.client_ip)
- self.logger.bind(tag=TAG).info(f"Client ip info: {self.client_ip_info}")
- self.prompt = self.prompt + f"\n我在:{self.client_ip_info}"
self.dialogue.put(Message(role="system", content=self.prompt))
- self.func_handler = FunctionHandler(self)
+ """加载记忆"""
+ device_id = self.headers.get("device-id", None)
+ self.memory.init_memory(device_id, self.llm)
+ self.intent.set_llm(self.llm)
+
+ """加载位置信息"""
+ self.client_ip_info = get_ip_info(self.client_ip)
+ if self.client_ip_info is not None and "city" in self.client_ip_info:
+ self.logger.bind(tag=TAG).info(f"Client ip info: {self.client_ip_info}")
+ self.prompt = self.prompt + f"\nuser location:{self.client_ip_info}"
+ self.dialogue.update_system_message(self.prompt)
def change_system_prompt(self, prompt):
self.prompt = prompt
diff --git a/main/xiaozhi-server/core/handle/helloHandle.py b/main/xiaozhi-server/core/handle/helloHandle.py
index bafcf09dc..cc9688624 100644
--- a/main/xiaozhi-server/core/handle/helloHandle.py
+++ b/main/xiaozhi-server/core/handle/helloHandle.py
@@ -1,8 +1,72 @@
import json
from config.logger import setup_logging
+from core.handle.sendAudioHandle import send_stt_message
+from core.utils.util import remove_punctuation_and_length
+import shutil
+import asyncio
+import os
+import random
+import time
logger = setup_logging()
+WAKEUP_CONFIG = {"dir": "config/assets/", "file_name": "wakeup_words", "create_time": time.time(), "refresh_time": 10,
+ "words": ["很高兴见到你", "你好啊", "我们又见面了", "最近可好?", "很高兴再次和你谈话", "在干嘛"]}
+
async def handleHelloMessage(conn):
await conn.websocket.send(json.dumps(conn.welcome_msg))
+
+
+async def checkWakeupWords(conn, text):
+ enable_wakeup_words_response_cache = conn.config["enable_wakeup_words_response_cache"]
+ """是否开启唤醒词加速"""
+ if not enable_wakeup_words_response_cache:
+ return False
+ """检查是否是唤醒词"""
+ _, text = remove_punctuation_and_length(text)
+ if text in conn.config.get("wakeup_words"):
+ await send_stt_message(conn, text)
+ conn.tts_first_text_index = 0
+ conn.tts_last_text_index = 0
+ conn.llm_finish_task = True
+
+ file = getWakeupWordFile(WAKEUP_CONFIG["file_name"])
+ if file is None:
+ asyncio.create_task(wakeupWordsResponse(conn))
+ return False
+ opus_packets, duration = conn.tts.audio_to_opus_data(file)
+ conn.audio_play_queue.put((opus_packets, text, 0))
+ if time.time() - WAKEUP_CONFIG["create_time"] > WAKEUP_CONFIG["refresh_time"]:
+ asyncio.create_task(wakeupWordsResponse(conn))
+ return True
+ return False
+
+
+def getWakeupWordFile(file_name):
+ for file in os.listdir(WAKEUP_CONFIG["dir"]):
+ if "my_"+file_name in file:
+ return f"config/assets/{file}"
+
+ """查找config/assets/目录下名称为wakeup_words的文件"""
+ for file in os.listdir(WAKEUP_CONFIG["dir"]):
+ if file_name in file:
+ return f"config/assets/{file}"
+ return None
+
+
+async def wakeupWordsResponse(conn):
+ """唤醒词响应"""
+ wakeup_word = random.choice(WAKEUP_CONFIG["words"])
+ result = conn.llm.response_no_stream(conn.config["prompt"], wakeup_word)
+ tts_file = await asyncio.to_thread(conn.tts.to_tts, result)
+ if tts_file is not None and os.path.exists(tts_file):
+ file_type = os.path.splitext(tts_file)[1]
+ if file_type:
+ file_type = file_type.lstrip('.')
+ old_file = getWakeupWordFile("my_" +WAKEUP_CONFIG["file_name"])
+ if old_file is not None:
+ os.remove(old_file)
+ """将文件挪到"wakeup_words.mp3"""
+ shutil.move(tts_file, WAKEUP_CONFIG["dir"] + "my_" +WAKEUP_CONFIG["file_name"] + "." + file_type)
+ WAKEUP_CONFIG["create_time"] = time.time()
diff --git a/main/xiaozhi-server/core/handle/intentHandler.py b/main/xiaozhi-server/core/handle/intentHandler.py
index f931574eb..7227a8744 100644
--- a/main/xiaozhi-server/core/handle/intentHandler.py
+++ b/main/xiaozhi-server/core/handle/intentHandler.py
@@ -2,6 +2,7 @@ from config.logger import setup_logging
import json
import uuid
from core.handle.sendAudioHandle import send_stt_message
+from core.handle.helloHandle import checkWakeupWords
from core.utils.util import remove_punctuation_and_length
TAG = __name__
@@ -12,6 +13,10 @@ async def handle_user_intent(conn, text):
# 检查是否有明确的退出命令
if await check_direct_exit(conn, text):
return True
+ # 检查是否是唤醒词
+ if await checkWakeupWords(conn, text):
+ return True
+
if conn.use_function_call_mode:
# 使用支持function calling的聊天方法,不再进行意图分析
return False
@@ -35,6 +40,7 @@ async def check_direct_exit(conn, text):
return False
+
async def analyze_intent_with_llm(conn, text):
"""使用LLM分析用户意图"""
if not hasattr(conn, 'intent') or not conn.intent:
diff --git a/main/xiaozhi-server/core/handle/sendAudioHandle.py b/main/xiaozhi-server/core/handle/sendAudioHandle.py
index 8999bf086..9a289d758 100644
--- a/main/xiaozhi-server/core/handle/sendAudioHandle.py
+++ b/main/xiaozhi-server/core/handle/sendAudioHandle.py
@@ -7,12 +7,26 @@ from core.utils.util import remove_punctuation_and_length, get_string_no_punctua
TAG = __name__
logger = setup_logging()
+
async def sendAudioMessage(conn, audios, text, text_index=0):
# 发送句子开始消息
if text_index == conn.tts_first_text_index:
logger.bind(tag=TAG).info(f"发送第一段语音: {text}")
await send_tts_message(conn, "sentence_start", text)
+ # 播放音频
+ await sendAudio(conn, audios)
+
+ await send_tts_message(conn, "sentence_end", text)
+
+ # 发送结束消息(如果是最后一个文本)
+ if conn.llm_finish_task and text_index == conn.tts_last_text_index:
+ await send_tts_message(conn, 'stop', None)
+ if conn.close_after_chat:
+ await conn.close()
+
+# 播放音频
+async def sendAudio(conn, audios):
# 流控参数优化
original_frame_duration = 60 # 原始帧时长(毫秒)
adjusted_frame_duration = int(original_frame_duration * 0.8) # 缩短20%
@@ -42,13 +56,6 @@ async def sendAudioMessage(conn, audios, text, text_index=0):
if compensation > 0:
await asyncio.sleep(compensation)
- await send_tts_message(conn, "sentence_end", text)
-
- # 发送结束消息(如果是最后一个文本)
- if conn.llm_finish_task and text_index == conn.tts_last_text_index:
- await send_tts_message(conn, 'stop', None)
- if conn.close_after_chat:
- await conn.close()
async def send_tts_message(conn, state, text=None):
"""发送 TTS 状态消息"""
@@ -60,10 +67,20 @@ async def send_tts_message(conn, state, text=None):
if text is not None:
message["text"] = text
- await conn.websocket.send(json.dumps(message))
+ # TTS播放结束
if state == "stop":
+ # 播放提示音
+ tts_notify = conn.config.get("enable_stop_tts_notify", False)
+ if tts_notify:
+ stop_tts_notify_voice = conn.config.get("stop_tts_notify_voice", "config/assets/tts_notify.mp3")
+ audios, duration = conn.tts.audio_to_opus_data(stop_tts_notify_voice)
+ await sendAudio(conn, audios)
+ # 清除服务端讲话状态
conn.clearSpeakStatus()
+ # 发送消息到客户端
+ await conn.websocket.send(json.dumps(message))
+
async def send_stt_message(conn, text):
"""发送 STT 状态消息"""
diff --git a/main/xiaozhi-server/core/handle/textHandle.py b/main/xiaozhi-server/core/handle/textHandle.py
index c63b9a334..3f60592ac 100644
--- a/main/xiaozhi-server/core/handle/textHandle.py
+++ b/main/xiaozhi-server/core/handle/textHandle.py
@@ -2,7 +2,9 @@ from config.logger import setup_logging
import json
from core.handle.abortHandle import handleAbortMessage
from core.handle.helloHandle import handleHelloMessage
+from core.utils.util import remove_punctuation_and_length
from core.handle.receiveAudioHandle import startToChat, handleAudioMessage
+from core.handle.sendAudioHandle import send_stt_message, send_tts_message
from core.handle.iotHandle import handleIotDescriptors, handleIotStatus
TAG = __name__
@@ -38,7 +40,21 @@ async def handleTextMessage(conn, message):
conn.client_have_voice = False
conn.asr_audio.clear()
if "text" in msg_json:
- await startToChat(conn, msg_json["text"])
+ text = msg_json["text"]
+ _, text = remove_punctuation_and_length(text)
+
+ # 识别是否是唤醒词
+ is_wakeup_words = text in conn.config.get("wakeup_words")
+ # 是否开启唤醒词回复
+ enable_greeting = conn.config.get("enable_greeting", True)
+
+ if is_wakeup_words and not enable_greeting:
+ # 如果是唤醒词,且关闭了唤醒词回复,就不用回答
+ await send_stt_message(conn, text)
+ await send_tts_message(conn, "stop", None)
+ else:
+ # 否则需要LLM对文字内容进行答复
+ await startToChat(conn, text)
elif msg_json["type"] == "iot":
if "descriptors" in msg_json:
await handleIotDescriptors(conn, msg_json["descriptors"])
diff --git a/main/xiaozhi-server/core/providers/tts/base.py b/main/xiaozhi-server/core/providers/tts/base.py
index 3146dc063..e39ca65c7 100644
--- a/main/xiaozhi-server/core/providers/tts/base.py
+++ b/main/xiaozhi-server/core/providers/tts/base.py
@@ -36,7 +36,7 @@ class TTSProviderBase(ABC):
return tmp_file
except Exception as e:
- logger.bind(tag=TAG).info(f"Failed to generate TTS file: {e}")
+ logger.bind(tag=TAG).error(f"Failed to generate TTS file: {e}")
return None
@abstractmethod
diff --git a/main/xiaozhi-server/core/utils/util.py b/main/xiaozhi-server/core/utils/util.py
index 63cb5b9c9..51841baf4 100644
--- a/main/xiaozhi-server/core/utils/util.py
+++ b/main/xiaozhi-server/core/utils/util.py
@@ -73,9 +73,7 @@ def get_ip_info(ip_addr):
resp = requests.get(url).json()
ip_info = {
- "city": resp.get("cityName"),
- "region": resp.get("regionName"),
- "country": resp.get("countryName")
+ "city": resp.get("cityName")
}
return ip_info
except Exception as e:
diff --git a/main/xiaozhi-server/plugins_func/functions/play_music.py b/main/xiaozhi-server/plugins_func/functions/play_music.py
index 75f3834dc..20148b5f5 100644
--- a/main/xiaozhi-server/plugins_func/functions/play_music.py
+++ b/main/xiaozhi-server/plugins_func/functions/play_music.py
@@ -21,13 +21,13 @@ play_music_function_desc = {
"type": "function",
"function": {
"name": "play_music",
- "description": "唱歌、听歌、播放音乐方法。比如用户说播放音乐,参数为:random,比如用户说播放两只老虎,参数为:两只老虎",
+ "description": "唱歌、听歌、播放音乐的方法。",
"parameters": {
"type": "object",
"properties": {
"song_name": {
"type": "string",
- "description": "歌曲名称,如果没有指定具体歌名则为'random'"
+ "description": "歌曲名称,如果用户没有指定具体歌名则为'random', 明确指定的时返回音乐的名字 示例: ```用户:播放两只老虎\n参数:两只老虎``` ```用户:播放音乐 \n参数:random ```"
}
},
"required": ["song_name"]
@@ -112,8 +112,8 @@ def get_music_files(music_dir, music_ext):
def initialize_music_handler(conn):
global MUSIC_CACHE
if MUSIC_CACHE == {}:
- if "music" in conn.config:
- MUSIC_CACHE["music_config"] = conn.config["music"]
+ if "play_music" in conn.config["plugins"]:
+ MUSIC_CACHE["music_config"] = conn.config["plugins"]["play_music"]
MUSIC_CACHE["music_dir"] = os.path.abspath(
MUSIC_CACHE["music_config"].get("music_dir", "./music") # 默认路径修改
)
diff --git a/main/xiaozhi-server/plugins_func/loadplugins.py b/main/xiaozhi-server/plugins_func/loadplugins.py
index d826fac8b..9b20355e5 100644
--- a/main/xiaozhi-server/plugins_func/loadplugins.py
+++ b/main/xiaozhi-server/plugins_func/loadplugins.py
@@ -22,6 +22,4 @@ def auto_import_modules(package_name):
# 导入模块
full_module_name = f"{package_name}.{module_name}"
importlib.import_module(full_module_name)
- #logger.bind(tag=TAG).info(f"模块 '{full_module_name}' 已加载")
-
-auto_import_modules('plugins_func.functions')
\ No newline at end of file
+ #logger.bind(tag=TAG).info(f"模块 '{full_module_name}' 已加载")
\ No newline at end of file