config
This commit is contained in:
parent
ebeb4e34df
commit
bddaf5f31d
20
recorder.py
20
recorder.py
@ -625,10 +625,14 @@ class EnergyBasedRecorder:
|
||||
tts_file = self.text_to_speech(llm_response)
|
||||
if tts_file:
|
||||
print("✅ AI语音回复完成")
|
||||
# 删除录音文件
|
||||
self._safe_delete_file(filename, "录音文件")
|
||||
else:
|
||||
print("❌ 文本转语音失败")
|
||||
else:
|
||||
print("ℹ️ 文本转语音功能已禁用")
|
||||
# 如果不启用TTS,直接删除录音文件
|
||||
self._safe_delete_file(filename, "录音文件")
|
||||
else:
|
||||
print("❌ 大语言模型调用失败")
|
||||
else:
|
||||
@ -1063,6 +1067,17 @@ class EnergyBasedRecorder:
|
||||
print(f"❌ LLM调用失败: {e}")
|
||||
return None
|
||||
|
||||
def _safe_delete_file(self, filepath, description="文件"):
|
||||
"""安全删除文件"""
|
||||
try:
|
||||
if filepath and os.path.exists(filepath):
|
||||
os.remove(filepath)
|
||||
print(f"🗑️ 已删除{description}: {filepath}")
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"⚠️ 删除{description}失败: {e}")
|
||||
return False
|
||||
|
||||
def generate_tts_filename(self):
|
||||
"""生成TTS文件名"""
|
||||
timestamp = time.strftime("%Y%m%d_%H%M%S")
|
||||
@ -1167,9 +1182,14 @@ class EnergyBasedRecorder:
|
||||
print("ℹ️ 跳过播放TTS音频(无可用播放器)")
|
||||
print(f"📁 TTS音频已保存到: {output_file}")
|
||||
|
||||
# 播放完成后删除PCM文件
|
||||
self._safe_delete_file(output_file, "TTS音频文件")
|
||||
|
||||
return output_file
|
||||
else:
|
||||
print("❌ 未接收到TTS音频数据")
|
||||
# 尝试删除可能存在的空文件
|
||||
self._safe_delete_file(output_file, "空的TTS音频文件")
|
||||
return None
|
||||
|
||||
finally:
|
||||
|
||||
Binary file not shown.
BIN
tts_test.mp3
BIN
tts_test.mp3
Binary file not shown.
Loading…
Reference in New Issue
Block a user