-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSMART_AI.py
171 lines (138 loc) · 4.6 KB
/
SMART_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
#All imported files can be install using the pip command
import pyttsx3
import datetime
import speech_recognition as sr
import wikipedia
import smtplib
import webbrowser as wb
import os
import pyautogui as pgui
import psutil
import pyjokes as pj
engine=pyttsx3.init()
def speak(audio):
engine.say(audio)
engine.runAndWait()
def time():
Time=datetime.datetime.now().strftime("%H:%M:%S") #I -> In 12 hrs clock #H -> for 24 hrs clock
speak("The current time is")
speak(Time)
def date():
day=int(datetime.datetime.now().day)
month=int(datetime.datetime.now().month)
year=int(datetime.datetime.now().year)
speak("The current date is")
speak(day)
speak(month)
speak(year)
def wishme():
speak("Welcome Back Sir!")
time()
date()
hour = datetime.datetime.now().hour
if(hour >= 5 and hour <= 12):
speak("Good Morning sir")
elif(hour >12 and hour<=17):
speak("Good AfterNoon sir")
elif(hour >17 and hour<=24):
speak("Good Evening Sir")
else:
speak("Good Night Sir")
speak("Rishi, at your service ..Tell me how can I help you .. Thank You!!")
def takeCommand():
r=sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source, duration=2)
print("Listining...")
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)
speak("Please speak it again .... Audio was not clear")
return "None"
return query
def takeScreenshot():
ss=pgui.screenshot()
ss.save("C:\\Users\\acer\\Desktop\\Project\\AI_Jarvis\\ss.png")
def jokes():
speak(pj.get_joke())
def cpu():
usage = str(psutil.cpu_percent())
speak("CPU is at"+ usage)
battery = psutil.sensors_battery()
speak("Battery is at")
speak(battery.percent)
def sendEmail(to,content):
server = smtplib.SMTP("smtp.gmail.com",587)
server.ehlo()
server.starttls()
server.login('[email protected]','***********')
server.sendmail('[email protected]',to,content)
server.close()
#speak("This is JARVIS \n Hello Rishi!")
#wishme()
#takeCommand()
if __name__ == "__main__":
wishme()
while True:
query=takeCommand().lower()
if 'time' in query:
time()
elif 'date' in query:
date()
elif "offline" in query:
speak("Rishi sighning off!!")
quit()
elif 'logout' in query:
os.system("shutdown -1")
elif 'shutdown' in query:
os.system('shutdown /s /t 1')
elif 'restart' in query:
os.system('shutdown /r /t 1')
elif 'play song' in query:
musicdir = 'C:\\Users\\Hp\\Music'
song=os.listdir(musicdir)
os.startfile(os.path.join(musicdir,song[0]))
elif 'remember that' in query:
speak("What should I remember")
data = takeCommand()
speak("You said me to remember"+ data)
remember = open('data.txt','w')
remember.write(data)
remember.close()
elif 'do you know anything' in query:
remember = open('data.txt','r')
speak("You said to remember that" + remember.raed())
elif 'search in chrome' in query:
speak("What should I search")
chromepath = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
search = takeCommand().lower()
wb.get(chromepath).open_new_tab(search+'.com')
elif "wikipedia" in query:
speak("Searching...")
query=query.replace("wikipedia","")
result=wikipedia.summary(query,sentences=2)
print(result)
speak(result)
elif 'screenshot' in query:
takeScreenshot()
speak("Done!")
elif 'cpu' in query:
cpu()
elif 'joke' in query:
jokes()
elif 'send email' in query:
try:
speak("What are the contents?")
content = takeCommand()
print(content)
to = '[email protected]'
sendEmail(to,content)
speak("Email sent successfully!")
except Exception as e:
print(e)
speak("Unable to send the email")