update:优化空asr语音

This commit is contained in:
hrz
2025-06-08 01:09:32 +08:00
parent 594b4f1d75
commit 61232e7dda
4 changed files with 15 additions and 4 deletions
@@ -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和空文本的情况