-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjarvis.py
More file actions
207 lines (164 loc) · 5.5 KB
/
jarvis.py
File metadata and controls
207 lines (164 loc) · 5.5 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import pyttsx3
import datetime
import speech_recognition as sr
import wikipedia
import smtplib
import webbrowser as wb
import os
import pyautogui #for the screenchot features
import psutil # for cpu usage and battery info
import pyjokes
name="roshan"
engine = pyttsx3.init()
# voices=engine.getProperty('voices')
# print(voices[1].id)
# engine.setProperty('voice',voices[0].id)
#using the function
def speaking(audio):
engine.say(audio)
engine.runAndWait()
#audiotaking=input('Please tye what you want to say :-\n')
#speaking(audiotaking)
#adding thetime function
def time():
Time= datetime.datetime.now().strftime("%I%M%S")
speaking("the current time is")
speaking(Time)
#time()
#adding the date function
def date():
year = int(datetime.datetime.now().year)
month = int(datetime.datetime.now().month)
day = int(datetime.datetime.now().day)
speaking("the current date is")
speaking(year)
speaking(month)
speaking(day)
#date() #calling the function
#Greeting function telling date and time
def wishme():
hour=datetime.datetime.now().hour
if hour>=6 and hour<12:
speaking("Good morning" + name)
elif hour>=12 and hour<18:
speaking("Good afternoon" + name)
elif hour>=18 and hour<24:
speaking("Good evening" + name)
else:
speaking("Good noght" + name)
speaking("Hello" + name + "Welcome to our world")
#speaking("the current time is")
time()
#speaking("The current date is")
date()
speaking("I am always at your service. How may i Assist you sir?")
#wishme()
#taking command from the user
def takeCommand():
r=sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing..")
query = r.recognize_google(audio, language='en-in')
print(query)
except Exception as e:
print(e)
speaking("will you say that again")
return "None"
return query
#takeCommand()
#send email function
def sendEmail(to,content):
server = smtplib.SmTP('smtp.gmail.com',587)
server.ehlo()
server.starttls()
server.login('abc@gmail.com','123password')
server.sendmail('abc@gmail.com',to,content)
server.close() #enter your gmail account
#taking the screenshot
def screenshot():
img = pyautogui.screenshot()
img.save('') #give the path where to store the file
#device usage
def cpu():
usage = str(psutil.cpu_percent()) #information about the cpu
speaking("CPU usage is "+ usage)
battery_info = psutil.sensors_battery()
speaking("Your Battery status is at"+ battery_info.percent)
#for jokes telling
def jokes():
speaking(pyjokes.get_jokes) #fetch jokes from the library
if __name__ == "__main__":
wishme()
while True:
query = takeCommand().lower()
if 'time' in query:
time()
elif 'date' in query:
date()
#using the wikipedia for searching
elif 'wikipedia' in query:
speaking('Searching...')
query = query.replace('wikipedia','')
result = wikipedia.summary(query,sentences=2)
print(result)
speaking(result)
#sending mail
elif 'send email' in query:
try:
speaking("what should i send?")
content = takeCommand()
to = 'xyz@gmail.com'
sendEmail(to,content)
speaking("Email has benn sent well")
speaking(content)
except Exception e:
print(e)
speaking("Unable to send email")
elif 'search in chrome' in query:
speaking("What should i search sir?")
chromepath = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
search = takeCommand().lower()
we.get(chromepath).open_new_tab(search , '.com')
#os applications
elif 'logout' in query:
os.system("shutdown -l")
elif 'shutdown' in query:
os.system("shutdown /s /t 1")
elif 'restart' in query:
os.system("shutdown /r /t 1")
#playing songs from the system
elif 'play songs' in query:
songs_dir = 'D:\\' #some location of the songs
songs = os.listdir(songs_dir)
os.startfile(os.path.join(songs_dir,songs[0]))
#remember the function whatever we say
elif 'remember that' in query:
speaking("What should i remember")
remember_data = takeCommand()
speaking("You said me to remember" + remember_data)
remember = open('data.txt','w')
remember.write(remember_data)
remember.close()
#reading the data from the file
elif 'do you know anything' in query:
remember = open('data.txt','r')
speaking("You said me to remember that" + remember.read)
#taking screenshot
elif 'screenshot' in query:
screenshot()
speaking("Screenshot have been taken")
#device information
elif 'cpu' in query:
cpu()
#jokes telling
elif 'jokes' in query:
jokes()
elif 'offline' in query:
quit()
rate = engine.getProperty('rate') # getting details of current speaking rate
print (rate) #printing current voice rate
engine.setProperty('rate', 200) # setting up new voice rate