mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
@@ -17,7 +17,7 @@ TAG = __name__
|
||||
|
||||
WAKEUP_CONFIG = {
|
||||
"refresh_time": 5,
|
||||
"words": ["你好小智", "你好啊小智", "小智你好", "小智"],
|
||||
"words": ["你好", "你好啊", "嘿,你好", "嗨"],
|
||||
}
|
||||
|
||||
# 创建全局的唤醒词配置管理器
|
||||
|
||||
@@ -15,11 +15,13 @@ async def handleAudioMessage(conn, audio):
|
||||
have_voice = conn.vad.is_vad(conn, audio)
|
||||
|
||||
# 如果设备刚刚被唤醒,短暂忽略VAD检测
|
||||
if hasattr(conn, "just_woken_up") and conn.just_woken_up:
|
||||
if have_voice and hasattr(conn, "just_woken_up") and conn.just_woken_up:
|
||||
have_voice = False
|
||||
# 设置一个短暂延迟后恢复VAD检测
|
||||
conn.asr_audio.clear()
|
||||
asyncio.create_task(resume_vad_detection(conn))
|
||||
if not hasattr(conn, "vad_resume_task") or conn.vad_resume_task.done():
|
||||
print("clear asr_audio")
|
||||
conn.vad_resume_task = asyncio.create_task(resume_vad_detection(conn))
|
||||
|
||||
if have_voice:
|
||||
if conn.client_is_speaking:
|
||||
@@ -32,7 +34,7 @@ async def handleAudioMessage(conn, audio):
|
||||
|
||||
async def resume_vad_detection(conn):
|
||||
# 等待2秒后恢复VAD检测
|
||||
await asyncio.sleep(2)
|
||||
await asyncio.sleep(1)
|
||||
conn.just_woken_up = False
|
||||
|
||||
|
||||
|
||||
@@ -168,6 +168,7 @@ class ASRProvider(ASRProviderBase):
|
||||
if (
|
||||
"payload_msg" in result
|
||||
and result["payload_msg"]["code"] != self.success_code
|
||||
and result["payload_msg"]["code"] != 1013 # 忽略无有效语音的错误
|
||||
):
|
||||
logger.bind(tag=TAG).error(f"ASR error: {result}")
|
||||
return None
|
||||
@@ -203,6 +204,9 @@ class ASRProvider(ASRProviderBase):
|
||||
if len(result["payload_msg"]["result"]) > 0:
|
||||
return result["payload_msg"]["result"][0]["text"]
|
||||
return None
|
||||
elif "payload_msg" in result and result["payload_msg"]["code"] == 1013:
|
||||
# 无有效语音,返回空字符串
|
||||
return ""
|
||||
else:
|
||||
logger.bind(tag=TAG).error(f"ASR error: {result}")
|
||||
return None
|
||||
|
||||
@@ -157,6 +157,11 @@ class ASRProvider(ASRProviderBase):
|
||||
|
||||
if "payload_msg" in result:
|
||||
payload = result["payload_msg"]
|
||||
# 检查是否是错误码1013(无有效语音)
|
||||
if "code" in payload and payload["code"] == 1013:
|
||||
# 静默处理,不记录错误日志
|
||||
continue
|
||||
|
||||
if "result" in payload:
|
||||
utterances = payload["result"].get("utterances", [])
|
||||
# 检查duration和空文本的情况
|
||||
|
||||
Reference in New Issue
Block a user