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.
- {xiaozhi_sdk-0.2.1/xiaozhi_sdk.egg-info → xiaozhi_sdk-0.2.3}/PKG-INFO +1 -1
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/tests/test_wake_word.py +3 -1
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/__init__.py +1 -1
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/core.py +34 -12
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3/xiaozhi_sdk.egg-info}/PKG-INFO +1 -1
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/LICENSE +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/MANIFEST.in +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/README.md +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/audio/greet.wav +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/audio/play_music.wav +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/audio/say_hello.wav +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/audio/take_photo.wav +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/image/leijun.jpg +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/opus/linux-arm64-libopus.so +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/opus/linux-x64-libopus.so +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/opus/macos-arm64-libopus.dylib +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/opus/macos-x64-libopus.dylib +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/file/opus/windows-opus.dll +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/pyproject.toml +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/setup.cfg +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/tests/test_iot.py +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/tests/test_pic.py +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/tests/test_xiaozhi.py +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/__main__.py +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/cli.py +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/config.py +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/iot.py +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/mcp.py +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/opus.py +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/utils/__init__.py +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/utils/mcp_tool.py +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk/utils/tool_func.py +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk.egg-info/SOURCES.txt +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk.egg-info/dependency_links.txt +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk.egg-info/requires.txt +0 -0
- {xiaozhi_sdk-0.2.1 → xiaozhi_sdk-0.2.3}/xiaozhi_sdk.egg-info/top_level.txt +0 -0
|
@@ -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()
|
|
@@ -122,9 +122,16 @@ class XiaoZhiWebsocket(McpTool):
|
|
|
122
122
|
|
|
123
123
|
async def send_wake_word(self, wake_word: str) -> None:
|
|
124
124
|
"""发送唤醒词"""
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
143
|
-
|
|
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
|
-
|
|
155
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
196
|
+
logger.debug("[websocket] close")
|
|
175
197
|
|
|
176
198
|
async def set_mcp_tool(self, mcp_tool_list) -> None:
|
|
177
199
|
"""设置MCP工具"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|