-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjarvis.py
More file actions
47 lines (38 loc) · 1.07 KB
/
jarvis.py
File metadata and controls
47 lines (38 loc) · 1.07 KB
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
import pyttsx3
import datetime
import speech_recognition as Sr
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
# print(voices[1].id)
engine.setProperty('voice', voices[1].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishMe():
hour = int(datetime.datetime.now().hour)
if 0 <= hour < 12:
speak("Good Morning Sir!")
elif 12 <= hour < 18:
speak("Good Afternoon Sir!")
else:
speak("Good Evening Sir!")
speak("Jarvis ready for Command ,Sir!!")
def takeCommand():
# it takes microphone input from the user and returns string output
r = Sr.Recognizer()
with Sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognising...")
query = r.recognize_google(audio, language='en-in')
print("User Said:", query)
except Exception as e:
print(e)
print("Say that Again Sir...")
return "None"
return query
if __name__ == '__main__':
wishMe()
takeCommand()