mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-25 00:23:53 +08:00
🦄 refactor(log): colorful log
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import json
|
||||
import logging
|
||||
from config.logger import setup_logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
TAG = __name__
|
||||
logger = setup_logging()
|
||||
|
||||
|
||||
async def handleAbortMessage(conn):
|
||||
logger.info("Abort message received")
|
||||
logger.bind(tag=TAG).info("Abort message received")
|
||||
# 设置成打断状态,会自动打断llm、tts任务
|
||||
conn.client_abort = True
|
||||
# 打断屏显任务
|
||||
@@ -13,4 +14,4 @@ async def handleAbortMessage(conn):
|
||||
# 打断客户端说话状态
|
||||
await conn.websocket.send(json.dumps({"type": "tts", "state": "stop", "session_id": conn.session_id}))
|
||||
conn.clearSpeakStatus()
|
||||
logger.info("Abort message received-end")
|
||||
logger.bind(tag=TAG).info("Abort message received-end")
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import logging
|
||||
from config.logger import setup_logging
|
||||
import json
|
||||
import asyncio
|
||||
import time
|
||||
from core.utils.util import remove_punctuation_and_length, get_string_no_punctuation_or_emoji
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
TAG = __name__
|
||||
logger = setup_logging()
|
||||
|
||||
|
||||
async def handleAudioMessage(conn, audio):
|
||||
if not conn.asr_server_receive:
|
||||
logger.debug(f"前期数据处理中,暂停接收")
|
||||
logger = setup_logging()
|
||||
logger.bind(tag=TAG).debug(f"前期数据处理中,暂停接收")
|
||||
return
|
||||
if conn.client_listen_mode == "auto":
|
||||
have_voice = conn.vad.is_vad(conn, audio)
|
||||
@@ -28,7 +30,7 @@ async def handleAudioMessage(conn, audio):
|
||||
conn.client_abort = False
|
||||
conn.asr_server_receive = False
|
||||
text, file_path = conn.asr.speech_to_text(conn.asr_audio, conn.session_id)
|
||||
logger.info(f"识别文本: {text}")
|
||||
logger.bind(tag=TAG).info(f"识别文本: {text}")
|
||||
text_len, text_without_punctuation = remove_punctuation_and_length(text)
|
||||
if text_len <= conn.max_cmd_length and await handleCMDMessage(conn, text_without_punctuation):
|
||||
return
|
||||
@@ -44,7 +46,7 @@ async def handleCMDMessage(conn, text):
|
||||
cmd_exit = conn.cmd_exit
|
||||
for cmd in cmd_exit:
|
||||
if text == cmd:
|
||||
logger.info("识别到明确的退出命令".format(text))
|
||||
logger.bind(tag=TAG).info("识别到明确的退出命令".format(text))
|
||||
await finishToChat(conn)
|
||||
return True
|
||||
return False
|
||||
@@ -80,7 +82,7 @@ async def sendAudioMessage(conn, audios, duration, text):
|
||||
|
||||
# 发送 tts.start
|
||||
if text == conn.tts_first_text:
|
||||
logger.info(f"发送第一段语音: {text}")
|
||||
logger.bind(tag=TAG).info(f"发送第一段语音: {text}")
|
||||
conn.tts_start_speak_time = time.time()
|
||||
|
||||
# 发送 sentence_start(每个音频文件之前发送一次)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import json
|
||||
import logging
|
||||
from config.logger import setup_logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger = setup_logging()
|
||||
|
||||
|
||||
async def handleHelloMessage(conn):
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import logging
|
||||
from config.logger import setup_logging
|
||||
import json
|
||||
from core.handle.abortHandle import handleAbortMessage
|
||||
from core.handle.helloHandle import handleHelloMessage
|
||||
from core.handle.audioHandle import startToChat
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
TAG = __name__
|
||||
logger = setup_logging()
|
||||
|
||||
|
||||
async def handleTextMessage(conn, message):
|
||||
"""处理文本消息"""
|
||||
logger.info(f"收到文本消息:{message}")
|
||||
logger.bind(tag=TAG).info(f"收到文本消息:{message}")
|
||||
try:
|
||||
msg_json = json.loads(message)
|
||||
if isinstance(msg_json, int):
|
||||
@@ -22,7 +23,7 @@ async def handleTextMessage(conn, message):
|
||||
elif msg_json["type"] == "listen":
|
||||
if "mode" in msg_json:
|
||||
conn.client_listen_mode = msg_json["mode"]
|
||||
logger.debug(f"客户端拾音模式:{conn.client_listen_mode}")
|
||||
logger.bind(tag=TAG).debug(f"客户端拾音模式:{conn.client_listen_mode}")
|
||||
if msg_json["state"] == "start":
|
||||
conn.client_have_voice = True
|
||||
conn.client_voice_stop = False
|
||||
|
||||
Reference in New Issue
Block a user