docs: 更新绑定设备后需要重启生效的说明

This commit is contained in:
Del Wang
2025-05-11 16:04:27 +08:00
parent c8e7861bdb
commit 6bdd1b9683
3 changed files with 25 additions and 45 deletions
+2
View File
@@ -53,5 +53,7 @@ XIAOZHI_CONFIG = {
请按照提示注册你的小智 AI 账号,然后创建 Agent 绑定设备即可开始体验。
注意:绑定设备成功后,需要重新运行本应用才会生效。
> [!NOTE]
> 本项目只是一个简单的演示程序,抛砖引玉。如果你想要更多的功能,比如唤醒词识别、语音转文字、连续对话等,可以参考开源的 [xiaozhi-esp32-server](https://github.com/xinnan-tech/xiaozhi-esp32-server) 项目,借助 Python 丰富的 AI 生态自行实现。
@@ -1,13 +1,12 @@
import asyncio
import json
import logging
import websockets
import websockets
from xiaozhi.services.protocols.protocol import Protocol
from xiaozhi.utils.config_manager import ConfigManager
logger = logging.getLogger("WebsocketProtocol")
@@ -41,17 +40,10 @@ class WebsocketProtocol(Protocol):
"Client-Id": self.CLIENT_ID,
}
# 建立WebSocket连接 (兼容不同Python版本的写法)
try:
# 新的写法 (在Python 3.11+版本中)
self.websocket = await websockets.connect(
uri=self.WEBSOCKET_URL, additional_headers=headers
)
except TypeError:
# 旧的写法 (在较早的Python版本中)
self.websocket = await websockets.connect(
self.WEBSOCKET_URL, extra_headers=headers
)
# 建立WebSocket连接
self.websocket = await websockets.connect(
uri=self.WEBSOCKET_URL, additional_headers=headers
)
# 启动消息处理循环
asyncio.create_task(self._message_handler())
+18 -32
View File
@@ -1,6 +1,7 @@
import asyncio
import json
import logging
import re
import threading
import time
@@ -319,11 +320,24 @@ class XiaoZhi:
text = data.get("text", "")
if text:
logger.info(f"<< {text}")
self.schedule(lambda: self.set_chat_message("assistant", text))
# 检查是否包含验证码信息
if "请登录到控制面板添加设备,输入验证码" in text:
self.schedule(lambda: self._handle_verification_code(text))
need_verification_code = re.search(r"验证码.*\d+", text)
verification_tips = (
"\n🔥 注意:绑定成功后,需要重新运行本应用才会生效"
if need_verification_code
else ""
)
if need_verification_code:
logger.info(verification_tips)
self.schedule(
lambda: self.set_chat_message(
"assistant",
text + verification_tips,
)
)
def _handle_tts_start(self):
"""处理TTS开始事件"""
@@ -488,7 +502,6 @@ class XiaoZhi:
if state == DeviceState.IDLE:
self.display.update_status("待命")
self.display.update_emotion("😶")
# 停止输出流但不关闭它
if (
self.audio_codec.output_stream
and self.audio_codec.output_stream.is_active()
@@ -769,33 +782,6 @@ class XiaoZhi:
logger.info("应用程序已关闭")
def _handle_verification_code(self, text):
"""处理验证码信息"""
try:
# 提取验证码
import re
verification_code = re.search(r"验证码:(\d+)", text)
if verification_code:
code = verification_code.group(1)
# 尝试打开浏览器
try:
import webbrowser
if webbrowser.open("https://xiaozhi.me/login"):
logger.info("已打开登录页面")
else:
logger.warning("无法打开浏览器")
except Exception as e:
logger.warning(f"打开浏览器时出错: {e}")
# 无论如何都显示验证码
self.alert("验证码", f"您的验证码是: {code}")
except Exception as e:
logger.error(f"处理验证码时出错: {e}")
def _on_mode_changed(self, auto_mode):
"""处理对话模式变更"""
# 只有在IDLE状态下才允许切换模式