-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathwebsites.py
49 lines (37 loc) · 1.22 KB
/
websites.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import speech_recognition as sr
import webbrowser
def takeCommand():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("\nListening...\n")
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)
try:
command = recognizer.recognize_google(audio).lower()
print(f"\nCommand: {command}\n")
return command
except sr.UnknownValueError:
print("Could not understand audio. Please try again.")
return None
except sr.RequestError as e:
print(f"\nError occurred while requesting results: {e}\n")
return None
def openWebsite(website):
website = website.replace("Open", "")
website = website.replace(" ", "")
url = f"https://www.{website}.com"
webbrowser.open(url)
def displayInstructions():
print('''\n\n1. Say "Open ${Website Name}" to open the Website.
2. Say "exit" to close the program.\n
''')
if __name__ == "__main__":
displayInstructions()
while True:
command = takeCommand()
if command == "exit":
print("\nExiting...\n")
print("Thanks for using this program !\n")
break
elif command:
openWebsite(command)