Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from libs_voice import *
- mutex = threading.Lock()# Создаем мьютекс
- def mic(driver):
- mutex.acquire() # Захватываем мьютекс
- primary_button = driver.find_element("id", "mic")
- style_value = primary_button.get_attribute("style")
- pattern = r"--(\w+)"
- result = re.search(pattern, style_value)
- # time.sleep(0.75)
- if result:
- res= (result.group(1))
- if res != "secondary-color":
- # print("on")
- driver.find_element("id", "mic").click() # выключить запись голоса
- time.sleep(0.75)
- driver.find_element("id", "mic").click() # включить запись голоса
- time.sleep(0.75)
- else:
- time.sleep(0.75)
- driver.find_element("id", "mic").click() # включить запись голоса
- mutex.release() # Освобождаем мьютекс
- def a():
- while 1:
- with keyboard.Listener(on_release=on_release, on_press=on_press) as listener:
- listener.join()
- driver=0
- try:
- prefs = {'safebrowsing.enabled': True,
- "credentials_enable_service": False,
- "profile.password_manager_enabled": False,
- "credentials_enable_service": False,
- "profile.password_manager_enabled": False,
- "profile.managed_default_content_settings.images": 0,
- # - Отключить загрузку CSS:
- # "profile.default_content_setting_values.javascript": 2,
- # - Отключить загрузку JavaScript:
- "profile.default_content_setting_values.cache": 0
- # - Включить кэширование:
- }
- option = webdriver.ChromeOptions()
- option.add_experimental_option("prefs", prefs)
- option.add_experimental_option("excludeSwitches", ['enable-automation']) # убрать окно
- 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")
- option.add_argument("--use-fake-ui-for-media-stream") # звук
- option.add_argument("--disable-popup-blocking") # блок всплывающих окон.
- option.add_argument("--disable-blink-features=AutomationControlled")
- option.add_argument('--disable-web-security')
- option.add_argument("--disk-cache-size=0")
- option.add_argument("--media-cache-size=0")
- option.add_argument("--automatic-wait-for-preview")
- option.add_argument("--enable-features=WebRtcHideLocalIpsWithMdns")
- option.add_argument("--disable-site-isolation-trials")
- option.binary_location = '/usr/bin/google-chrome'
- option.add_argument("--disable-session-crashed-bubble")
- option.add_argument('--disable-infobars')
- option.add_argument('--user-data-dir=/home/egor/.config/google-chrome')
- try:
- driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),
- options=option)
- driver.set_window_size(624, 568) # optiol
- driver.set_window_position(600, 250) # Открываем новое окно
- driver.get("https://www.speechtexter.com")# открыть сайт
- k.save_driver(driver)
- time.sleep(1.5)
- driver.find_element("id", "mic").click() # включить запись голоса
- time.sleep(2.91)
- driver.minimize_window()
- except Exception as ex2:
- print("lkjn")
- if 'no such window: target window' in str(ex2):
- print("exit no such window: target window already closed")
- error_closse(driver)
- # print(ex2) # print("error")
- time.sleep(5)
- pass
- t1 = threading.Thread(target=a)
- t1.start()
- except Exception as ex1:
- # print(ex1) # driver.close() # driver.quit()
- pass
- # t2 = threading.Thread(target=t, args=(driver,))
- # t2.start()
- while 1:
- try:
- # time.sleep(0.31)
- text0 = driver.find_element("id", "textEditor").text
- text = str(text0)
- if len(text) != 0 and text != None and text != "None":
- driver.find_element("id", "textEditor").clear() # удалить старый текст.
- text = str(text.lower()) + str(" ")
- text = repeat(text, k)
- if k.get_flag() == True:
- k.set_flag(False)
- text0 = text[0].upper() + text[1:]
- press_keys(text0)
- else:
- press_keys(text)
- print("+++++++++++++++")
- mic(driver)
- text = "None"
- except KeyboardInterrupt:
- error_closse(driver)
- break
- except Exception as ex: #
- print(ex)
- if 'HTTPConnectionPool'in str(ex):
- print("exit HTTPConnectionPool") # except HTTPConnectionPool:
- error_closse(driver)
- break
- if 'SIGKILL'in str(ex):
- print("exit SIGKILL") # except HTTPConnectionPool:
- error_closse(driver)
- break
- if 'no such window: target window already closed'in str(ex):
- print("exit target window closed")
- error_closse(driver)
- break
- print("yex")
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement