简单的读屏软件(Linux) 2021.7.10

背景
最近学外语需要读屏软件, vscode-translator-voice 需要注册Azure, glate 又需要访问谷歌翻译,都不方便,只好自己赶快写个年轻简单有时幼稚的小软件。谷歌翻译TTS的效果比较机械化,所以调用的是微软翻译。
环境:Manjaro+Firefox+Pycharm+KDE

  • 【简单的读屏软件(Linux) 2021.7.10】准备工作
    pip install PyUserInput pip install pyperclip pip install selenium yay -S geckodriver

  • main.py
    import time import pyperclip from selenium import webdriver def sndtxt(str,tm): driver.find_element_by_id荐("tta_input_ta").send_keys(str) time.sleep(tm)# 用selenium自带的延时功能会出错 def clk(tm): driver.find_element_by_id("tta_playiconsrc").click() time.sleep(tm) driver.find_element_by_id("tta_input_ta").clear() driver = webdriver.Firefox() driver.get("https://cn.bing.com/translator") sndtxt("软件加载", 0.5) sndtxt("完成", 1.5) clk(1.5) while(1): time.sleep(0.5) text = pyperclip.paste() if text[0:12] == "577857775776":#暗号 sndtxt(text[12:], 0.5) clk(0) pyperclip.copy("6")

  • Hotkey.py
    import pyperclip from pykeyboard import * k = PyKeyboard() k.press_key(k.control_key) k.tap_key("c") k.release_key(k.control_key) pyperclip.copy("577857775776"+pyperclip.paste()) pyperclip.copy("577857775776"+pyperclip.paste()) #需要执行两次才能正常使用

    注册快捷键
    系统设置->快捷键->自定义快捷键->新建->全局快捷键->命令/URL
    命令/URL->触发器->快捷键:Ctrl+Shift+Space
    命令/URL->动作->命令/URL:python /home/帐户名/Hotkey.py
  • 说明书
    听到语音“软件加载完成“时,即可使用,选定需要朗读的内容(Within 500 Words),按Ctrl+Shift+Space播放,在尚在播放时再按Ctrl+Shift+Space即可停止播放。

    推荐阅读