from
selenium
import
webdriver
from
selenium.webdriver.support.ui
import
WebDriverWait
from
selenium.webdriver.support
import
expected_conditions
from
selenium.webdriver.common.by
import
By
from
selenium.webdriver.common.keys
import
Keys
import
speech_recognition as sr
import
pyttsx3
import
time
def
automateYoutube(searchtext):
path
=
"C:\\Users\\hp\\Downloads\\chromedriver"
driver
=
webdriver.Chrome(path)
driver.get(url)
driver.find_element_by_name(
"search_query"
).send_keys(searchtext)
driver.find_element_by_css_selector(
"#search-icon-legacy.ytd-searchbox"
).click()
WebDriverWait(driver,
0
).until(expected_conditions.title_contains(MyText))
WebDriverWait(driver,
30
).until(
expected_conditions.element_to_be_clickable((By.
ID
,
"img"
))).click()
speak
=
sr.Recognizer()
try
:
with sr.Microphone() as speaky:
speak.adjust_for_ambient_noise(speaky, duration
=
0.2
)
print
(
"listening..."
)
searchquery
=
speak.listen(speaky)
MyText
=
speak.recognize_google(searchquery)
MyText
=
MyText.lower()
except
sr.RequestError as e:
print
(
"Could not request results; {0}"
.
format
(e))
except
sr.UnknownValueError:
print
(
"unknown error occurred"
)
automateYoutube(MyText)