add clean

This commit is contained in:
朱潮 2025-09-26 13:21:15 +08:00
parent a7876fb472
commit 2d403e2965

View File

@ -397,13 +397,6 @@ class InputProcess:
self.tts_app_key = "aGjiRDfUWi"
self.tts_speaker = config.get('tts_speaker', "zh_female_wanqudashu_moon_bigtts") if config else "zh_female_wanqudashu_moon_bigtts"
# 录音文件清理配置
self.cleanup_config = config.get('cleanup', {}) if config else {}
self.auto_cleanup_enabled = self.cleanup_config.get('auto_cleanup', False)
self.retention_hours = self.cleanup_config.get('retention_hours', 24)
self.max_files = self.cleanup_config.get('max_files', 50)
self.cleanup_interval = self.cleanup_config.get('cleanup_interval', 3600) # 1小时
self.last_cleanup_time = time.time()
# 启动 TTS 工作线程
self._start_tts_worker()
@ -439,11 +432,7 @@ class InputProcess:
if should_process_audio:
self._process_audio()
# 3. 检查是否需要执行自动清理
if self.auto_cleanup_enabled:
self._check_auto_cleanup()
# 4. 短暂休眠减少CPU占用
# 3. 短暂休眠减少CPU占用
time.sleep(0.01)
except KeyboardInterrupt:
@ -834,28 +823,6 @@ class InputProcess:
print(f"❌ 输入进程保存录音失败: {e}")
return None
def _check_auto_cleanup(self):
"""检查是否需要执行自动清理"""
current_time = time.time()
if current_time - self.last_cleanup_time >= self.cleanup_interval:
print(f"🧹 执行自动清理录音文件")
self._perform_cleanup()
self.last_cleanup_time = current_time
def _perform_cleanup(self):
"""执行录音文件清理"""
try:
if self.retention_hours > 0:
print(f"🧹 按时间清理录音文件(保留 {self.retention_hours} 小时内的文件)")
cleanup_recordings(retention_hours=self.retention_hours, dry_run=False)
if self.max_files > 0:
print(f"🧹 按数量清理录音文件(保留最新的 {self.max_files} 个文件)")
cleanup_recordings_by_count(max_files=self.max_files, dry_run=False)
except Exception as e:
print(f"❌ 执行清理时出错: {e}")
def _list_recordings_info(self):
"""列出录音文件信息"""
try: