Advertisement
egor230

голосовой_набор_текста_в_linux

Oct 20th, 2023 (edited)
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.92 KB | Source Code | 0 0
  1. from libs_voice import *
  2.  
  3. mutex = threading.Lock()# Создаем мьютекс
  4. def mic(driver):
  5.   mutex.acquire()  # Захватываем мьютекс
  6.   primary_button = driver.find_element("id", "mic")
  7.   style_value = primary_button.get_attribute("style")
  8.  
  9.   pattern = r"--(\w+)"
  10.   result = re.search(pattern, style_value)
  11.   # time.sleep(0.75)
  12.   if result:
  13.     res= (result.group(1))
  14.     if res != "secondary-color":
  15.      # print("on")
  16.      driver.find_element("id", "mic").click()  # выключить запись голоса
  17.      time.sleep(0.75)
  18.      driver.find_element("id", "mic").click()  # включить запись голоса
  19.      time.sleep(0.75)
  20.   else:
  21.      time.sleep(0.75)
  22.      driver.find_element("id", "mic").click()  # включить запись голоса
  23.  
  24.   mutex.release()     # Освобождаем мьютекс
  25.  
  26. def a():
  27.   while 1:
  28.     with keyboard.Listener(on_release=on_release, on_press=on_press) as listener:
  29.       listener.join()
  30. driver=0
  31. try:
  32.    prefs = {'safebrowsing.enabled': True,
  33.            "credentials_enable_service": False,
  34.            "profile.password_manager_enabled": False,
  35.            "credentials_enable_service": False,
  36.            "profile.password_manager_enabled": False,
  37.            "profile.managed_default_content_settings.images": 0,
  38.            # - Отключить загрузку CSS:
  39.            # "profile.default_content_setting_values.javascript": 2,
  40.            # - Отключить загрузку JavaScript:
  41.            "profile.default_content_setting_values.cache": 0
  42.            # - Включить кэширование:
  43.            }
  44.    option = webdriver.ChromeOptions()
  45.    option.add_experimental_option("prefs", prefs)
  46.    option.add_experimental_option("excludeSwitches", ['enable-automation'])  # убрать окно
  47.    option.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.6367.118 Safari/537.36")
  48.    option.add_argument("--use-fake-ui-for-media-stream")  # звук
  49.    option.add_argument("--disable-popup-blocking")  # блок всплывающих окон.
  50.    option.add_argument("--disable-blink-features=AutomationControlled")
  51.    option.add_argument('--disable-web-security')
  52.    option.add_argument("--disk-cache-size=0")
  53.    option.add_argument("--media-cache-size=0")
  54.    option.add_argument("--automatic-wait-for-preview")
  55.    option.add_argument("--enable-features=WebRtcHideLocalIpsWithMdns")
  56.    option.add_argument("--disable-site-isolation-trials")
  57.    option.binary_location = '/usr/bin/google-chrome'
  58.    option.add_argument("--disable-session-crashed-bubble")
  59.    option.add_argument('--disable-infobars')
  60.    option.add_argument('--user-data-dir=/home/egor/.config/google-chrome')
  61.    try:
  62.     driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),
  63.                               options=option)
  64.     driver.set_window_size(624, 568) # optiol
  65.     driver.set_window_position(600, 250)    # Открываем новое окно
  66.     driver.get("https://www.speechtexter.com")# открыть сайт
  67.     k.save_driver(driver)
  68.     time.sleep(1.5)
  69.     driver.find_element("id", "mic").click()  # включить запись голоса
  70.     time.sleep(2.91)
  71.     driver.minimize_window()
  72.    except Exception as ex2:
  73.      print("lkjn")
  74.      if 'no such window: target window' in str(ex2):
  75.         print("exit no such window: target window already closed")
  76.         error_closse(driver)
  77.      # print(ex2)  # print("error")
  78.      time.sleep(5)
  79.      pass
  80.  
  81.    t1 = threading.Thread(target=a)
  82.    t1.start()
  83. except Exception as ex1:
  84.   # print(ex1)  # driver.close()  # driver.quit()
  85.   pass
  86.  
  87. # t2 = threading.Thread(target=t, args=(driver,))
  88. # t2.start()
  89. while 1:
  90.   try:
  91.       # time.sleep(0.31)
  92.       text0 = driver.find_element("id", "textEditor").text
  93.       text = str(text0)
  94.       if len(text) != 0 and text != None and text != "None":
  95.         driver.find_element("id", "textEditor").clear()  # удалить старый текст.
  96.         text = str(text.lower()) + str(" ")
  97.         text = repeat(text, k)
  98.         if k.get_flag() == True:
  99.           k.set_flag(False)
  100.           text0 = text[0].upper() + text[1:]
  101.           press_keys(text0)
  102.         else:
  103.           press_keys(text)
  104.         print("+++++++++++++++")
  105.         mic(driver)
  106.         text = "None"
  107.   except KeyboardInterrupt:
  108.     error_closse(driver)
  109.     break
  110.  
  111.   except Exception as ex:    #
  112.     print(ex)
  113.     if 'HTTPConnectionPool'in str(ex):
  114.       print("exit HTTPConnectionPool")    # except HTTPConnectionPool:
  115.       error_closse(driver)
  116.       break
  117.  
  118.     if 'SIGKILL'in str(ex):
  119.       print("exit SIGKILL")    # except HTTPConnectionPool:
  120.       error_closse(driver)
  121.       break
  122.     if 'no such window: target window already closed'in str(ex):
  123.       print("exit  target window  closed")
  124.       error_closse(driver)
  125.       break
  126.     print("yex")
  127.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement