-
Notifications
You must be signed in to change notification settings - Fork 0
/
jarvis.py
174 lines (116 loc) · 5.22 KB
/
jarvis.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
def AI():
import pyttsx3
from datetime import datetime
import speech_recognition as sr
import wikipedia
import webbrowser
import os
import smtplib
import random as rd
memes_list = ['I gotcha in my sight, leave the memes and try to save your life.', 'Hanging out with some friends is cool but coding 100 lines and getting no error while running is Heaven!!!!!!!!!!',
'BedWars: Destroy the Bed,,,,,,,,,,,,,,, ShadowApples: I need to sleep and mod this',
'Diamond: I am the Best,,,,,,,,,,,,,,,,,,,,,,,, Netherite: Are you sure about that.',
'Dream: Let me speedrun minecraft real quick,,,,,,,,,,,,,,,,,,,,, Me: Lemme Speadrun my homework on the last 10 mins of the due']
webbrowser.register('chrome',
None,
webbrowser.BackgroundBrowser("C://Program Files (x86)//Google//Chrome//Application//chrome.exe"))
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty(voices, voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishMe():
hour = int(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 Your Assistant. How may I help you !")
def takeCommand():
# Input from microphone and returns string output
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-uk')
print(f"User Said: {query}\n")
except Exception:
# print(e)
print("Say that again...")
return "None"
return query
def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('email', 'password')
server.sendmail('sender email', to, content)
server.close()
if __name__ == '__main__':
wishMe()
while True:
query = takeCommand().lower()
#Logic for executing
if 'wikipedia' in query:
speak('Searching Wikipedia........')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=3)
speak("According to wikipedia")
print(results)
speak(results)
elif 'open youtube' in query:
webbrowser.get('chrome').open('youtube.com')
elif 'open google' in query:
webbrowser.get('chrome').open('google.com')
elif 'open school meet' in query:
webbrowser.get('chrome').open('https://meet.google.com/?hs=197&pli=1&authuser=1')
elif 'open chat' in query:
webbrowser.get('chrome').open('web.whatsapp.com')
elif 'open media' in query:
webbrowser.get('chrome').open('github.com')
elif 'open my website' in query:
webbrowser.get('chrome').open('https://tkn6qbyjao3lqsopxzkhha-on.drv.tw/School%20Projects/main.html')
elif 'play surah' in query:
music_dir = "C:\\Users\\Ahmer Khan\\Downloads\\Test_Surah"
surah = os.listdir(music_dir)
print(surah)
os.startfile(os.path.join(music_dir, surah[0]))
elif 'the time' in query:
strTime = datetime.now().strftime("%H;%M;%S")
speak(f"The time is {strTime}\n")
elif 'open code' in query:
code_path = "C:\\Users\\Ahmer Khan\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Visual Studio Code\\Visual Studio Code.lnk"
os.startfile(code_path)
elif 'open cmd' in query:
cmd_path = "C:\\Windows\\System32\\cmd.exe"
os.startfile(cmd_path)
elif 'email' in query:
try:
speak('What should I say')
content = takeCommand()
to = "saadyarkhan11@gmail.com"
sendEmail(to, content)
speak("Email has been sent")
except Exception as e:
print(e)
speak('Not sent bhai')
elif "open classroom" in query:
webbrowser.get('chrome').open('classroom.google.com/u/1/h')
elif 'who are you' in query:
speak('I am better than google')
speak('Thats it!')
elif 'start' in query:
speak('I am started, BRUH!')
elif 'meme' in query:
speak(rd.choice(memes_list))
elif 'quit' in query:
speak('Hope you are Satisfied')
speak('Bye See you soon')
quit()
AI()