xiaozhi-sdk 0.2.1__tar.gz → 0.2.3__tar.gz

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.
Files changed (36) hide show
  1. {xiaozhi_sdk-0.2.1/xiaozhi_sdk.egg-info → xiaozhi_sdk-0.2.3}/PKG-INFO +1 -1
  2. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/tests/test_wake_word.py +3 -1
  3. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/__init__.py +1 -1
  4. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/core.py +34 -12
  5. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3/xiaozhi_sdk.egg-info}/PKG-INFO +1 -1
  6. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/LICENSE +0 -0
  7. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/MANIFEST.in +0 -0
  8. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/README.md +0 -0
  9. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/audio/greet.wav +0 -0
  10. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/audio/play_music.wav +0 -0
  11. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/audio/say_hello.wav +0 -0
  12. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/audio/take_photo.wav +0 -0
  13. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/image/leijun.jpg +0 -0
  14. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/opus/linux-arm64-libopus.so +0 -0
  15. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/opus/linux-x64-libopus.so +0 -0
  16. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/opus/macos-arm64-libopus.dylib +0 -0
  17. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/opus/macos-x64-libopus.dylib +0 -0
  18. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/opus/windows-opus.dll +0 -0
  19. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/pyproject.toml +0 -0
  20. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/setup.cfg +0 -0
  21. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/tests/test_iot.py +0 -0
  22. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/tests/test_pic.py +0 -0
  23. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/tests/test_xiaozhi.py +0 -0
  24. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/__main__.py +0 -0
  25. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/cli.py +0 -0
  26. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/config.py +0 -0
  27. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/iot.py +0 -0
  28. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/mcp.py +0 -0
  29. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/opus.py +0 -0
  30. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/utils/__init__.py +0 -0
  31. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/utils/mcp_tool.py +0 -0
  32. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/utils/tool_func.py +0 -0
  33. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk.egg-info/SOURCES.txt +0 -0
  34. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk.egg-info/dependency_links.txt +0 -0
  35. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk.egg-info/requires.txt +0 -0
  36. {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xiaozhi-sdk
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: 一个用于连接和控制小智智能设备的Python SDK,支持实时音频通信、MCP工具集成和设备管理功能。
5
5
  Author-email: dairoot <623815825@qq.com>
6
6
  License-Expression: MIT
@@ -25,7 +25,9 @@ async def test_main():
25
25
  xiaozhi = XiaoZhiWebsocket(message_handler_callback, url=URL, ota_url=ota_url)
26
26
  await xiaozhi.init_connection(MAC_ADDR)
27
27
 
28
- await xiaozhi.send_wake_word("你是")
28
+ await xiaozhi.send_wake_word("退下,拜拜不聊了")
29
+ await asyncio.wait_for(is_end.wait(), timeout=20.0)
30
+ await xiaozhi.send_wake_word("你好")
29
31
 
30
32
  await asyncio.wait_for(is_end.wait(), timeout=20.0)
31
33
  await xiaozhi.close()
@@ -1,3 +1,3 @@
1
- __version__ = "0.2.1"
1
+ __version__ = "0.2.3"
2
2
 
3
3
  from xiaozhi_sdk.core import XiaoZhiWebsocket # noqa
@@ -122,9 +122,16 @@ class XiaoZhiWebsocket(McpTool):
122
122
 
123
123
  async def send_wake_word(self, wake_word: str) -> None:
124
124
  """发送唤醒词"""
125
- await self.websocket.send(
126
- json.dumps({"session_id": self.session_id, "type": "listen", "state": "detect", "text": wake_word})
127
- )
125
+ try:
126
+ await self.websocket.send(
127
+ json.dumps({"session_id": self.session_id, "type": "listen", "state": "detect", "text": wake_word})
128
+ )
129
+ except websockets.ConnectionClosed:
130
+ if self.message_handler_callback:
131
+ await self.message_handler_callback(
132
+ {"type": "websocket", "state": "close", "source": "sdk.send_wake_word"}
133
+ )
134
+ logger.debug("[websocket] close")
128
135
 
129
136
  async def send_silence_audio(self, duration_seconds: float = 1.2) -> None:
130
137
  """发送静音音频"""
@@ -139,8 +146,11 @@ class XiaoZhiWebsocket(McpTool):
139
146
 
140
147
  # audio data
141
148
  if isinstance(message, bytes):
142
- pcm_array = await self.audio_opus.opus_to_pcm(message)
143
- self.output_audio_queue.extend(pcm_array)
149
+ try:
150
+ pcm_array = await self.audio_opus.opus_to_pcm(message)
151
+ self.output_audio_queue.extend(pcm_array)
152
+ except Exception as e:
153
+ logger.error("opus_to_pcm error: %s", e)
144
154
  return
145
155
 
146
156
  # json message
@@ -149,29 +159,41 @@ class XiaoZhiWebsocket(McpTool):
149
159
  if message_type == "hello":
150
160
  self.hello_received.set()
151
161
  self.session_id = data["session_id"]
162
+ return
152
163
  elif message_type == "mcp":
153
164
  await self.mcp(data)
154
- elif self.message_handler_callback:
155
- if data["type"] == "tts":
165
+ return
166
+
167
+ # 转发其他 message_type
168
+ if self.message_handler_callback:
169
+ try:
170
+ await self.message_handler_callback(data)
171
+ except Exception as e:
172
+ logger.error("message_handler_callback error: %s", e)
173
+
174
+ if message_type == "tts":
156
175
  if data["state"] == "sentence_start":
157
176
  self.is_playing = True
158
- # self.output_audio_queue.clear()
159
177
  else:
160
178
  self.is_playing = False
161
-
162
- await self.message_handler_callback(data)
179
+ else:
180
+ logger.warning("未定义回调函数 %s", data)
163
181
 
164
182
  async def _message_handler(self) -> None:
165
183
  """消息处理器"""
166
184
  try:
167
185
  async for message in self.websocket:
168
- await self._handle_websocket_message(message)
186
+ try:
187
+ await self._handle_websocket_message(message)
188
+ except Exception as e:
189
+ logger.error("message_handler error: %s", e)
190
+
169
191
  except websockets.ConnectionClosed:
170
192
  if self.message_handler_callback:
171
193
  await self.message_handler_callback(
172
194
  {"type": "websocket", "state": "close", "source": "sdk.message_handler"}
173
195
  )
174
- logger.debug("[websocket] close")
196
+ logger.debug("[websocket] close")
175
197
 
176
198
  async def set_mcp_tool(self, mcp_tool_list) -> None:
177
199
  """设置MCP工具"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xiaozhi-sdk
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: 一个用于连接和控制小智智能设备的Python SDK,支持实时音频通信、MCP工具集成和设备管理功能。
5
5
  Author-email: dairoot <623815825@qq.com>
6
6
  License-Expression: MIT
File without changes
File without changes
File without changes
File without changes
File without changes