-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
56 lines (39 loc) · 1.27 KB
/
main.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
50
51
52
53
54
55
56
import subprocess
import speech_recognition as sr
from commands import music, weather, hello, stop
r = sr.Recognizer()
muted_testing = None
def handle_speech(result):
text = result.lower().strip()
if text.__contains__("orchid"):
hello.say_hello()
elif text.__contains__("tell me the weather"):
weather.get_weather_data()
elif text.__contains__("play"):
music.play_track(text.split("play ")[1])
elif text.__contains__("pause"):
music.pause_playback()
elif text.__contains__("resume"):
music.resume_playback()
elif text.__contains__("stop"):
stop.stop_orchid()
def handle_speech_input():
with sr.Microphone() as source:
print("Talk")
text = r.listen(source)
try:
result = r.recognize_google(text)
print("Text: " + result)
handle_speech(result)
handle_speech_input()
except:
print("Talk again")
handle_speech_input()
if __name__ == "__main__":
subprocess.Popen('python server.py', shell=True, start_new_session=True)
muted_testing = False # or False if not testing manually
if muted_testing:
# !MUTED TESTING
handle_speech("Orchid")
else:
handle_speech_input()