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