-
Notifications
You must be signed in to change notification settings - Fork 1
/
heisenberg.py
178 lines (147 loc) · 5.93 KB
/
heisenberg.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import pyttsx3
import datetime
import speech_recognition as sr
import wikipedia
import webbrowser
import jokes_feature # file created by me not a module
import alarm_feature # file created by me not a module
# import pyaudio
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voices', voices[1].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def greetMe():
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour < 12:
speak("Hello and Good Morning!")
elif hour >= 12 and hour < 18:
speak("Hello and Good Afternoon!")
else:
speak("Hello and Good Evening!")
speak("My name is Heisenberg, I'm your virtual assistant please tell how may I help you?")
def getCommands():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
r.energy_threshold = 100
audio = r.listen(source)
# r.pyaudio_module = r.get_pyaudio()
# audio = r.pyaudio_module.PyAudio()
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"You said: {query}\n")
speak(f"you said{query}")
except Exception as e:
# print(e)
print("Say that again please, I'm not able to recognize...")
speak("Say that again please, I'm not able to recognize")
return "None"
return query
def alarm_command():
recogniser = sr.Recognizer()
with sr.Microphone() as source:
print("Listening: ")
audio = recogniser.listen(source)
command = ""
try:
command = recogniser.recognize_google(audio)
print(command)
except Exception:
print("Sorry didn't get that, could you please repeat?")
return command
if __name__ == "__main__":
greetMe()
while True:
query = getCommands().lower()
if 'wikipedia' in query:
speak("Searching Wikipedia...")
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=1)
speak("According to wekipedia")
print(results)
speak(results)
elif 'hello' in query:
speak("Hello how may I help you")
elif 'hi' in query:
speak("Hi how may I help you")
elif 'hey' in query:
speak("Hey how may I help you")
elif 'hey there' in query:
speak("Hello how may I help you")
elif 'whats up' in query:
speak("Nothing much you tell?")
elif 'bye' in query:
speak("Good bye and thank you")
break
elif 'who created you' in query:
speak("Akshat Srivastava created me")
elif 'open youtube' in query:
speak("Opening YouTube")
webbrowser.open("youtube.com")
elif 'open google' in query:
speak("Opening Google")
webbrowser.open("google.com")
elif 'open wikipedia' in query:
speak("Opening Wikipedia")
webbrowser.open("wikipedia.com")
elif 'open linkedin' in query:
speak("Opening LinkedIn")
webbrowser.open(
"https://www.linkedin.com/in/akshat-srivastava-4812271a9/")
elif 'open github' in query:
speak("Opening Github")
webbrowser.open("https://github.com/akshat-fsociety")
elif 'who are you' in query:
speak(
"My name is Heisenberg, I'm the virtual assistant of Akshat Srivastava who created me")
elif 'what is your name' in query:
speak(
"My name is Heisenberg, I'm the virtual assistant of Akshat Srivastava who created me")
elif 'why is your name heisenberg' in query:
speak("First tell me what is your name only first name?")
name = getCommands().lower()
speak(f"why is your name{name}...")
speak("Just kidding, If you want to know the reason for my name you have to ask Akshat Srivastava who created me hahahahah ")
elif 'why heisenberg' in query:
speak("First tell me what is your name only first name?")
name = getCommands().lower()
speak(f"why is your name{name}...")
speak("Just kidding, If you want to know the reason for my name you have to ask Akshat Srivastava who created me hahahahah ")
elif 'the time' in query:
strTime = datetime.datetime.now().strftime(
"%H hours %M minutes and %S seconds")
print(strTime)
speak(f"Sir, The time is{strTime}")
elif "what is the day" in query:
day = datetime.datetime.now().strftime("%A")
speak(f"The day today is {day} ")
elif "what is the date" in query:
date = datetime.datetime.now().strftime("%A,%d %B, %Y")
speak("The date today is " + date)
elif "joke" in query:
joke = jokes_feature.joke_choice()
speak(joke)
elif "set alarm" or "set a alarm" or "set an alarm" in query:
speak("What hour do you want the alarm to be at: ")
alarm_hour = alarm_command()
speak("What minute do you want the alarm to be: ")
alarm_minute = alarm_command()
speak("Am or Pm")
am_pm = alarm_command()
speak("What message do you want to recieve: ")
message = alarm_command()
try:
alarm_feature.start_alarm(
alarm_hour, alarm_minute, am_pm, message, speak)
except Exception as e:
print(f"Error: {e}")
elif "search map" in query:
location = query.replace("search", "")
location = query.replace("map", "")
webbrowser.open_new(
f"https://www.google.com/maps/place/{location}")
speak(f"Here is what I found for {location} on Google Maps")