关于python:简单的读屏软件Linux-2021710

4次阅读

共计 1206 个字符,预计需要花费 4 分钟才能阅读完成。

背景

最近学外语须要读屏软件,vscode-translator-voice 须要注册 Azure,glate 又须要拜访谷歌翻译,都不不便,只好本人赶快写个年老简略有时童稚的小软件。谷歌翻译 TTS 的成果比拟机械化,所以调用的是微软翻译。

环境:Manjaro+Firefox+Pycharm+KDE

  • 筹备工作

    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 即可进行播放。

正文完
 0