-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjarvis.py
More file actions
75 lines (68 loc) · 2.38 KB
/
jarvis.py
File metadata and controls
75 lines (68 loc) · 2.38 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
import pyttsx3
import os
import datetime
import speech_recognition as sr
import wikipedia
import webbrowser
import smtplib
import time
class Jarvis:
"""docstring for Jarvis"""
def __init__(self):
self.active = True
self.contact_list = {'prabhat': 'prabhat.ghimire2@gmail.com', 'bikrant': 'vikrantabasyal@gmail.com'}
self.app_list = {'sublime' : 'subl', 'blender': 'blender', 'gimp':'gimp', 'firefox':'firefox','':''}
# window = sapi5, mac = nsss, linux = espeak
self.engine = pyttsx3.init('espeak')
self.voices = self.engine.getProperty('voices')
# print(voices)
# for voice of girl voices[1]
self.engine.setProperty('voice', self.voices[0])
def sendEmail(self, to, content):
'''send email'''
server = smtplib.SMTP('smtp.gmail.com',587)
server.ehlo()
server.starttls()
server.login('prabhu10612@gmail.com','Gulmi!512')
server.sendmail('prabhu10612@gmail.com', to, content)
server.close()
def speak(self, audio):
'''it speak the given sentence'''
if self.active :
self.engine.say(audio)
self.engine.runAndWait()
def wishme(self):
''' it take time and wish according to time'''
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12 :
print('good morning!')
self.speak('good morning!')
elif hour>=12 and hour<18 :
print('good aftrnoon!')
self.speak('good aftrnoon!')
else :
print('good evening!')
self.speak('good evening!')
print('I am jarvis, how can i help you')
self.speak('I am jarvis, how can i help you')
def takeCommand(self):
'''it takes microphone input from the user and return the string'''
r = sr.Recognizer()
with sr.Microphone() as source:
print('Listening...')
r.pause_threshold = 1
r.adjust_for_ambient_noise(source)
audio = r.record(source, duration=4)
try:
print('Recognizing...')
query = r.recognize_google(audio)
print(f' You said : {query}\n')
except Exception as e:
print(e)
print('say that again please')
return 'None'
# else:
# pass
# finally:
# pass
return query