Amazing-Python-Scripts
49 строк · 1.2 Кб
1import speech_recognition as sr2import webbrowser3
4
5def takeCommand():6recognizer = sr.Recognizer()7
8with sr.Microphone() as source:9print("\nListening...\n")10recognizer.adjust_for_ambient_noise(source)11audio = recognizer.listen(source)12
13try:14command = recognizer.recognize_google(audio).lower()15print(f"\nCommand: {command}\n")16return command17except sr.UnknownValueError:18print("Could not understand audio. Please try again.")19return None20except sr.RequestError as e:21print(f"\nError occurred while requesting results: {e}\n")22return None23
24
25def openWebsite(website):26website = website.replace("Open", "")27website = website.replace(" ", "")28url = f"https://www.{website}.com"29webbrowser.open(url)30
31
32def displayInstructions():33print('''\n\n1. Say "Open ${Website Name}" to open the Website.342. Say "exit" to close the program.\n
35''')36
37
38if __name__ == "__main__":39displayInstructions()40while True:41command = takeCommand()42
43if command == "exit":44print("\nExiting...\n")45print("Thanks for using this program !\n")46break47
48elif command:49openWebsite(command)50