mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-30 17:43:56 +08:00
update:豆包tts流式ASR空字符串问题
This commit is contained in:
@@ -82,9 +82,9 @@ class ASRProviderBase(ABC):
|
||||
) # 确保ASR模块返回原始文本
|
||||
conn.logger.bind(tag=TAG).info(f"识别文本: {raw_text}")
|
||||
text_len, _ = remove_punctuation_and_length(raw_text)
|
||||
self.stop_ws_connection()
|
||||
if text_len > 0:
|
||||
# 使用自定义模块进行上报
|
||||
self.stop_ws_connection()
|
||||
await startToChat(conn, raw_text)
|
||||
enqueue_asr_report(conn, raw_text, asr_audio_task)
|
||||
|
||||
|
||||
@@ -54,12 +54,8 @@ class ASRProvider(ASRProviderBase):
|
||||
await super().open_audio_channels(conn)
|
||||
|
||||
async def receive_audio(self, conn, audio, audio_have_voice):
|
||||
if not isinstance(audio, bytes):
|
||||
return
|
||||
|
||||
conn.asr_audio.append(audio)
|
||||
if audio_have_voice == False and conn.client_have_voice == False:
|
||||
conn.asr_audio = conn.asr_audio[-10:]
|
||||
conn.asr_audio = conn.asr_audio[-10:]
|
||||
|
||||
# 如果本次有声音,且之前没有建立连接
|
||||
if audio_have_voice and self.asr_ws is None and not self.is_processing:
|
||||
@@ -114,9 +110,6 @@ class ASRProvider(ASRProviderBase):
|
||||
|
||||
# 发送缓存的音频数据
|
||||
if conn.asr_audio and len(conn.asr_audio) > 0:
|
||||
logger.bind(tag=TAG).info(
|
||||
f"发送缓存音频数据: {len(conn.asr_audio)}"
|
||||
)
|
||||
for cached_audio in conn.asr_audio[-10:]:
|
||||
try:
|
||||
pcm_frame = self.decoder.decode(cached_audio, 960)
|
||||
@@ -166,6 +159,18 @@ class ASRProvider(ASRProviderBase):
|
||||
payload = result["payload_msg"]
|
||||
if "result" in payload:
|
||||
utterances = payload["result"].get("utterances", [])
|
||||
# 检查duration和空文本的情况
|
||||
if (
|
||||
payload.get("audio_info", {}).get("duration", 0) > 2000
|
||||
and not utterances
|
||||
and not payload["result"].get("text")
|
||||
):
|
||||
logger.bind(tag=TAG).error(f"识别文本:空")
|
||||
self.text = ""
|
||||
conn.reset_vad_states()
|
||||
await self.handle_voice_stop(conn, None)
|
||||
break
|
||||
|
||||
for utterance in utterances:
|
||||
if utterance.get("definite", False):
|
||||
self.text = utterance["text"]
|
||||
@@ -235,7 +240,7 @@ class ASRProvider(ASRProviderBase):
|
||||
"sample_rate": self.rate,
|
||||
},
|
||||
}
|
||||
logger.bind(tag=TAG).info(
|
||||
logger.bind(tag=TAG).debug(
|
||||
f"构造请求参数: {json.dumps(req, ensure_ascii=False)}"
|
||||
)
|
||||
return req
|
||||
|
||||
Reference in New Issue
Block a user