1、将耗时最大的iot处理改成异步

2、iot循环5次等待func_handler加载完成
This commit is contained in:
hrz
2025-03-31 22:54:37 +08:00
parent fdd16ad3c7
commit 6ba63db47f
6 changed files with 150 additions and 71 deletions
@@ -6,6 +6,7 @@ from core.utils.util import remove_punctuation_and_length
from core.handle.receiveAudioHandle import startToChat, handleAudioMessage
from core.handle.sendAudioHandle import send_stt_message, send_tts_message
from core.handle.iotHandle import handleIotDescriptors, handleIotStatus
import asyncio
TAG = __name__
logger = setup_logging()
@@ -34,7 +35,7 @@ async def handleTextMessage(conn, message):
conn.client_have_voice = True
conn.client_voice_stop = True
if len(conn.asr_audio) > 0:
await handleAudioMessage(conn, b'')
await handleAudioMessage(conn, b"")
elif msg_json["state"] == "detect":
conn.asr_server_receive = False
conn.client_have_voice = False
@@ -57,8 +58,8 @@ async def handleTextMessage(conn, message):
await startToChat(conn, text)
elif msg_json["type"] == "iot":
if "descriptors" in msg_json:
await handleIotDescriptors(conn, msg_json["descriptors"])
asyncio.create_task(handleIotDescriptors(conn, msg_json["descriptors"]))
if "states" in msg_json:
await handleIotStatus(conn, msg_json["states"])
asyncio.create_task(handleIotStatus(conn, msg_json["states"]))
except json.JSONDecodeError:
await conn.websocket.send(message)