-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJarvis.py
More file actions
338 lines (280 loc) · 10.3 KB
/
Jarvis.py
File metadata and controls
338 lines (280 loc) · 10.3 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
from cgitb import reset
from time import sleep
from typing_extensions import Self
import pyttsx3 #pip install pyttsx3
import speech_recognition as sr #pip install speechRecognitionFR
import datetime
import wikipedia #pip install wikipedia
import webbrowser as wb
import os
import smtplib
import sys#pip install sys
import cv2
import pyjokes
import pyautogui#pip install pyautogui
from Translator import translategl
import self #pip install self
import typing_extensions #pip install typing-extensions
from selenium import webdriver #pip install selenium
import requests
from bs4 import BeautifulSoup #pip install bs4
import keyboard #pip install keyboard
import NewsRead
engine = pyttsx3.init()
voices = engine.getProperty('voices')
#print(voices[1].id)
engine.setProperty('voice', voices[0].id)
rate = engine.setProperty("rate",170)
chrome_path = "C:/Program Files/Google/Chrome/Application/chrome.exe %s"
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<18:
speak("Good Afternoon!")
else:
speak("Good Evening!")
speak("I am Jarvis Sir. Please tell me how may I help you")
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
r.energy_threshold = 300
audio = r.listen(source,0,4)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"User said: {query}\n")
except Exception as e:
print(e)
print("Say that again please...")
return "None"
return query
#Email
def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('youremail@gmail.com', 'your-password')
server.sendmail('youremail@gmail.com', to, content)
server.close()
#Jokes
def jokes():
my_jokes = pyjokes.get_joke('en', category='neutral')
print(my_jokes)
speak(my_jokes)
#web search commands
def open_chrome():
url = "https://www.google.co.in/"
wb.get(chrome_path).open(url)
#Alarm
def alarm(query):
timehere = open("Alarmtext.txt","a")
timehere.write(query)
timehere.close()
os.startfile("Alarm.py")
#Weather And Temperature
def temperature():
city = query.split("in", 1)
soup = BeautifulSoup(requests.get(f"https://google.com/search?q=weather+in+{city[1]}").text, "html.parser")
region = soup.find("span", class_="BNeawe tAd8D AP7Wnd")
temp = soup.find("div", class_="BNeawe iBp4i AP7Wnd")
day = soup.find("div", class_="BNeawe tAd8D AP7Wnd")
weather = day.text.split("m", 1)
temperature = temp.text.split("C", 1)
speak("Its Currently"+weather[1]+" and "+temperature[0]+"Celcius"+" in "+region.text)
print("Its Currently"+weather[1]+" and "+temperature[0]+"Celcius"+" in "+region.text)
#wikipedia search
if __name__ == "__main__":
wishMe()
while True:
# if 1:
query = takeCommand().lower()
# Logic for executing tasks based on query
if 'wikipedia' in query:
speak('Searching Wikipedia...')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=2)
speak("According to Wikipedia")
print(results)
speak(results)
#about hi job
elif 'how are you' in query:
speak("I am fine, and you")
print("I am fine, and you")
elif "who are you" in query:
speak("I am the personal assistant of darsh yadav")
elif "what is your name" in query:
speak("my name is jarvis")
#open on chrome
elif "open chrome" in query:
open_chrome()
elif "search" in query:
speak("what should I search")
search = takeCommand().lower()
wb.get(chrome_path).open_new_tab(search + ".com")
elif 'start anime' in query:
wb.get(chrome_path).open_new_tab("animixplay.to")
#open camera
elif "open camera" in query:
cap = cv2.VideoCapture(0)
while True:
ret, img = cap.read()
cv2.imshow('webcam', img)
k = cv2.waitKey(50)
if k==27:
break;
cap.release()
cv2.destroyAllWindows()
#song
if 'play music' in query:
speak("sir what song should I play")
song = takeCommand().lower()
wb.open(f'https://open.spotify.com/search/{song}')
sleep(5)
pyautogui.click(x=784, y=536)
speak('Playing' + song)
elif 'add this song to the playlist' in query:
speak("which song should i add?")
song1 = takeCommand().lower()
wb.open(f'https://open.spotify.com/search/{song1}')
sleep(13)
pyautogui.click(x=1844, y=343)
sleep(3)
pyautogui.click(x=1757, y=700)
sleep(3)
pyautogui.click(x=1431, y=333)
elif 'like this song' in query:
speak("which song should i like")
song2 = takeCommand().lower()
wb.open(f'https://open.spotify.com/search/{song2}')
sleep(10)
pyautogui.click(x=1736, y=343)
sleep(5)
speak("this is my favourite song too")
#translate command
elif "translate" in query:
from Translator import translategl
query = query.replace("jarvis","")
query = query.replace("translate","")
translategl(query)
#temperature
elif "weather" in query:
temperature()
#time
elif 'the time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"Sir, the time is {strTime}")
#Smart Home Automation
elif "activate the smart bulb" in query:
speak('opening the smart bulb')
keyboard.press_and_release('windows + s')
sleep(3)
keyboard.write('app: blue 5')
sleep(3)
keyboard.press('enter')
sleep(5)
pyautogui.click(x=1599, y=129)
sleep(45)
pyautogui.click(x=1687, y=213)
sleep(30)
pyautogui.click(x=405, y=326)
speak('started the bulb')
elif "close the bulb" in query:
sleep(5)
pyautogui.click(x=416, y=293)
speak("closed the bulb")
elif "change the colour" in query:
speak("changing the colour")
sleep(5)
pyautogui.click(x=300, y=368)
sleep(5)
pyautogui.click(x=915, y=480)
sleep(5)
pyautogui.scroll(-500)
sleep(5)
pyautogui.click(x=1079, y=834)
speak("changed the colour")
# elif "change brightness" in query:
# sleep(5)
# pyautogui.
#Youtube computer
elif "pause" in query:
pyautogui.press("k")
speak("Video paused")
elif "play" in query:
pyautogui.press("k")
speak("video played")
elif "Mute" in query:
pyautogui.press("m")
speak("Video muted")
elif "volume up" in query:
from keyboard import volumeup
speak("Turning volume up,Sir")
volumeup()
elif "volume down" in query:
from keyboard import volumedown
speak("Turning volume down,Sir")
volumedown()
#News Headline
elif "news" in query:
from NewsRead import latestnews
latestnews()
#alarm
elif "set an alarm" in query:
print("input time example:- 10 and 10 and 10")
speak("Set the time")
a = input("Please tell the time :- ")
alarm(a)
speak("Done,sir")
# apps
elif "open command prompt" in query:
os.system("start cmd")
elif 'open code' in query:
codePath = "C:\\Users\\ACER\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
os.startfile(codePath)
elif 'open epic game' in query:
gamePath = "C:\\Program Files (x86)\\Epic Games\\Launcher\\Portal\\Binaries\\Win32\\EpicGamesLauncher.exe"
os.startfile(gamePath)
elif 'open editor' in query:
editorPath = "C:\\Program Files\\Adobe\\Adobe Premiere Pro 2022\\Adobe Premiere Pro.exe"
os.startfile(editorPath)
elif 'open photoshop' in query:
photoshoppath = "C:\\Program Files (x86)\\Adobe Photoshop CS6\\Photoshop.exe"
os.startfile(photoshoppath)
elif 'open animate' in query:
animatepath = "C:\\Program Files\\Adobe\\Adobe Animate 2022\\Animate.exe"
os.startfile(animatepath)
elif 'open audacity' in query:
audacitypath = "D:\\Audacity\\Audacity.exe"
os.startfile(audacitypath)
elif 'open minecraft' in query:
minecraftpath = "C:\\minecraft\\Minecraft Launcher\\MinecraftLauncher.exe"
os.startfile(minecraftpath)
elif 'open fall guys' in query:
fallguyspath = "steam://rungameid//1097150"
os.startfile(fallguyspath)
elif 'open steam' in query:
steamPath = "C:\\Program Files (x86)\\Steam\\steam.exe"
os.startfile(steamPath)
elif 'email to darsh' in query:
try:
speak("What should I say?")
content = takeCommand()
to = "darshyadav1976@gmail.com"
sendEmail(to, content)
speak("Email has been sent!")
except Exception as e:
print(e)
speak("Sorry my friend dishu bhai. I am not able to send this email")
elif"joke" in query:
jokes()
elif "sleep" in query:
speak("thank you for your time, have a nice day")
sys.exit()
speak ("any thing else sir")