-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathJARVIS_AI.py
203 lines (157 loc) · 5.94 KB
/
JARVIS_AI.py
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
import pyttsx3
import speech_recognition as sr
import datetime
import wikipedia
import webbrowser as wb
import os
import smtplib
import requests
from pprint import pprint
from selenium import webdriver
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
#print(voices[1].id)
engine.setProperty('voice',voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishMe():
speak("Welcome back sir")
hour = int(datetime.datetime.now().hour)
print(hour)
year = int(datetime.datetime.now().year)
month = int(datetime.datetime.now().month)
date = int(datetime.datetime.now().day)
Time = datetime.datetime.now().strftime("%I:%M:%S")
print(Time)
print(date)
print(month)
print(year)
speak("the current Time is")
speak(Time)
speak("the current Date is")
speak(date)
speak(month)
speak(year)
if hour>=6 and hour<12:
speak("Good Morning AK47!")
elif hour>=12 and hour<18:
speak("Good Afternoon AK47!")
elif hour>=18 and hour<24:
speak("Good Evening AK47!")
else:
speak("Good Night AK47!")
speak("Jarvis at your Service. Please tell me how can I help You ")
#wishMe()
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(f"AK47 Said:{query}\n")
except Exception as e:
print(e)
print("Say that again Please...")
speak("Say that again Please...")
return "None"
return query
def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('[email protected]', 'Password')
server.sendmail('[email protected]', to, content)
server.close()
def lighton():
driver = webdriver.Chrome('C:/Users/Username/Downloads/chromedriver.exe')add the location of the chrome Drivers
driver.get("https://Add here.000webhostapp.com/main.html")Add the webhost name
elem1 = driver.find_element_by_id("S1off")
elem1.click()
def lightoff():
driver = webdriver.Chrome('C:/Users/HACKER47/Downloads/chromedriver.exe')
driver.get("https://Add here.000webhostapp.com/main.html")Add the webhost name
elem1 = driver.find_element_by_id("S1on")
elem1.click()
if __name__ == "__main__":
wishMe()
while True:
query = takeCommand().lower()
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)
elif 'search in chrome' in query:
speak("what should i search?")
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'Add the Location of the chrome browser
r = sr.Recognizer()
with sr.Microphone() as source:
print('say something!')
audio = r.listen(source)
print("done")
try:
text = r.recognize_google(audio)
print('google think you said:\n' +text +'.com')
wb.get(chrome_path).open(text+'.com')
except Exception as e:
print(e)
elif 'how is the weather' and 'weather' in query:
url = 'https://api.openweathermap.org/'#Open api link here
res = requests.get(url)
data = res.json()
weather = data['weather'] [0] ['main']
temp = data['main']['temp']
wind_speed = data['wind']['speed']
latitude = data['coord']['lat']
longitude = data['coord']['lon']
description = data['weather'][0]['description']
speak('Temperature : {} degree celcius'.format(temp))
print('Wind Speed : {} m/s'.format(wind_speed))
print('Latitude : {}'.format(latitude))
print('Longitude : {}'.format(longitude))
print('Description : {}'.format(description))
print('weather is: {} '.format(weather))
speak('weather is : {} '.format(weather))
elif 'the time' in query:
strTime = datetime.datetime.now().strftime("%I:%M:%S")
speak(f"Sir, the time is {strTime}")
elif 'the date' in query:
year = int(datetime.datetime.now().year)
month = int(datetime.datetime.now().month)
date = int(datetime.datetime.now().day)
speak("the current Date is")
speak(date)
speak(month)
speak(year)
elif 'email to harry' and 'send email' in query:
try:
speak("What should I say?")
content = takeCommand()
to = "[email protected]"
sendEmail(to, content)
speak("Email has been sent!")
except Exception as e:
print(e)
speak("Sorry my friend . I am not able to send this email")
elif 'open code' in query:
codePath = "C:\\Users\\user account\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"#ADD THE PATH OF THE PROGEM HERE
os.startfile(codePath)
elif 'open' in query:
os.system('explorer C://{}'.format(query.replace('Open','')))
elif 'turn on lights' in query:
speak("OK,sir turning on the Lights")
lighton()
speak("Lights are on")
elif 'turn off lights' in query:
speak("OK,sir turning off the Lights")
lightoff()
speak("Lights are off")
elif 'go offline' in query:
speak("ok sir shutting down the system")
quit()