From 123f7919b06b30938d83d80ea8417c31e8ff188e Mon Sep 17 00:00:00 2001 From: david-ajax Date: Wed, 30 Jul 2025 01:55:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=9F=B3=E9=A2=91=E9=A2=84?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=AE=9E=E7=94=A8=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- precaching.py | 42 ++++++++++++++++++++++++++++++++++++++++++ reactor.py | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5841f3a..2f0f946 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .directory __pycache__/ scripts/ -.idea \ No newline at end of file +.idea +cache \ No newline at end of file diff --git a/precaching.py b/precaching.py index e69de29..ce56652 100644 --- a/precaching.py +++ b/precaching.py @@ -0,0 +1,42 @@ +import particles as pt +import edge_tts as tts +from pathlib import Path +import shutil + +def precache(text): + cache_dir = Path(f"./cache/voice/") + cache_dir.mkdir(parents = True, exist_ok = True) + cache = cache_dir / f"{text}.wav" + if not cache.exists(): + communicate = tts.Communicate(text, "zh-CN-YunjianNeural") + communicate.save_sync(f"./cache/voice/{text}.wav") + +def proc_file(path): + nu = pt.NucleonUnion(path) + c = 0 + for i in nu.nucleons: + c += 1 + print(f"预缓存 [{nu.name}] ({c}/{len(nu)}): {i["content"]}") + precache(f"{i["content"]}") + +def walk(path_str): + path = Path(path_str) + + print(f"正在遍历目录: {path}") + for item in path.iterdir(): + if item.is_file(): + if item.suffix == ".toml": + print(f"正预缓存文件: {item.name}") + proc_file(item) + elif item.is_dir(): + print(f"进入目录: {item.name}") + +print("音频预缓存实用程序") +print("需要?") +print("全部缓存: A") +print("清空缓存: C") +choice = input("输入选项 $ ") +if choice == "a" or choice == "A": + walk("./nucleon") +if choice == "c" or choice == "C": + shutil.rmtree("./cache/voice") \ No newline at end of file diff --git a/reactor.py b/reactor.py index 8d70574..fa98687 100644 --- a/reactor.py +++ b/reactor.py @@ -2,6 +2,7 @@ import typing import particles as pt import pathlib import auxiliary as aux + class Parser(): """轻量级版本文件解析器, 用于文件管理器的记忆状态解析"""