xiaozhi-sdk 0.2.7__tar.gz → 0.2.8__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.7/xiaozhi_sdk.egg-info → xiaozhi_sdk-0.2.8}/PKG-INFO +1 -1
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/pyproject.toml +0 -2
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/xiaozhi_sdk/__init__.py +1 -1
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/xiaozhi_sdk/cli.py +17 -10
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8/xiaozhi_sdk.egg-info}/PKG-INFO +1 -1
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/LICENSE +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/MANIFEST.in +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/README.md +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/file/audio/16k_greet.wav +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/file/audio/16k_play_music.wav +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/file/audio/16k_say_hello.wav +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/file/audio/16k_take_photo.wav +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/file/audio/test_16k.wav +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/file/audio/test_24k.wav +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/file/audio/test_48k.wav +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/file/image/leijun.jpg +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/file/opus/linux-arm64-libopus.so +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/file/opus/linux-x64-libopus.so +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/file/opus/macos-arm64-libopus.dylib +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/file/opus/macos-x64-libopus.dylib +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/file/opus/windows-opus.dll +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/setup.cfg +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/tests/test_iot.py +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/tests/test_pic.py +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/tests/test_wake_word.py +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/tests/test_xiaozhi.py +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/tests/test_xiaozhi_opus.py +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/xiaozhi_sdk/__main__.py +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/xiaozhi_sdk/config.py +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/xiaozhi_sdk/core.py +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/xiaozhi_sdk/iot.py +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/xiaozhi_sdk/mcp.py +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/xiaozhi_sdk/opus.py +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/xiaozhi_sdk/utils/__init__.py +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/xiaozhi_sdk/utils/mcp_tool.py +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/xiaozhi_sdk/utils/tool_func.py +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/xiaozhi_sdk.egg-info/SOURCES.txt +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/xiaozhi_sdk.egg-info/dependency_links.txt +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/xiaozhi_sdk.egg-info/requires.txt +0 -0
- {xiaozhi_sdk-0.2.7 → xiaozhi_sdk-0.2.8}/xiaozhi_sdk.egg-info/top_level.txt +0 -0
|
@@ -4,6 +4,7 @@ import logging
|
|
|
4
4
|
import time
|
|
5
5
|
import uuid
|
|
6
6
|
from collections import deque
|
|
7
|
+
from tkinter import NO
|
|
7
8
|
from typing import Optional
|
|
8
9
|
|
|
9
10
|
import click
|
|
@@ -76,7 +77,8 @@ logger.setLevel(logging.DEBUG)
|
|
|
76
77
|
|
|
77
78
|
# 全局状态
|
|
78
79
|
input_audio_buffer: deque[bytes] = deque()
|
|
79
|
-
|
|
80
|
+
device_stauts = "listen" # "speak" or "listen"
|
|
81
|
+
|
|
80
82
|
is_end = False
|
|
81
83
|
human_speak_time = None
|
|
82
84
|
|
|
@@ -109,7 +111,7 @@ def get_image_byte(data):
|
|
|
109
111
|
|
|
110
112
|
|
|
111
113
|
async def handle_message(message):
|
|
112
|
-
global
|
|
114
|
+
global device_stauts
|
|
113
115
|
global human_speak_time
|
|
114
116
|
|
|
115
117
|
"""处理接收到的消息"""
|
|
@@ -122,11 +124,11 @@ async def handle_message(message):
|
|
|
122
124
|
logger.info1("human: %s", message["text"])
|
|
123
125
|
|
|
124
126
|
elif message["type"] == "tts" and message["state"] == "sentence_start": # AI语音
|
|
125
|
-
|
|
127
|
+
device_stauts = "speak" # 防止打断
|
|
126
128
|
logger.info2("AI: %s", message["text"])
|
|
127
129
|
|
|
128
130
|
elif message["type"] == "tts" and message["state"] == "stop":
|
|
129
|
-
|
|
131
|
+
device_stauts = "listen"
|
|
130
132
|
# logger.info2("播放结束")
|
|
131
133
|
logger.info("聆听中...")
|
|
132
134
|
elif message["type"] == "llm": # 表情
|
|
@@ -141,27 +143,33 @@ async def handle_message(message):
|
|
|
141
143
|
|
|
142
144
|
async def play_assistant_audio(audio_queue: deque[bytes], enable_audio, audio_samplerate):
|
|
143
145
|
"""播放音频流"""
|
|
144
|
-
global
|
|
146
|
+
global device_stauts
|
|
145
147
|
global human_speak_time
|
|
146
148
|
|
|
147
149
|
stream = None
|
|
148
150
|
if enable_audio:
|
|
149
151
|
stream = sd.OutputStream(samplerate=audio_samplerate, channels=INPUT_AUDIO_CHANNELS, dtype=np.int16)
|
|
150
152
|
stream.start()
|
|
153
|
+
|
|
151
154
|
last_audio_time = None
|
|
152
155
|
|
|
153
156
|
while True:
|
|
154
157
|
if is_end:
|
|
155
158
|
return
|
|
156
159
|
|
|
160
|
+
if device_stauts == "listen":
|
|
161
|
+
last_audio_time = None
|
|
162
|
+
|
|
157
163
|
if not audio_queue:
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
164
|
+
# 空音频 超过 2s ,将device_stauts 设置为listen,代表聆听中
|
|
165
|
+
if device_stauts == "speak" and last_audio_time and time.time() - last_audio_time > 2:
|
|
166
|
+
device_stauts = "listen"
|
|
161
167
|
|
|
162
168
|
await asyncio.sleep(0.01)
|
|
163
169
|
continue
|
|
164
170
|
|
|
171
|
+
last_audio_time = time.time()
|
|
172
|
+
|
|
165
173
|
if human_speak_time:
|
|
166
174
|
logger.debug("首个音频包响应时间:%s 秒", time.time() - human_speak_time)
|
|
167
175
|
human_speak_time = None
|
|
@@ -169,7 +177,6 @@ async def play_assistant_audio(audio_queue: deque[bytes], enable_audio, audio_sa
|
|
|
169
177
|
pcm_data = audio_queue.popleft()
|
|
170
178
|
if stream:
|
|
171
179
|
stream.write(pcm_data)
|
|
172
|
-
last_audio_time = time.time()
|
|
173
180
|
|
|
174
181
|
|
|
175
182
|
class XiaoZhiClient:
|
|
@@ -225,7 +232,7 @@ class XiaoZhiClient:
|
|
|
225
232
|
continue
|
|
226
233
|
|
|
227
234
|
pcm_data = input_audio_buffer.popleft()
|
|
228
|
-
if
|
|
235
|
+
if device_stauts == "listen":
|
|
229
236
|
|
|
230
237
|
await self.xiaozhi.send_audio(pcm_data)
|
|
231
238
|
else:
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|