Daily-Dose/SimonSays.py

49 lines
1.2 KiB
Python
Raw Normal View History

2020-12-12 11:42:17 +00:00
"""
Simon Says
"""
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
base_url = "https://azure.microsoft.com/en-in/services/cognitive-services/text-to-speech/"
fname = "./archive-daily-dose/11 November, 2020.html"
text = open(fname,'rb').read().decode('utf-8')
#text = "Hakuna Matata fjbsdf sd fsdf sdf s df sd fs df"
def strip_html(text):
import re
p = re.compile(r'<.*?>')
return p.sub('',text)
#print(text)
text = strip_html(text)
driver = webdriver.Chrome()
driver.get(base_url)
WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.ID, "languageselect"))
)
langsel = driver.find_element_by_id('languageselect')
select = Select(langsel)
select.select_by_visible_text("English (UK)")
voicesel = driver.find_element_by_id('voiceselect')
select = Select(voicesel)
select.select_by_visible_text("Mia (Neural)")
textselect = driver.find_element_by_id('ttstext')
textselect.clear()
textselect.send_keys(text)
play = driver.find_element_by_id('playbtn')
play.click()
#river.quit()