From 082684a6b11aec73dd8749d57640412a9bd656e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=B5=E6=9B=A6?= Date: Tue, 13 Jan 2026 16:06:18 +0800 Subject: [PATCH] =?UTF-8?q?tts=20=E5=BE=AA=E7=8E=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xiaomusic/device_player.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/xiaomusic/device_player.py b/xiaomusic/device_player.py index fe39ca4..95c5321 100644 --- a/xiaomusic/device_player.py +++ b/xiaomusic/device_player.py @@ -647,6 +647,9 @@ class XiaoMusicDevice: ) self.log.info(f"edge-tts 生成的文件路径: {mp3_path}") + # 保存当前 TTS 文件路径,用于定时器清空文件 + self._current_tts_file = mp3_path + # 生成播放 URL url = self.xiaomusic._music_url_handler._get_file_url(mp3_path) self.log.info(f"TTS 播放 URL: {url}") @@ -667,6 +670,20 @@ class XiaoMusicDevice: self.log.info("TTS 播放定时器时间到") if self._tts_timer: self._tts_timer = None + # 保底逻辑:删除临时 mp3 文件 + if ( + hasattr(self, "_current_tts_file") + and self._current_tts_file + ): + try: + if os.path.exists(self._current_tts_file): + await asyncio.sleep(1) # 延迟1秒后再删除文件 + os.remove(self._current_tts_file) + self.log.info( + f"已删除 TTS 临时文件: {self._current_tts_file}" + ) + except Exception as delete_err: + self.log.warning(f"删除 TTS 文件失败: {delete_err}") await self.stop(arg1="notts") except Exception as e: self.log.error(f"TTS 定时器异常: {e}")