-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjarvis_github.py
More file actions
111 lines (92 loc) · 2.95 KB
/
Copy pathjarvis_github.py
File metadata and controls
111 lines (92 loc) · 2.95 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import pyttsx3
import speech_recognition as sr
import wikipedia,webbrowser,os
import datetime
import smtplib
email = {
'User1':'[email protected]',
'User2': '[email protected]',
'User3': '[email protected]'
}
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voice')
engine.setProperty('voice',voices[0])
engine. setProperty("rate", 200)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishMe():
hour = int(datetime.datetime.now().hour)
if(hour<12):
speak("Good Morning Sir")
elif(hour<=17):
speak("Good afternoon Sir")
else:
speak("Good evening Sir")
speak("I am Jarvis, How can I help you")
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening now...")
r.pause_threshold =1
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
try:
#print("Recognizing ... ")
query = r.recognize_google(audio,language='en-in')
print(f"User said:{query}\n")
except Exception as e:
print("Please say again")
return ("None")
return query
def sendEmail(mailto, content):
server = smtplib.SMTP('smtp.gmail.com',587)
server.ehlo()
server.starttls()
server.login('[email protected]','your-password')
server.sendmail('[email protected]',mailto,content)
server.close()
def main():
speak("Hello")
query = takeCommand().lower()
if 'wikipedia' in query:
speak("Searching Wikipedia")
query=query.replace('wikipedia','')
result=wikipedia.summary(query,sentences=2)
print(result)
speak(result)
elif 'google' in query or 'chrome' in query:
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
url = 'https://google.com/'
webbrowser.get(chrome_path).open(url)
elif 'youtube' in query:
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
url = 'https://youtube.com/'
webbrowser.get(chrome_path).open(url)
elif 'time' in query:
strTime=datetime.datetime.now().strftime("%I:%M")
if(datetime.datetime.now().hour >12):
strTime+="PM"
else:
strTime+="AM"
speak(strTime)
elif 'email' in query:
if 'rahul' in query:
mailto=email['rahul']
elif 'papa' in query:
mailto=email['papa']
elif 'mummy' in query:
mailto=email['mummy']
try:
speak("What should be the subject")
subject = takeCommand();
speak("What should be the message")
content = takeCommand();
content = 'Subject: {}\n\n{}'.format(subject, content)
sendEmail(mailto, content)
speak("Email has been sent")
except Exception as e:
print(e)
speak("Please try again")
if __name__ == "__main__":
main()