diff --git a/recorder.py b/recorder.py index 405783d..765c780 100644 --- a/recorder.py +++ b/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: diff --git a/tts_response_20250920_165657.mp3 b/tts_response_20250920_165657.mp3 deleted file mode 100644 index 763b82b..0000000 Binary files a/tts_response_20250920_165657.mp3 and /dev/null differ diff --git a/tts_test.mp3 b/tts_test.mp3 deleted file mode 100644 index 46dd725..0000000 Binary files a/tts_test.mp3 and /dev/null differ