mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 17:43:55 +08:00
refactor: 优化非流式音频过滤机制
fix: 修复等待中被打断队列被停止造成的死锁
This commit is contained in:
@@ -17,7 +17,11 @@ AUDIO_FRAME_DURATION = 60
|
||||
PRE_BUFFER_COUNT = 5
|
||||
|
||||
|
||||
async def sendAudioMessage(conn: "ConnectionHandler", sentenceType, audios, text):
|
||||
async def sendAudioMessage(conn: "ConnectionHandler", sentenceType, audios, text, sentence_id=None):
|
||||
# 跳过旧句子残留音频
|
||||
if sentence_id is not None and sentence_id != conn.sentence_id:
|
||||
return
|
||||
|
||||
if conn.tts.tts_audio_first_sentence:
|
||||
conn.logger.bind(tag=TAG).info(f"发送第一段语音: {text}")
|
||||
conn.tts.tts_audio_first_sentence = False
|
||||
@@ -281,12 +285,14 @@ async def send_tts_message(conn: "ConnectionHandler", state, text=None):
|
||||
await sendAudio(conn, audios)
|
||||
# 等待所有音频包发送完成
|
||||
await _wait_for_audio_completion(conn)
|
||||
# 停止音频发送循环(仅在流控器已初始化时调用)
|
||||
if hasattr(conn, "audio_rate_controller") and conn.audio_rate_controller:
|
||||
conn.audio_rate_controller.stop_sending()
|
||||
|
||||
# 检查是否是当前轮次
|
||||
if current_sentence_id != conn.sentence_id:
|
||||
return
|
||||
|
||||
# 停止音频发送循环(仅在流控器已初始化时调用)
|
||||
if hasattr(conn, "audio_rate_controller") and conn.audio_rate_controller:
|
||||
conn.audio_rate_controller.stop_sending()
|
||||
conn.clearSpeakStatus()
|
||||
|
||||
# 发送消息到客户端
|
||||
|
||||
Reference in New Issue
Block a user