Skip to content

Instantly share code, notes, and snippets.

@do-me
Created May 8, 2020 21:05
Show Gist options
  • Save do-me/e3e4703ae335f3c730c90030d70944e8 to your computer and use it in GitHub Desktop.
Save do-me/e3e4703ae335f3c730c90030d70944e8 to your computer and use it in GitHub Desktop.
# importing the neccessary packages
import speech_recognition as sr
from selenium import webdriver
# initialise speech_recognition
r = sr.Recognizer()
mic = sr.Microphone()
# listen!
with mic as source:
audio = r.listen(source)
# here we use Google's speech recognition for convenience
phrase = r.recognize_google(audio)
# if what me say matches "play the radio"...
if phrase == "play the radio":
print(phrase)
# open Chrome by initialising our browser driver
# just change the path to yours
# this is the Windows .exe version, it works the same for Linux
browser = webdriver.Chrome(executable_path="C:/.../chromedriver.exe")
# navigate to an online radio page, here Deutschlandfunk
browser.get("https://srv.deutschlandradio.de/themes/dradio/script/aod/index.html?audioMode=2&audioID=4&state=")
# and click the play button!
browser.find_element_by_xpath('//*[@class="mkdraod-audio-play"]').click()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment