From cccf7189e378dbb2ddbd181eca7931f1b8724118 Mon Sep 17 00:00:00 2001 From: david-ajax Date: Thu, 21 Aug 2025 13:30:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=92=AD=E6=94=BE=E6=9C=BA?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .playsound.py | 2 ++ auxiliary.py | 14 ++++++++++++++ main.py | 17 +++++------------ nucleon/示例.toml | 22 ---------------------- 4 files changed, 21 insertions(+), 34 deletions(-) create mode 100644 .playsound.py delete mode 100644 nucleon/示例.toml diff --git a/.playsound.py b/.playsound.py new file mode 100644 index 0000000..09e008d --- /dev/null +++ b/.playsound.py @@ -0,0 +1,2 @@ +def playsound(p): + print(p) \ No newline at end of file diff --git a/auxiliary.py b/auxiliary.py index 015b31f..997931e 100644 --- a/auxiliary.py +++ b/auxiliary.py @@ -2,6 +2,9 @@ import time import pathlib import toml import typing +import playsound +import threading +import edge_tts as tts class ConfigFile: def __init__(self, path: str): @@ -34,6 +37,17 @@ class ConfigFile: """获取配置值,如果不存在返回默认值""" return self.data.get(key, default) +def action_play_voice(content): + def play(): + communicate = tts.Communicate( + content, + "zh-CN-YunjianNeural", + ) + communicate.save_sync( + f"./cache/voice/{content}" + ) + playsound() + threading.Thread(target=play).start() def get_daystamp() -> int: """获取当前日戳(以天为单位的整数时间戳)""" diff --git a/main.py b/main.py index ecc2b7e..d3b38fc 100644 --- a/main.py +++ b/main.py @@ -22,18 +22,7 @@ import auxiliary as aux import compositions as compo import builtins -# Hook python 的 open() 函数, 使用 utf-8 (兼容 Windows 万年 GBK) - -_original_open = builtins.open - -def _open(*args, **kwargs): - if "encoding" not in kwargs: - kwargs["encoding"] = "utf-8" - return _original_open(*args, **kwargs) - -builtins.open = _open - -ver = "0.3.0" +ver = "0.3.1b" config = aux.ConfigFile("config.toml") @@ -62,6 +51,8 @@ class MemScreen(Screen): self.compo = next(self.reactor.current_appar) def compose(self) -> ComposeResult: + if type(self.compo).__name__ == "Recognition": + self.action_play_voice() yield Header(show_clock=True) with Center(): yield Static( @@ -116,8 +107,10 @@ class MemScreen(Screen): def refresh_ui(self): self.call_later(self.recompose) + print(type(self.compo).__name__) def action_play_voice(self): + print("VOICE") def play(): cache_dir = pathlib.Path(f"./cache/voice/") cache_dir.mkdir(parents=True, exist_ok=True) diff --git a/nucleon/示例.toml b/nucleon/示例.toml deleted file mode 100644 index 056eeeb..0000000 --- a/nucleon/示例.toml +++ /dev/null @@ -1,22 +0,0 @@ -# 文件头, 按部就班复制即可 -["keydata"] -note = "笔记" -keyword_note = "关键词翻译" -translation = "语句翻译" -["testdata"] -additional_inf = ["translation","keyword_note", "note"] -fill_blank_test = {"from"=["content"], "hint"=["translation"]} - - -#可重复的单元 -draw_card_test = {"from"=["keyword_note"]} -[CONTENT] -note = [] -translation = "TRANSLATION" -keyword_note = {"KN_KEY": "KN_VALUE"} - -#这是一个示例:(不要求附加在生成文本中) -["臣/密/言: /臣/以/险衅/, 夙/遭/闵凶./"] -note = [] -translation = "臣子李密陈言: 我因命运不好, 小时候遭遇到了不幸" -keyword_note = {"险衅"="凶险祸患(这里指命运不好)", "夙"="早时, 这里指年幼的时候", "闵"="通'悯', 指可忧患的事", "凶"="不幸, 指丧父"}