xiaozhi-sdk 0.2.3__tar.gz → 0.2.5__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.
Potentially problematic release.
This version of xiaozhi-sdk might be problematic. Click here for more details.
- {xiaozhi_sdk-0.2.3/xiaozhi_sdk.egg-info → xiaozhi_sdk-0.2.5}/PKG-INFO +1 -1
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/xiaozhi_sdk/__init__.py +1 -1
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/xiaozhi_sdk/core.py +8 -3
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/xiaozhi_sdk/mcp.py +22 -21
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5/xiaozhi_sdk.egg-info}/PKG-INFO +1 -1
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/LICENSE +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/MANIFEST.in +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/README.md +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/file/audio/greet.wav +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/file/audio/play_music.wav +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/file/audio/say_hello.wav +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/file/audio/take_photo.wav +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/file/image/leijun.jpg +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/file/opus/linux-arm64-libopus.so +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/file/opus/linux-x64-libopus.so +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/file/opus/macos-arm64-libopus.dylib +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/file/opus/macos-x64-libopus.dylib +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/file/opus/windows-opus.dll +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/pyproject.toml +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/setup.cfg +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/tests/test_iot.py +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/tests/test_pic.py +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/tests/test_wake_word.py +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/tests/test_xiaozhi.py +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/xiaozhi_sdk/__main__.py +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/xiaozhi_sdk/cli.py +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/xiaozhi_sdk/config.py +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/xiaozhi_sdk/iot.py +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/xiaozhi_sdk/opus.py +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/xiaozhi_sdk/utils/__init__.py +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/xiaozhi_sdk/utils/mcp_tool.py +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/xiaozhi_sdk/utils/tool_func.py +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/xiaozhi_sdk.egg-info/SOURCES.txt +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/xiaozhi_sdk.egg-info/dependency_links.txt +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/xiaozhi_sdk.egg-info/requires.txt +0 -0
- {xiaozhi_sdk-0.2.3 → xiaozhi_sdk-0.2.5}/xiaozhi_sdk.egg-info/top_level.txt +0 -0
|
@@ -120,18 +120,20 @@ class XiaoZhiWebsocket(McpTool):
|
|
|
120
120
|
await self.websocket.send(opus_data)
|
|
121
121
|
await self.send_silence_audio()
|
|
122
122
|
|
|
123
|
-
async def send_wake_word(self, wake_word: str) ->
|
|
123
|
+
async def send_wake_word(self, wake_word: str) -> bool:
|
|
124
124
|
"""发送唤醒词"""
|
|
125
125
|
try:
|
|
126
126
|
await self.websocket.send(
|
|
127
127
|
json.dumps({"session_id": self.session_id, "type": "listen", "state": "detect", "text": wake_word})
|
|
128
128
|
)
|
|
129
|
+
return True
|
|
129
130
|
except websockets.ConnectionClosed:
|
|
130
131
|
if self.message_handler_callback:
|
|
131
132
|
await self.message_handler_callback(
|
|
132
133
|
{"type": "websocket", "state": "close", "source": "sdk.send_wake_word"}
|
|
133
134
|
)
|
|
134
135
|
logger.debug("[websocket] close")
|
|
136
|
+
return False
|
|
135
137
|
|
|
136
138
|
async def send_silence_audio(self, duration_seconds: float = 1.2) -> None:
|
|
137
139
|
"""发送静音音频"""
|
|
@@ -253,15 +255,16 @@ class XiaoZhiWebsocket(McpTool):
|
|
|
253
255
|
if self.wake_word:
|
|
254
256
|
await self.send_wake_word(self.wake_word)
|
|
255
257
|
|
|
256
|
-
async def send_audio(self, pcm: bytes) ->
|
|
258
|
+
async def send_audio(self, pcm: bytes) -> bool:
|
|
257
259
|
"""发送音频数据"""
|
|
258
260
|
if not self.websocket:
|
|
259
|
-
return
|
|
261
|
+
return False
|
|
260
262
|
|
|
261
263
|
state = self.websocket.state
|
|
262
264
|
if state == websockets.protocol.State.OPEN:
|
|
263
265
|
opus_data = await self.audio_opus.pcm_to_opus(pcm)
|
|
264
266
|
await self.websocket.send(opus_data)
|
|
267
|
+
return True
|
|
265
268
|
elif state in [websockets.protocol.State.CLOSED, websockets.protocol.State.CLOSING]:
|
|
266
269
|
if self.wait_device_activated:
|
|
267
270
|
logger.debug("[websocket] Server actively disconnected, reconnecting...")
|
|
@@ -272,8 +275,10 @@ class XiaoZhiWebsocket(McpTool):
|
|
|
272
275
|
logger.debug("[websocket] Server actively disconnected")
|
|
273
276
|
|
|
274
277
|
await asyncio.sleep(0.5)
|
|
278
|
+
return False
|
|
275
279
|
else:
|
|
276
280
|
await asyncio.sleep(0.1)
|
|
281
|
+
return False
|
|
277
282
|
|
|
278
283
|
async def close(self) -> None:
|
|
279
284
|
"""关闭连接"""
|
|
@@ -12,24 +12,23 @@ from xiaozhi_sdk.utils.tool_func import _get_random_music_info
|
|
|
12
12
|
|
|
13
13
|
logger = logging.getLogger("xiaozhi_sdk")
|
|
14
14
|
|
|
15
|
-
mcp_initialize_payload: Dict[str, Any] = {
|
|
16
|
-
"jsonrpc": "2.0",
|
|
17
|
-
"id": 1,
|
|
18
|
-
"result": {
|
|
19
|
-
"protocolVersion": "2024-11-05",
|
|
20
|
-
"capabilities": {"tools": {}},
|
|
21
|
-
"serverInfo": {"name": "", "version": "0.0.1"},
|
|
22
|
-
},
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
mcp_tools_payload: Dict[str, Any] = {
|
|
26
|
-
"jsonrpc": "2.0",
|
|
27
|
-
"id": 2,
|
|
28
|
-
"result": {"tools": []},
|
|
29
|
-
}
|
|
30
|
-
|
|
31
15
|
|
|
32
16
|
class McpTool(object):
|
|
17
|
+
mcp_initialize_payload: Dict[str, Any] = {
|
|
18
|
+
"jsonrpc": "2.0",
|
|
19
|
+
"id": 1,
|
|
20
|
+
"result": {
|
|
21
|
+
"protocolVersion": "2024-11-05",
|
|
22
|
+
"capabilities": {"tools": {}},
|
|
23
|
+
"serverInfo": {"name": "", "version": "0.0.1"},
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
mcp_tools_payload: Dict[str, Any] = {
|
|
28
|
+
"id": 2,
|
|
29
|
+
"jsonrpc": "2.0",
|
|
30
|
+
"result": {"tools": []},
|
|
31
|
+
}
|
|
33
32
|
|
|
34
33
|
def __init__(self):
|
|
35
34
|
self.session_id = ""
|
|
@@ -131,8 +130,8 @@ class McpTool(object):
|
|
|
131
130
|
# self.explain_url = "http://82.157.143.133:8000/vision/explain"
|
|
132
131
|
self.explain_token = payload["params"]["capabilities"]["vision"]["token"]
|
|
133
132
|
|
|
134
|
-
mcp_initialize_payload["id"] = payload["id"]
|
|
135
|
-
await self.websocket.send(self.get_mcp_json(mcp_initialize_payload))
|
|
133
|
+
self.mcp_initialize_payload["id"] = payload["id"]
|
|
134
|
+
await self.websocket.send(self.get_mcp_json(self.mcp_initialize_payload))
|
|
136
135
|
|
|
137
136
|
elif method == "notifications/initialized":
|
|
138
137
|
# print("\nMCP 工具初始化")
|
|
@@ -142,9 +141,9 @@ class McpTool(object):
|
|
|
142
141
|
logger.error("[MCP] 工具加载失败")
|
|
143
142
|
|
|
144
143
|
elif method == "tools/list":
|
|
145
|
-
mcp_tools_payload["id"] = payload["id"]
|
|
146
144
|
tool_name_list = []
|
|
147
145
|
mcp_tool_dict = copy.deepcopy(self.mcp_tool_dict)
|
|
146
|
+
mcp_tool_list = []
|
|
148
147
|
for _, mcp_tool in mcp_tool_dict.items():
|
|
149
148
|
tool_name_list.append(mcp_tool["name"])
|
|
150
149
|
tool_func = mcp_tool.pop("tool_func", None)
|
|
@@ -152,9 +151,11 @@ class McpTool(object):
|
|
|
152
151
|
logger.error("[MCP] Tool %s has no tool_func", mcp_tool["name"])
|
|
153
152
|
return
|
|
154
153
|
mcp_tool.pop("is_async", None)
|
|
155
|
-
|
|
154
|
+
mcp_tool_list.append(mcp_tool)
|
|
156
155
|
|
|
157
|
-
|
|
156
|
+
self.mcp_tools_payload["id"] = payload["id"]
|
|
157
|
+
self.mcp_tools_payload["result"]["tools"] = mcp_tool_list
|
|
158
|
+
await self.websocket.send(self.get_mcp_json(self.mcp_tools_payload))
|
|
158
159
|
logger.debug("[MCP] 加载成功,当前可用工具列表为:%s", tool_name_list)
|
|
159
160
|
|
|
160
161
|
elif method == "tools/call":
|
|
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
|