Add debug logging to track audio data flow and TTS processing
Added comprehensive debug logging to identify why audio playback ends without starting: - TTS text processing and buffer management - Audio chunk generation and transfer between buffers - TTS task queue management - Streaming text processing This will help identify if the issue is: 1. Empty text being sent to TTS 2. TTS generation failing 3. Audio data not being transferred between buffers 4. Premature completion detection 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
92c5e0b9e4
commit
85a67aa1fa
@ -463,10 +463,13 @@ class InputProcess:
|
||||
|
||||
def _add_tts_task(self, content):
|
||||
"""添加TTS任务到队列"""
|
||||
print(f"🔊 OutputProcess添加TTS任务到队列: '{content[:30]}...' (队列大小: {self.tts_task_queue.qsize()})")
|
||||
try:
|
||||
self.tts_task_queue.put_nowait(("tts_sentence", content))
|
||||
print(f"✅ OutputProcess TTS任务添加成功,队列大小: {self.tts_task_queue.qsize()}")
|
||||
return True
|
||||
except queue.Full:
|
||||
print(f"❌ OutputProcess TTS任务队列已满,丢弃任务")
|
||||
self.logger.warning("TTS任务队列已满,丢弃任务")
|
||||
return False
|
||||
|
||||
@ -598,7 +601,7 @@ class OutputProcess:
|
||||
|
||||
# 智能缓冲系统 - 借鉴 recorder.py 的智能句子累积策略
|
||||
self.preload_buffer = [] # 预加载缓冲区(保留用于音频块)
|
||||
self.preload_size = 1 # 预加载1个音频块即可开始播放
|
||||
self.preload_size = 3 # 预加载3个音频块
|
||||
|
||||
# 智能句子缓冲系统 - 从 recorder.py 借鉴的核心机制
|
||||
self.tts_buffer = [] # 智能句子缓冲区
|
||||
@ -1448,16 +1451,20 @@ class OutputProcess:
|
||||
|
||||
def _add_tts_task(self, content):
|
||||
"""添加TTS任务到队列"""
|
||||
print(f"🔊 OutputProcess添加TTS任务到队列: '{content[:30]}...' (队列大小: {self.tts_task_queue.qsize()})")
|
||||
try:
|
||||
self.tts_task_queue.put_nowait(("tts_sentence", content))
|
||||
print(f"✅ OutputProcess TTS任务添加成功,队列大小: {self.tts_task_queue.qsize()}")
|
||||
return True
|
||||
except queue.Full:
|
||||
print(f"❌ OutputProcess TTS任务队列已满,丢弃任务")
|
||||
self.logger.warning("TTS任务队列已满,丢弃任务")
|
||||
return False
|
||||
|
||||
def _generate_tts_audio(self, text):
|
||||
"""生成TTS音频数据并发送到统一播放队列 - 借鉴 recorder.py 的流式处理"""
|
||||
try:
|
||||
print(f"🔊 TTS开始生成音频,文本长度: {len(text)} 文本内容: {text[:50]}...")
|
||||
self.logger.info(f"生成TTS音频: {text[:50]}...")
|
||||
|
||||
# 清空所有缓冲区,确保新的音频不被旧数据干扰
|
||||
@ -1562,15 +1569,20 @@ class OutputProcess:
|
||||
continue
|
||||
|
||||
# 处理剩余的预加载数据
|
||||
print(f"🔊 TTS生成结束,检查剩余预加载数据: preload_buffer={len(self.preload_buffer)} 块")
|
||||
if self.preload_buffer:
|
||||
print(f"🔊 将剩余的 {len(self.preload_buffer)} 个音频块转移到播放缓冲区")
|
||||
self.playback_buffer.extend(self.preload_buffer)
|
||||
self.preload_buffer.clear()
|
||||
if not self.is_playing:
|
||||
self.is_playing = True
|
||||
self.last_playback_time = time.time()
|
||||
self.logger.info("开始播放TTS音频(处理剩余预加载)")
|
||||
else:
|
||||
print(f"⚠️ TTS生成完成但预加载缓冲区为空!")
|
||||
|
||||
success_rate = (success_count / chunk_count * 100) if chunk_count > 0 else 0
|
||||
print(f"🔊 TTS音频生成完成统计: chunk_count={chunk_count}, success_count={success_count}, success_rate={success_rate:.1f}%, total_size={total_audio_size / 1024:.1f} KB")
|
||||
self.logger.info(f"TTS音频生成完成: {chunk_count} 块, 成功率 {success_rate:.1f}% | 总大小: {total_audio_size / 1024:.1f} KB")
|
||||
|
||||
# 通知自己TTS生成已完成
|
||||
@ -1625,29 +1637,42 @@ class OutputProcess:
|
||||
|
||||
def _process_tts_buffer(self):
|
||||
"""处理TTS缓冲区 - 发送累积的句子到TTS"""
|
||||
print(f"🔊 处理TTS缓冲区,当前缓冲区内容: {self.tts_buffer}")
|
||||
if not self.tts_buffer:
|
||||
print(f"🔊 TTS缓冲区为空,跳过处理")
|
||||
return
|
||||
|
||||
# 合并缓冲区的句子
|
||||
combined_text = ''.join(self.tts_buffer)
|
||||
print(f"🔊 合并后的文本: '{combined_text}' (长度: {len(combined_text)})")
|
||||
|
||||
# 添加到TTS任务队列
|
||||
print(f"🔊 尝试添加TTS任务到队列")
|
||||
if self._add_tts_task(combined_text):
|
||||
print(f"🎵 触发TTS: {combined_text[:50]}...")
|
||||
self.tts_last_trigger_time = time.time()
|
||||
else:
|
||||
print(f"❌ 添加TTS任务失败")
|
||||
|
||||
# 清空缓冲区
|
||||
self.tts_buffer.clear()
|
||||
print(f"🔊 TTS缓冲区已清空")
|
||||
|
||||
def _add_sentence_to_buffer(self, sentence):
|
||||
"""添加句子到智能缓冲区 - 核心方法"""
|
||||
print(f"🔊 添加句子到TTS缓冲区: '{sentence}' (缓冲区大小: {len(self.tts_buffer)} -> {len(self.tts_buffer)+1})")
|
||||
if not sentence.strip():
|
||||
print(f"🔊 句子为空,不添加到缓冲区")
|
||||
return
|
||||
|
||||
self.tts_buffer.append(sentence)
|
||||
print(f"🔊 已添加到TTS缓冲区,当前缓冲区: {self.tts_buffer}")
|
||||
|
||||
# 检查是否应该触发TTS
|
||||
if self._should_trigger_tts(sentence):
|
||||
should_trigger = self._should_trigger_tts(sentence)
|
||||
print(f"🔊 是否应该触发TTS: {should_trigger}")
|
||||
if should_trigger:
|
||||
print(f"🔊 触发TTS缓冲区处理")
|
||||
self._process_tts_buffer()
|
||||
|
||||
def _flush_tts_buffer(self):
|
||||
@ -1725,15 +1750,21 @@ class OutputProcess:
|
||||
|
||||
def process_streaming_text(self, text):
|
||||
"""处理流式文本 - 新增的公共接口,用于与LLM流式输出集成"""
|
||||
print(f"🔊 收到流式文本: '{text}' (长度: {len(text)})")
|
||||
if not text.strip():
|
||||
print(f"🔊 流式文本为空,跳过处理")
|
||||
return
|
||||
|
||||
# 过滤括号内容
|
||||
filtered_text = self._filter_parentheses_content(text.strip())
|
||||
print(f"🔊 过滤后的文本: '{filtered_text}' (长度: {len(filtered_text)})")
|
||||
|
||||
if filtered_text:
|
||||
# 使用智能句子缓冲系统
|
||||
print(f"🔊 添加文本到智能缓冲区")
|
||||
self._add_sentence_to_buffer(filtered_text)
|
||||
else:
|
||||
print(f"🔊 过滤后文本为空,不添加到缓冲区")
|
||||
|
||||
def process_complete_text(self, text):
|
||||
"""处理完整文本 - 强制刷新缓冲区"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user