-
Notifications
You must be signed in to change notification settings - Fork 0
/
smart-ai-assistant.py
135 lines (119 loc) · 5.09 KB
/
smart-ai-assistant.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from features.spotify_funcs.spotify_control import Spotifier
from features.ears.hearing import Ears
from features.voice.voice import Voice
from datetime import datetime
from features.weather import get_weather
from features.news import get_news
import speech_recognition as sr
from features.clap_detector import clap_trigger
import argparse
ears = Ears()
voice = Voice()
spier = Spotifier()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Smart AI Assistant")
parser.add_argument("action", nargs="?", default=None, help="Specify an action (e.g. clap)")
args = parser.parse_args()
if args.action == "clap" and clap_trigger():
# WELCOME SONG
# spier.play_track("Hotel California", "Eagles")
# spier.play_track("The day the never comes", "Metallica")
spier.play_track("Back in black", "AC/DC")
spier.change_volume(85)
# GREETING
if datetime.now().hour >= 0 and datetime.now().hour < 12:
print("Good morning sir!")
voice.speak("Good morning sir!")
elif datetime.now().hour >= 12 and datetime.now().hour < 18:
print("Good afternoon sir!")
voice.speak("Good afternoon sir!")
else:
print("Good evening sir!")
voice.speak("Good evening sir!")
print("Some Black Sabbath to start the day nicely.")
voice.speak("Some Black Sabbath to start the day nicely.")
# THE WEATHER
msg = get_weather(location="Athens")
print(msg)
voice.speak(msg)
# JARVIS READY
print("I hope you have a creative day! Jarvis is at your service, for whatever you need sir.")
voice.speak("I hope you have a creative day! Jarvis is at your service for whatever you need sir.")
if spier.isbusy():
spier.change_volume(60)
while True:
ears.listen_to_microphone(spier)
elif args.action == "welcome":
# WELCOME SONG
# spier.play_track("Hotel California", "Eagles")
# spier.play_track("The day the never comes", "Metallica")
spier.play_track("Back in black", "AC/DC")
spier.change_volume(85)
# GREETING
if datetime.now().hour >= 0 and datetime.now().hour < 12:
print("Good morning sir!")
voice.speak("Good morning sir!")
elif datetime.now().hour >= 12 and datetime.now().hour < 18:
print("Good afternoon sir!")
voice.speak("Good afternoon sir!")
else:
print("Good evening sir!")
voice.speak("Good evening sir!")
print("Some Black Sabbath to start the day nicely.")
voice.speak("Some Black Sabbath to start the day nicely.")
# THE WEATHER
msg = get_weather(location="Athens")
print(msg)
voice.speak(msg)
# THE NEWS
print("Wanna hear the news?")
voice.speak("Wanna hear the news?")
if spier.isbusy():
spier.change_volume(60)
try:
with sr.Microphone() as source:
ears.recognizer.adjust_for_ambient_noise(source)
audio = ears.recognizer.listen(source)
command = ears.recognizer.recognize_google(audio).lower()
print(f"You said: {command}")
if "yes" in command or "please" in command or "sure" in command:
print("Sure thing!")
voice.speak("Sure thing!")
print("Today's top science news are:")
newslist = get_news()
voice.speak("Today's top science news are:")
for i, news in enumerate(newslist):
print(f"{i+1}. {news}")
voice.speak(news)
voice.speak(".")
else:
print("Okay then.")
voice.speak("Okay then.")
if spier.isbusy():
spier.change_volume(85)
except sr.UnknownValueError:
print("No news for you then.")
voice.speak("No news for you then.")
if spier.isbusy():
spier.change_volume(85)
# JARVIS READY
print("I hope you have a creative day! Jarvis is at your service, for whatever you need sir.")
voice.speak("I hope you have a creative day! Jarvis is at your service for whatever you need sir.")
while True:
ears.listen_to_microphone(spier)
else:
# GREETING
if datetime.now().hour >= 0 and datetime.now().hour < 12:
print("Good morning sir!")
voice.speak("Good morning sir!")
elif datetime.now().hour >= 12 and datetime.now().hour < 18:
print("Good afternoon sir!")
voice.speak("Good afternoon sir!")
else:
print("Good evening sir!")
voice.speak("Good evening sir!")
# JARVIS READY
print("Expecting your orders!")
voice.speak("Expecting your orders!")
while True:
ears.listen_to_microphone(spier)