From 220af8068e38d5919123f1f24bf360c57b2db30c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=81=A5=E8=B1=AA?= Date: Fri, 21 Mar 2025 14:59:01 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=9F=B3=E4=B9=90?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E6=96=AD=E5=BC=80bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复音乐播放速度太快导致设备内存溢出断开连接的问题 --- .../core/handle/sendAudioHandle.py | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/main/xiaozhi-server/core/handle/sendAudioHandle.py b/main/xiaozhi-server/core/handle/sendAudioHandle.py index 8999bf086..a6fed97be 100644 --- a/main/xiaozhi-server/core/handle/sendAudioHandle.py +++ b/main/xiaozhi-server/core/handle/sendAudioHandle.py @@ -14,33 +14,37 @@ async def sendAudioMessage(conn, audios, text, text_index=0): await send_tts_message(conn, "sentence_start", text) # 流控参数优化 - original_frame_duration = 60 # 原始帧时长(毫秒) - adjusted_frame_duration = int(original_frame_duration * 0.8) # 缩短20% - total_frames = len(audios) # 获取总帧数 - compensation = total_frames * (original_frame_duration - adjusted_frame_duration) / 1000 # 补偿时间(秒) - + frame_duration = 62 # 帧时长(毫秒),增加余量 start_time = time.perf_counter() play_position = 0 # 已播放时长(毫秒) - for opus_packet in audios: + # 预发送前 n 帧 + pre_buffer = min(5, len(audios)) + for i in range(pre_buffer): + await conn.websocket.send(audios[i]) + conn.logger.bind(tag=TAG).debug(f"预缓冲帧 {i}") + + # 正常播放剩余帧 + for opus_packet in audios[pre_buffer:]: if conn.client_abort: return - - # 计算带加速因子的预期时间 + + # 计算预期发送时间 expected_time = start_time + (play_position / 1000) current_time = time.perf_counter() - - # 流控等待(使用加速后的帧时长) delay = expected_time - current_time if delay > 0: await asyncio.sleep(delay) - await conn.websocket.send(opus_packet) - play_position += adjusted_frame_duration # 使用调整后的帧时长 + send_start = time.perf_counter() - # 补偿因加速损失的时长 - if compensation > 0: - await asyncio.sleep(compensation) + await conn.websocket.send(opus_packet) + + send_duration = (time.perf_counter() - send_start) * 1000 + logger.bind(tag=TAG).debug(f"发送帧,位置: {play_position}ms, 实际间隔: {(time.perf_counter() - current_time) * 1000:.2f}ms, 发送耗时: {send_duration:.2f}ms") + + # 动态调整下次延迟,补偿发送耗时 + play_position += frame_duration # 更新播放位置 await send_tts_message(conn, "sentence_end", text) From 5b1c20d625828e67fa29a5f408fad9118aa58912 Mon Sep 17 00:00:00 2001 From: Jad Date: Mon, 24 Mar 2025 02:09:01 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=A4=A9=E6=B0=94=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 7天预报包含每日天气 --- .../plugins_func/functions/get_weather.py | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/main/xiaozhi-server/plugins_func/functions/get_weather.py b/main/xiaozhi-server/plugins_func/functions/get_weather.py index 75c0c1a3c..8cdd6ea16 100644 --- a/main/xiaozhi-server/plugins_func/functions/get_weather.py +++ b/main/xiaozhi-server/plugins_func/functions/get_weather.py @@ -39,6 +39,23 @@ HEADERS = { ) } +# 天气代码 https://dev.qweather.com/docs/resource/icons/#weather-icons +WEATHER_CODE_MAP = { + "100": "晴", "101": "多云", "102": "少云", "103": "晴间多云", "104": "阴", + "150": "晴", "151": "多云", "152": "少云", "153": "晴间多云", + "300": "阵雨", "301": "强阵雨", "302": "雷阵雨", "303": "强雷阵雨", "304": "雷阵雨伴有冰雹", + "305": "小雨", "306": "中雨", "307": "大雨", "308": "极端降雨", "309": "毛毛雨/细雨", + "310": "暴雨", "311": "大暴雨", "312": "特大暴雨", "313": "冻雨", "314": "小到中雨", + "315": "中到大雨", "316": "大到暴雨", "317": "暴雨到大暴雨", "318": "大暴雨到特大暴雨", + "350": "阵雨", "351": "强阵雨", "399": "雨", + "400": "小雪", "401": "中雪", "402": "大雪", "403": "暴雪", "404": "雨夹雪", + "405": "雨雪天气", "406": "阵雨夹雪", "407": "阵雪", "408": "小到中雪", "409": "中到大雪", "410": "大到暴雪", + "456": "阵雨夹雪", "457": "阵雪", "499": "雪", + "500": "薄雾", "501": "雾", "502": "霾", "503": "扬沙", "504": "浮尘", + "507": "沙尘暴", "508": "强沙尘暴", + "509": "浓雾", "510": "强浓雾", "511": "中度霾", "512": "重度霾", "513": "严重霾", "514": "大雾", "515": "特强浓雾", + "900": "热", "901": "冷", "999": "未知" +} def fetch_city_info(location, api_key): url = f"https://geoapi.qweather.com/v2/city/lookup?key={api_key}&location={location}&lang=zh" @@ -67,9 +84,11 @@ def parse_weather_info(soup): temps_list = [] for row in soup.select(".city-forecast-tabs__row")[:7]: # 取前7天的数据 date = row.select_one(".date-bg .date").get_text(strip=True) + weather_code = row.select_one(".date-bg .icon")["src"].split("/")[-1].split(".")[0] + weather = WEATHER_CODE_MAP.get(weather_code, "未知") temps = [span.get_text(strip=True) for span in row.select(".tmp-cont .temp")] high_temp, low_temp = (temps[0], temps[-1]) if len(temps) >= 2 else (None, None) - temps_list.append((date, high_temp, low_temp)) + temps_list.append((date, weather, high_temp, low_temp)) return city_name, current_abstract, current_basic, temps_list @@ -91,13 +110,13 @@ def get_weather(conn, location: str = None, lang: str = "zh_CN"): city_name, current_abstract, current_basic, temps_list = parse_weather_info(soup) weather_report = f"根据下列数据,用{lang}回应用户的查询天气请求:\n{city_name}未来7天天气:\n" - for i, (date, high, low) in enumerate(temps_list): + for i, (date, weather, high, low) in enumerate(temps_list): if high and low: - weather_report += f"{date}: {low}到{high}\n" + weather_report += f"{date}: {low}到{high}, {weather}\n" weather_report += ( f"当前天气: {current_abstract}\n" f"当前天气参数: {current_basic}\n" - f"(确保只报告指定单日的气温范围,除非用户明确要求想要了解多日天气,如果未指定,默认报告今天的温度范围。" + f"(确保只报告指定单日的天气情况,除非未来会出现异常天气;或者用户明确要求想要了解多日天气,如果未指定,默认报告今天的天气。" "参数为0的值不需要报告给用户,每次都报告体感温度,根据语境选择合适的参数内容告知用户,并对参数给出相应评价)" ) From b59c097bcaaea84f62ad1e26c1001e076b0c26ea Mon Sep 17 00:00:00 2001 From: CGD <3030332422@qq.com> Date: Mon, 24 Mar 2025 09:16:48 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=99=BA=E8=83=BD=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/manager-web/src/apis/module/user.js | 15 +++++++++ .../manager-web/src/components/DeviceItem.vue | 7 +++- main/manager-web/src/components/HeaderBar.vue | 7 ++-- main/manager-web/src/views/home.vue | 33 ++++++++++++++++--- 4 files changed, 55 insertions(+), 7 deletions(-) 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/HeaderBar.vue b/main/manager-web/src/components/HeaderBar.vue index 53946ed65..a8dff30cb 100644 --- a/main/manager-web/src/components/HeaderBar.vue +++ b/main/manager-web/src/components/HeaderBar.vue @@ -25,7 +25,7 @@ - {{ userInfo.username || '加载中...' }} + {{ userInfo.username }} 个人中心 @@ -71,7 +71,10 @@ export default { // 获取用户信息 fetchUserInfo() { userApi.getUserInfo(({data}) => { - this.userInfo = data.data + this.userInfo = { + username: data.data.mobile, // 暂时先使用手机号作为用户名 + mobile: data.data.mobile + } }) }, 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(() => {}); } - } } From 49cb98a60654871f6a645d2867079501b851366d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=81=A5=E8=B1=AA?= Date: Mon, 24 Mar 2025 09:28:01 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=9F=B3=E4=B9=90?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E5=8D=A1=E9=A1=BF=E5=92=8C=E6=96=AD=E8=BF=9E?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/handle/sendAudioHandle.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/main/xiaozhi-server/core/handle/sendAudioHandle.py b/main/xiaozhi-server/core/handle/sendAudioHandle.py index ffb363986..c0a664eb6 100644 --- a/main/xiaozhi-server/core/handle/sendAudioHandle.py +++ b/main/xiaozhi-server/core/handle/sendAudioHandle.py @@ -28,15 +28,15 @@ async def sendAudioMessage(conn, audios, text, text_index=0): # 播放音频 async def sendAudio(conn, audios): # 流控参数优化 - frame_duration = 62 # 帧时长(毫秒),增加余量 + frame_duration = 60 # 帧时长(毫秒),匹配 Opus 编码 start_time = time.perf_counter() - play_position = 0 # 已播放时长(毫秒) + play_position = 0 - # 预发送前 n 帧 - pre_buffer = min(5, len(audios)) + # 预缓冲:发送前 3 帧 + pre_buffer = min(3, len(audios)) for i in range(pre_buffer): await conn.websocket.send(audios[i]) - conn.logger.bind(tag=TAG).debug(f"预缓冲帧 {i}") + conn.logger.bind(tag=TAG).debug(f"预缓冲帧 {i}, 时间: {(time.perf_counter() - start_time) * 1000:.2f}ms") # 正常播放剩余帧 for opus_packet in audios[pre_buffer:]: @@ -50,15 +50,11 @@ async def sendAudio(conn, audios): if delay > 0: await asyncio.sleep(delay) - send_start = time.perf_counter() - await conn.websocket.send(opus_packet) + conn.logger.bind(tag=TAG).debug(f"发送帧,位置: {play_position}ms, 实际间隔: {(time.perf_counter() - current_time) * 1000:.2f}ms") - send_duration = (time.perf_counter() - send_start) * 1000 - logger.bind(tag=TAG).debug(f"发送帧,位置: {play_position}ms, 实际间隔: {(time.perf_counter() - current_time) * 1000:.2f}ms, 发送耗时: {send_duration:.2f}ms") + play_position += frame_duration - # 动态调整下次延迟,补偿发送耗时 - play_position += frame_duration # 更新播放位置 async def send_tts_message(conn, state, text=None): From 02e33f68b4cbcbe9eb8a3ef7f52e89d92bac6e32 Mon Sep 17 00:00:00 2001 From: Jad Date: Mon, 24 Mar 2025 13:12:46 +0800 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=86=9C=E5=8E=86=E6=97=A5=E6=9C=9F=E5=92=8C=E9=BB=84?= =?UTF-8?q?=E5=8E=86=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins_func/functions/get_time.py | 32 +++++++++++++++++-- main/xiaozhi-server/requirements.txt | 1 + 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/main/xiaozhi-server/plugins_func/functions/get_time.py b/main/xiaozhi-server/plugins_func/functions/get_time.py index 9a9aebfec..c415e4a2d 100644 --- a/main/xiaozhi-server/plugins_func/functions/get_time.py +++ b/main/xiaozhi-server/plugins_func/functions/get_time.py @@ -1,11 +1,12 @@ from datetime import datetime +import cnlunar from plugins_func.register import register_function, ToolType, ActionResponse, Action get_time_function_desc = { "type": "function", "function": { "name": "get_time", - "description": "获取当前时间、日期、星期几", + "description": "获取当前日期、时间和农历、黄历等信息", 'parameters': {'type': 'object', 'properties': {}, 'required': []} } } @@ -14,12 +15,37 @@ get_time_function_desc = { @register_function('get_time', get_time_function_desc, ToolType.WAIT) def get_time(): """ - 获取当前时间、日期、星期几 + 获取当前日期、时间和农历、黄历等信息 """ now = datetime.now() current_time = now.strftime("%H:%M:%S") current_date = now.strftime("%Y-%m-%d") current_weekday = now.strftime("%A") - response_text = f"当前日期: {current_date},当前时间: {current_time},星期: {current_weekday}" + response_text = f"根据以下信息,回应用户的时间查询请求,默认仅回应公历信息;如果用户询问阴历或农历日期,则回应农历日期;如果用户要求提供更多信息,则回应黄历信息\n" + + lunar = cnlunar.Lunar(now, godType='8char') + response_text += ( + f"当前日期: {current_date},当前时间: {current_time},星期: {current_weekday}\n" + "农历信息:\n" + "%s年%s%s\n" % (lunar.lunarYearCn, lunar.lunarMonthCn[:-1], lunar.lunarDayCn) + + "干支: %s年 %s月 %s日\n" % (lunar.year8Char, lunar.month8Char, lunar.day8Char) + + "生肖: 属%s\n" % (lunar.chineseYearZodiac) + + "八字: %s\n" % (' '.join([lunar.year8Char, lunar.month8Char, lunar.day8Char, lunar.twohour8Char])) + + "今日节日: %s\n" % (",".join(filter(None, (lunar.get_legalHolidays(), lunar.get_otherHolidays(), lunar.get_otherLunarHolidays())))) + + "今日节气: %s\n" % (lunar.todaySolarTerms) + + "下一节气: %s %s年%s月%s日\n" % (lunar.nextSolarTerm, lunar.nextSolarTermYear, lunar.nextSolarTermDate[0], lunar.nextSolarTermDate[1]) + + "今年节气表: %s\n" % (', '.join([f"{term}({date[0]}月{date[1]}日)" for term, date in lunar.thisYearSolarTermsDic.items()])) + + "生肖冲煞: %s\n" % (lunar.chineseZodiacClash) + + "星座: %s\n" % (lunar.starZodiac) + + "纳音: %s\n" % lunar.get_nayin() + + "彭祖百忌: %s\n" % (lunar.get_pengTaboo(delimit=", ")) + + "值日: %s执位\n" % lunar.get_today12DayOfficer()[0] + + "值神: %s(%s)\n" % (lunar.get_today12DayOfficer()[1], lunar.get_today12DayOfficer()[2]) + + "廿八宿: %s\n" % lunar.get_the28Stars() + + "吉神方位: %s\n" % ' '.join(lunar.get_luckyGodsDirection()) + + "今日胎神: %s\n" % lunar.get_fetalGod() + + "宜: %s\n" % '、'.join(lunar.goodThing[:10]) + + "忌: %s\n" % '、'.join(lunar.badThing[:10]) + ) return ActionResponse(Action.REQLLM, response_text, None) \ No newline at end of file diff --git a/main/xiaozhi-server/requirements.txt b/main/xiaozhi-server/requirements.txt index 6afec6b5f..51433cb90 100755 --- a/main/xiaozhi-server/requirements.txt +++ b/main/xiaozhi-server/requirements.txt @@ -22,3 +22,4 @@ mem0ai==0.1.62 bs4==0.0.2 modelscope==1.23.2 sherpa_onnx==1.11.0 +cnlunar==0.2.0 \ No newline at end of file