xiaozhi-sdk 0.0.3__py3-none-any.whl → 0.0.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of xiaozhi-sdk might be problematic. Click here for more details.
- xiaozhi_sdk/__init__.py +10 -3
- xiaozhi_sdk/__main__.py +11 -0
- xiaozhi_sdk/config.py +1 -1
- xiaozhi_sdk/iot.py +4 -1
- {xiaozhi_sdk-0.0.3.dist-info → xiaozhi_sdk-0.0.5.dist-info}/METADATA +6 -15
- {xiaozhi_sdk-0.0.3.dist-info → xiaozhi_sdk-0.0.5.dist-info}/RECORD +9 -9
- {xiaozhi_sdk-0.0.3.dist-info → xiaozhi_sdk-0.0.5.dist-info}/WHEEL +0 -0
- {xiaozhi_sdk-0.0.3.dist-info → xiaozhi_sdk-0.0.5.dist-info}/licenses/LICENSE +0 -0
- {xiaozhi_sdk-0.0.3.dist-info → xiaozhi_sdk-0.0.5.dist-info}/top_level.txt +0 -0
xiaozhi_sdk/__init__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
__version__ = "0.0.
|
|
1
|
+
__version__ = "0.0.5"
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
4
|
import json
|
|
@@ -147,6 +147,7 @@ class XiaoZhiWebsocket(McpTool):
|
|
|
147
147
|
await self.message_handler_callback(
|
|
148
148
|
{"type": "websocket", "state": "close", "source": "sdk.message_handler"}
|
|
149
149
|
)
|
|
150
|
+
logger.info("[websocket] close")
|
|
150
151
|
|
|
151
152
|
async def set_mcp_tool_callback(self, tool_func: Dict[str, Callable[..., Any]]) -> None:
|
|
152
153
|
"""设置MCP工具回调函数"""
|
|
@@ -165,11 +166,15 @@ class XiaoZhiWebsocket(McpTool):
|
|
|
165
166
|
|
|
166
167
|
self.ota = OtaDevice(self.mac_addr, self.client_id, self.ota_url, serial_number)
|
|
167
168
|
ota_info = await self.ota.activate_device()
|
|
168
|
-
ws_url = ota_info
|
|
169
|
+
ws_url = ota_info.get("websocket", {}).get("url")
|
|
169
170
|
self.url = self.url or ws_url
|
|
170
171
|
|
|
172
|
+
if not self.url:
|
|
173
|
+
logger.warning("[websocket] 未找到websocket链接地址")
|
|
174
|
+
return
|
|
175
|
+
|
|
171
176
|
if "tenclass.net" not in self.url and "xiaozhi.me" not in self.url:
|
|
172
|
-
logger.warning("[websocket]
|
|
177
|
+
logger.warning("[websocket] 检测到非官方服务器,当前链接地址: %s", self.url)
|
|
173
178
|
|
|
174
179
|
headers = {
|
|
175
180
|
"Authorization": "Bearer {}".format(ota_info["websocket"]["token"]),
|
|
@@ -202,6 +207,8 @@ class XiaoZhiWebsocket(McpTool):
|
|
|
202
207
|
if self.message_handler_callback:
|
|
203
208
|
await self.message_handler_callback({"type": "websocket", "state": "close", "source": "sdk.send_audio"})
|
|
204
209
|
self.websocket = None
|
|
210
|
+
logger.info("[websocket] close")
|
|
211
|
+
|
|
205
212
|
await asyncio.sleep(0.5)
|
|
206
213
|
else:
|
|
207
214
|
await asyncio.sleep(0.1)
|
xiaozhi_sdk/__main__.py
CHANGED
|
@@ -20,11 +20,15 @@ logger = logging.getLogger("xiaozhi_sdk")
|
|
|
20
20
|
# 全局状态
|
|
21
21
|
input_audio_buffer: deque[bytes] = deque()
|
|
22
22
|
is_playing_audio = False
|
|
23
|
+
is_end = False
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
async def handle_message(message):
|
|
26
27
|
"""处理接收到的消息"""
|
|
28
|
+
global is_end
|
|
27
29
|
logger.info("message received: %s", message)
|
|
30
|
+
if message["type"] == "websocket" and message["state"] == "close":
|
|
31
|
+
is_end = True
|
|
28
32
|
|
|
29
33
|
|
|
30
34
|
async def play_assistant_audio(audio_queue: deque[bytes]):
|
|
@@ -36,6 +40,9 @@ async def play_assistant_audio(audio_queue: deque[bytes]):
|
|
|
36
40
|
last_audio_time = None
|
|
37
41
|
|
|
38
42
|
while True:
|
|
43
|
+
if is_end:
|
|
44
|
+
return
|
|
45
|
+
|
|
39
46
|
if not audio_queue:
|
|
40
47
|
await asyncio.sleep(0.01)
|
|
41
48
|
if last_audio_time and time.time() - last_audio_time > 1:
|
|
@@ -77,6 +84,10 @@ class XiaoZhiClient:
|
|
|
77
84
|
async def process_audio_input(self):
|
|
78
85
|
"""处理音频输入"""
|
|
79
86
|
while True:
|
|
87
|
+
|
|
88
|
+
if is_end:
|
|
89
|
+
return
|
|
90
|
+
|
|
80
91
|
if not input_audio_buffer:
|
|
81
92
|
await asyncio.sleep(0.02)
|
|
82
93
|
continue
|
xiaozhi_sdk/config.py
CHANGED
xiaozhi_sdk/iot.py
CHANGED
|
@@ -29,6 +29,8 @@ class OtaDevice:
|
|
|
29
29
|
|
|
30
30
|
def __init__(self, mac_addr: str, client_id: str, ota_url: Optional[str] = None, serial_number: str = "") -> None:
|
|
31
31
|
self.ota_url = ota_url or OTA_URL
|
|
32
|
+
self.ota_url = self.ota_url.rstrip("/")
|
|
33
|
+
|
|
32
34
|
self.mac_addr = mac_addr
|
|
33
35
|
self.client_id = client_id
|
|
34
36
|
self.serial_number = serial_number
|
|
@@ -54,12 +56,13 @@ class OtaDevice:
|
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
async with aiohttp.ClientSession() as session:
|
|
57
|
-
async with session.post(self.ota_url, headers=headers, data=json.dumps(payload)) as response:
|
|
59
|
+
async with session.post(self.ota_url + "/", headers=headers, data=json.dumps(payload)) as response:
|
|
58
60
|
response.raise_for_status()
|
|
59
61
|
return await response.json()
|
|
60
62
|
|
|
61
63
|
async def check_activate(self, challenge: str, license_key: str = "") -> bool:
|
|
62
64
|
url = f"{self.ota_url}/activate"
|
|
65
|
+
|
|
63
66
|
headers = self._get_base_headers()
|
|
64
67
|
|
|
65
68
|
hmac_instance = hmac.new(license_key.encode(), challenge.encode(), hashlib.sha256)
|
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xiaozhi-sdk
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.5
|
|
4
4
|
Summary: 一个用于连接和控制小智智能设备的Python SDK,支持实时音频通信、MCP工具集成和设备管理功能。
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Author-email: dairoot <623815825@qq.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/dairoot/xiaozhi-sdk
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.8
|
|
11
|
+
Requires-Python: >=3.8.1
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
Requires-Dist: numpy
|
|
15
|
-
Requires-Dist: websockets
|
|
15
|
+
Requires-Dist: websockets>=15.0.1
|
|
16
16
|
Requires-Dist: aiohttp
|
|
17
17
|
Requires-Dist: av
|
|
18
18
|
Requires-Dist: opuslib
|
|
19
19
|
Requires-Dist: requests
|
|
20
20
|
Requires-Dist: sounddevice
|
|
21
21
|
Requires-Dist: python-socks
|
|
22
|
-
Dynamic: author
|
|
23
|
-
Dynamic: author-email
|
|
24
|
-
Dynamic: classifier
|
|
25
|
-
Dynamic: description
|
|
26
|
-
Dynamic: description-content-type
|
|
27
|
-
Dynamic: home-page
|
|
28
22
|
Dynamic: license-file
|
|
29
|
-
Dynamic: requires-dist
|
|
30
|
-
Dynamic: requires-python
|
|
31
|
-
Dynamic: summary
|
|
32
23
|
|
|
33
24
|
# 小智SDK (XiaoZhi SDK)
|
|
34
25
|
|
|
@@ -7,16 +7,16 @@ file/opus/linux-x64-libopus.so,sha256=FmXJqkxLpDzNFOHYkmOzmsp1hP0eIS5b6x_XfOs-IQ
|
|
|
7
7
|
file/opus/macos-arm64-libopus.dylib,sha256=H7wXwkrGwb-hesMMZGFxWb0Ri1Y4m5GWiKsd8CfOhE8,357584
|
|
8
8
|
file/opus/macos-x64-libopus.dylib,sha256=MqyL_OjwSACF4Xs_-KrGbcScy4IEprr5Rlkk3ddZye8,550856
|
|
9
9
|
file/opus/windows-x86_64-opus.dll,sha256=kLfhioMvbJhOgNMAldpWk3DCZqC5Xd70LRbHnACvAnw,463360
|
|
10
|
-
xiaozhi_sdk/__init__.py,sha256=
|
|
11
|
-
xiaozhi_sdk/__main__.py,sha256=
|
|
12
|
-
xiaozhi_sdk/config.py,sha256=
|
|
10
|
+
xiaozhi_sdk/__init__.py,sha256=psrVT0BBTsCj1wqJ7ZmKRhGfRj2y7NPGRwn_aiKLw-E,8146
|
|
11
|
+
xiaozhi_sdk/__main__.py,sha256=_Xh6v2oMYXYHsrAkw4PYMJpvi-0r3ujLNRLMxPNarTQ,3807
|
|
12
|
+
xiaozhi_sdk/config.py,sha256=h4mpMeBf2vT9qYAqCCbGVGmMemkgk98pcXP2Rh4TEFc,89
|
|
13
13
|
xiaozhi_sdk/data.py,sha256=8z8erOjBZFvPSBJlPoyTzRYZ3BuMvnPpAFQCbSxs-48,2522
|
|
14
|
-
xiaozhi_sdk/iot.py,sha256=
|
|
14
|
+
xiaozhi_sdk/iot.py,sha256=w_DvEDcQmaP1JJAYElRDCJP5h0GhaoZ2lg5JBnmZBnU,2392
|
|
15
15
|
xiaozhi_sdk/mcp.py,sha256=JA-z6EjGqitEfwMlvxk6XUSjbmfAdyWJVZPjtjqo6Oo,3823
|
|
16
16
|
xiaozhi_sdk/opus.py,sha256=4O-kz-PcUVmpa27Vju6jv-sbwywuAXFvVL23R1-vv5o,2104
|
|
17
17
|
xiaozhi_sdk/utils.py,sha256=5qHAiI5Nrzeka3TofMPhAVmMovEJJa6QSrKcDM0OF4g,1703
|
|
18
|
-
xiaozhi_sdk-0.0.
|
|
19
|
-
xiaozhi_sdk-0.0.
|
|
20
|
-
xiaozhi_sdk-0.0.
|
|
21
|
-
xiaozhi_sdk-0.0.
|
|
22
|
-
xiaozhi_sdk-0.0.
|
|
18
|
+
xiaozhi_sdk-0.0.5.dist-info/licenses/LICENSE,sha256=Vwgps1iODKl43cAtME_0dawTjAzNW-O2BWiN5BHggww,1085
|
|
19
|
+
xiaozhi_sdk-0.0.5.dist-info/METADATA,sha256=M0BcMb2zM9SjHdJHfivECeUtOFKNuPDiBoe3BM8dkW0,2352
|
|
20
|
+
xiaozhi_sdk-0.0.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
21
|
+
xiaozhi_sdk-0.0.5.dist-info/top_level.txt,sha256=nBpue4hU5Ykm5CtYPsAdxSa_yqbtZsIT_gF_EkBaJPM,12
|
|
22
|
+
xiaozhi_sdk-0.0.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|