自动播放机制
This commit is contained in:
2
.playsound.py
Normal file
2
.playsound.py
Normal file
@@ -0,0 +1,2 @@
|
||||
def playsound(p):
|
||||
print(p)
|
14
auxiliary.py
14
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:
|
||||
"""获取当前日戳(以天为单位的整数时间戳)"""
|
||||
|
17
main.py
17
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)
|
||||
|
@@ -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 = {"险衅"="凶险祸患(这里指命运不好)", "夙"="早时, 这里指年幼的时候", "闵"="通'悯', 指可忧患的事", "凶"="不幸, 指丧父"}
|
Reference in New Issue
Block a user