fix: 修复型号M01获取对话记录时间戳的问题

This commit is contained in:
涵曦 2024-10-13 12:31:25 +08:00
parent 2e864eed7c
commit 42e44caf0d

View File

@ -178,6 +178,11 @@ class XiaoMusic:
# 拉取所有音箱的对话记录 # 拉取所有音箱的对话记录
tasks = [] tasks = []
for device_id in self.device_id_did: for device_id in self.device_id_did:
# 首次用当前时间初始化
did = self.get_did(device_id)
if did not in self.last_timestamp:
self.last_timestamp[did] = int(time.time() * 1000)
hardware = self.get_hardward(device_id) hardware = self.get_hardward(device_id)
if hardware in GET_ASK_BY_MINA or self.config.get_ask_by_mina: if hardware in GET_ASK_BY_MINA or self.config.get_ask_by_mina:
tasks.append(self.get_latest_ask_by_mina(device_id)) tasks.append(self.get_latest_ask_by_mina(device_id))
@ -331,8 +336,8 @@ class XiaoMusic:
f"get_latest_ask_by_mina device_id:{device_id} did:{did} response:{response}" f"get_latest_ask_by_mina device_id:{device_id} did:{did} response:{response}"
) )
if d := response.get("data", {}).get("info", {}): if d := response.get("data", {}).get("info", {}):
result = json.loads(d).get("result", []) result = json.loads(d).get("result", [{}])
if result and len(result) > 0: if result and len(result) > 0 and result[0].get("nlp"):
answers = ( answers = (
json.loads(result[0]["nlp"]) json.loads(result[0]["nlp"])
.get("response", {}) .get("response", {})
@ -340,7 +345,7 @@ class XiaoMusic:
) )
if answers: if answers:
query = answers[0].get("intention", {}).get("query", "").strip() query = answers[0].get("intention", {}).get("query", "").strip()
timestamp = result[0]["timestamp"] timestamp = result[0]["timestamp"] * 1000
answer = answers[0].get("content", {}).get("to_speak") answer = answers[0].get("content", {}).get("to_speak")
last_record = { last_record = {
"time": timestamp, "time": timestamp,
@ -374,9 +379,6 @@ class XiaoMusic:
query = last_record.get("query", "").strip() query = last_record.get("query", "").strip()
self.log.debug(f"获取到最后一条对话记录:{query} {timestamp}") self.log.debug(f"获取到最后一条对话记录:{query} {timestamp}")
# 首次用当前时间初始化
if did not in self.last_timestamp:
self.last_timestamp[did] = int(time.time() * 1000)
if timestamp > self.last_timestamp[did]: if timestamp > self.last_timestamp[did]:
self.last_timestamp[did] = timestamp self.last_timestamp[did] = timestamp
self.last_record = last_record self.last_record = last_record