-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinal jarvis.py
More file actions
90 lines (70 loc) · 2.67 KB
/
final jarvis.py
File metadata and controls
90 lines (70 loc) · 2.67 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
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
import pyttsx3
import datetime
import speech_recognition as sr
import wikipedia
import os
import webbrowser
import sys
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice',voices[1].id)
engine.setProperty('rate', 185)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishme():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("Good Morning")
elif hour>=12 and hour<=15:
speak("Good Afternoon")
else:
speak("Good Evening")
speak("Hey Buddy Whats Up How can I help you.")
def takecommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Please Wait....Calibrating Microphone")
r.adjust_for_ambient_noise(source,duration=5)
r.dynamic_energy_threshold = True
print("Now Listening....")
r.phrase_threshold = 0.8
audio = r.listen(source)
try:
print("Recognizing.....")
query = r.recognize_google(audio, language = 'en-in')
print("User said:",query)
except Exception as e:
print("SAY THAT AGAIN PLEASE...")
return "None"
return query
if __name__ == "__main__":
wishme()
while True:
query=takecommand().lower()
#print(query);
if ( query.find('hello')!=-1 or query.find('hey')!=-1 ) :
speak('Hey Buudy How can I help you')
elif ( query.find('time')!=-1) :
time=str(datetime.datetime.now().time())
time=time.replace(":"," ")
time=time[0:5]
speak("The time is "+time)
elif ( query.find('wikipedia')!=-1 or query.find('where')!=-1 or query.find('what')!=-1 ) :
query = query.replace("wikipedia"," ")
query = query.replace("what"," ")
results = wikipedia.summary(query,sentences=3)
print(results)
speak(results)
elif query.find('open youtube')!=-1:
webbrowser.get('windows-default').open('http://www.youtube.com')
elif query.find('youtube')!=-1:
query=query.replace("youtube"," ")
webbrowser.get('windows-default').open('https://www.youtube.com/results?search_query='+query)
elif query.find('open google')!=-1:
webbrowser.get('windows-default').open('http://www.google.com')
elif query.find('bye')!=-1:
speak('Bye Have a good Day Ahead')
sys.exit()
else:
webbrowser.get('windows-default').open("https://www.google.com/search?q="+query)