add clean
This commit is contained in:
parent
a7876fb472
commit
2d403e2965
@ -397,13 +397,6 @@ class InputProcess:
|
|||||||
self.tts_app_key = "aGjiRDfUWi"
|
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.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 工作线程
|
# 启动 TTS 工作线程
|
||||||
self._start_tts_worker()
|
self._start_tts_worker()
|
||||||
@ -439,11 +432,7 @@ class InputProcess:
|
|||||||
if should_process_audio:
|
if should_process_audio:
|
||||||
self._process_audio()
|
self._process_audio()
|
||||||
|
|
||||||
# 3. 检查是否需要执行自动清理
|
# 3. 短暂休眠,减少CPU占用
|
||||||
if self.auto_cleanup_enabled:
|
|
||||||
self._check_auto_cleanup()
|
|
||||||
|
|
||||||
# 4. 短暂休眠,减少CPU占用
|
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
@ -834,28 +823,6 @@ class InputProcess:
|
|||||||
print(f"❌ 输入进程保存录音失败: {e}")
|
print(f"❌ 输入进程保存录音失败: {e}")
|
||||||
return None
|
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):
|
def _list_recordings_info(self):
|
||||||
"""列出录音文件信息"""
|
"""列出录音文件信息"""
|
||||||
try:
|
try:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user