增加软件管理实用程序与音频缓存机制修复

This commit is contained in:
2025-09-10 23:27:02 +08:00
parent 6293b69ef0
commit bb99b0a0b7
8 changed files with 277 additions and 15 deletions

View File

@@ -1,18 +1,20 @@
# 音频预缓存实用程序, 独立于主程序之外, 但依赖 particles 组件
# 音频预缓存实用程序, 独立于主程序之外, 但依赖其他组件
import particles as pt
import auxiliary as aux
import edge_tts as tts
from pathlib import Path
import shutil
import time
def precache(text: str):
"""预缓存单个文本的音频"""
cache_dir = Path("./cache/voice/")
cache_dir.mkdir(parents=True, exist_ok=True)
cache = cache_dir / f"{text}.wav"
cache = cache_dir / f"{aux.get_md5(text)}.wav"
if not cache.exists():
communicate = tts.Communicate(text, "zh-CN-XiaoxiaoNeural")
communicate.save_sync(f"./cache/voice/{text}.wav")
communicate.save_sync(f"./cache/voice/{aux.get_md5(text)}.wav")
def proc_file(path: Path):
@@ -29,14 +31,17 @@ def walk(path_str: str):
"""遍历目录处理所有文件"""
path = Path(path_str)
print(f"正在遍历目录: {path}")
for item in path.iterdir():
if item.is_file() and item.suffix == ".toml":
print(f"正预缓存文件: {item.name}")
proc_file(item)
elif item.is_dir():
print(f"进入目录: {item.name}")
try:
for item in path.iterdir():
if item.is_file() and item.suffix == ".toml":
print(f"正预缓存文件: {item.name}")
proc_file(item)
elif item.is_dir():
print(f"进入目录: {item.name}")
except:
print("发生一个异常, 于 5 秒后自动重新下载")
time.sleep(5)
walk(path_str)
if __name__ == "__main__":
print("音频预缓存实用程序")