xiaozhi-sdk 0.0.3__py3-none-any.whl → 0.0.4__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 +4 -1
- xiaozhi_sdk/__main__.py +11 -0
- xiaozhi_sdk/iot.py +3 -0
- {xiaozhi_sdk-0.0.3.dist-info → xiaozhi_sdk-0.0.4.dist-info}/METADATA +5 -14
- {xiaozhi_sdk-0.0.3.dist-info → xiaozhi_sdk-0.0.4.dist-info}/RECORD +8 -8
- {xiaozhi_sdk-0.0.3.dist-info → xiaozhi_sdk-0.0.4.dist-info}/WHEEL +0 -0
- {xiaozhi_sdk-0.0.3.dist-info → xiaozhi_sdk-0.0.4.dist-info}/licenses/LICENSE +0 -0
- {xiaozhi_sdk-0.0.3.dist-info → xiaozhi_sdk-0.0.4.dist-info}/top_level.txt +0 -0
xiaozhi_sdk/__init__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
__version__ = "0.0.
|
|
1
|
+
__version__ = "0.0.4"
|
|
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工具回调函数"""
|
|
@@ -202,6 +203,8 @@ class XiaoZhiWebsocket(McpTool):
|
|
|
202
203
|
if self.message_handler_callback:
|
|
203
204
|
await self.message_handler_callback({"type": "websocket", "state": "close", "source": "sdk.send_audio"})
|
|
204
205
|
self.websocket = None
|
|
206
|
+
logger.info("[websocket] close")
|
|
207
|
+
|
|
205
208
|
await asyncio.sleep(0.5)
|
|
206
209
|
else:
|
|
207
210
|
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/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
|
|
@@ -60,6 +62,7 @@ class OtaDevice:
|
|
|
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,14 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xiaozhi-sdk
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
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
|
|
@@ -19,16 +19,7 @@ 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=
|
|
10
|
+
xiaozhi_sdk/__init__.py,sha256=iNRkEIYK6f4kbbu3dz874LKOxtMitUa2GzHH2gRSD1w,8034
|
|
11
|
+
xiaozhi_sdk/__main__.py,sha256=_Xh6v2oMYXYHsrAkw4PYMJpvi-0r3ujLNRLMxPNarTQ,3807
|
|
12
12
|
xiaozhi_sdk/config.py,sha256=mpjWWklTI2bw4zY3ZWCYvqvpfZSoF5iM7ubAP9y_8cM,90
|
|
13
13
|
xiaozhi_sdk/data.py,sha256=8z8erOjBZFvPSBJlPoyTzRYZ3BuMvnPpAFQCbSxs-48,2522
|
|
14
|
-
xiaozhi_sdk/iot.py,sha256=
|
|
14
|
+
xiaozhi_sdk/iot.py,sha256=aIrHVZVVObu8VDC20JOc8yO4X7ORMW-R7RNxIEyl9ng,2386
|
|
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.4.dist-info/licenses/LICENSE,sha256=Vwgps1iODKl43cAtME_0dawTjAzNW-O2BWiN5BHggww,1085
|
|
19
|
+
xiaozhi_sdk-0.0.4.dist-info/METADATA,sha256=WdiQkFfDXnlRiFHZT3Z7lq9d4t94J1imAH6ai_OIuhs,2344
|
|
20
|
+
xiaozhi_sdk-0.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
21
|
+
xiaozhi_sdk-0.0.4.dist-info/top_level.txt,sha256=nBpue4hU5Ykm5CtYPsAdxSa_yqbtZsIT_gF_EkBaJPM,12
|
|
22
|
+
xiaozhi_sdk-0.0.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|