-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMAX.py
236 lines (215 loc) · 7.8 KB
/
MAX.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
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
#Created by Nalin Agrawal
import pyttsx3
import datetime
import speech_recognition as sr
import wikipedia
import smtplib
import webbrowser,requests
import os
import pyautogui
import psutil
import pyjokes
import cv2,time
engine = pyttsx3.init()
def speech(audio):
engine.say(audio)
print(audio)
engine.runAndWait()
def takeInstructions():
rec=sr.Recognizer()
with sr.Microphone() as source:
print("Listining...")
audio = rec.listen(source)
try:
print("Recognising...")
Instruction = rec.recognize_google(audio, language='en-in')
print(Instruction)
except Exception as exeptions:
print(exeptions)
speech("Say that again please...")
return "None"
return Instruction
def greatings():
speech("Hello")
speech("I am MAX, your personal desktop companion")
def time():
TimeRightNow=datetime.datetime.now().strftime("%I:%M:%S")
hour=0
hour=datetime.datetime.now().hour
if hour>=6 and hour<12:
phase="morning"
elif hour>=12 and hour<18:
phase="afternoon"
elif hour>=18 and hour<=24:
phase="eveining"
else:
phase="night"
speech("Its " + TimeRightNow+" of "+phase)
def date():
YYYY=int(datetime.datetime.now().year)
MM=int(datetime.datetime.now().month)
DD=int(datetime.datetime.now().day)
speech("current date is "+str(DD)+" "+str(MM)+" "+str(YYYY))
def CPUstatus():
usage=str(psutil.cpu_percent())
speech('Current CPU usage is at '+usage + "%")
battery = psutil.sensors_battery()
speech("Battery remaining is " + str(battery.percent)+"%")
hdd = psutil.disk_usage('/')
hddusage=(hdd.used/hdd.total)*100
hddusage=round(hddusage,2)
speech("Storage used in C Drive is "+str(hddusage)+"%")
frequency=psutil.cpu_freq()
speech("Current frequency of CPU is "+str(frequency.current)+" Megha Hetz")
RAMused=psutil.virtual_memory().percent
speech("RAM used is "+str(RAMused)+"%")
def jokes():
speech(pyjokes.get_joke())
def screenshot():
img = pyautogui.screenshot()
speech("By what name should I save it?")
ans=takeInstructions()
#Replace FolderPath with the path of folder where you want to save your screenshots in your computer
ans="FolderPath"+ans+".png"
img.save(ans)
speech("Screenshot taken")
def camera():
speech("Press space to take image and escape to stop Camera")
Camera = cv2.VideoCapture(0)
cv2.namedWindow("Camera")
img_counter = 0
while True:
ret, frame = Camera.read()
if not ret:
print("failed to grab frame")
break
cv2.imshow("Camera", frame)
k = cv2.waitKey(1)
if k%256 == 27:
speech("closing camera")
break
elif k%256 == 32:
img_name = "camera{}.png".format(img_counter)
#Replace CameraPath with the path of the folder where you want to save your photos taken by camera
path="CameraPath"
cv2.imwrite(os.path.join(path , img_name), frame)
cv2.imwrite(img_name, frame)
speech("{} image taken".format(img_name))
img_counter += 1
Camera.release()
cv2.destroyAllWindows()
def Wikipedia(query):
speech("Searching...")
query=query.replace("wikipedia","")
result = wikipedia.summary(query,sentences=2)
speech(result)
def OpenWebsite():
speech("Which website should i open?")
# Replace ChromePath with path of chrome.exe in your computer in the line below where it is written
path='ChromePath %s'
website=takeInstructions().lower()
webbrowser.get(path).open_new_tab(website+'.com')
def GoogleSearch():
speech("What should I search?")
SearchData=takeInstructions()
webbrowser.open(SearchData)
speech("Here is the search result")
def Songs():
#Replace MusicPath with the path of the folder where you want to save the music that you want it to play
songs_dir='MusicPath'
playsongs=os.listdir(songs_dir)
os.startfile(os.path.join(songs_dir,playsongs[0]))
def Remember():
speech("What should I remember?")
Information=takeInstructions()
speech('you said me to remember that '+Information)
rem = open('data.txt','w')
rem.write(Information)
rem.close()
def Knowing():
remember=open('data.txt','r')
speech("you said me to remember that"+remember.read())
def Weather():
speech("Which city's weather you want to know?")
city=takeInstructions().lower()
# Replace YourAPIkey by your API key in line below which you get after signing in in https://openweathermap.org/
url="http://api.openweathermap.org/data/2.5/weather?q={}&appid=YourAPIkey".format(city)
res=requests.get(url)
data=res.json()
climate=data["weather"][0]["description"]
speech("Todays climate is "+climate)
temp=data['main']['temp']
temp=round(temp-273.15,2)
speech("Average Temperature is "+str(temp)+" Degree Celcius")
maxtemp=data['main']['temp_max']
maxtemp=round(maxtemp-273.15,2)
speech("Maximum temperature is "+ str(maxtemp)+" Degree Celcius")
mintemp=data['main']['temp_min']
mintemp=round(mintemp-273.15,2)
speech("Minimum temperature is "+ str(mintemp)+ " Degree Celcius")
wind=data["wind"]["speed"]
speech("WindSpeed is "+str(wind)+" meters per second")
humidity=data["main"]["humidity"]
speech("Humidity is "+str(humidity)+"%")
visibile=data["visibility"]
speech("Visibitity is "+str(visibile)+" meters")
cloud=data["clouds"]["all"]
speech("Its "+str(cloud)+" percent cloudy")
pressure=data['main']["pressure"]
speech("Air pressure is at "+ str(pressure)+"hpa")
def help():
speech("Here are the keywords that should be in your command for following work to be done")
speech("MY INTRODUCTION to repeat my introduction")
speech("TIME to get time")
speech("DATE to get date")
speech("CPU STATUS to get information about present condition of CPU")
speech("JOKE to listen a joke")
speech("SCREENSHOT to get screenshot")
speech("CAMERA to click photos of you in webcam")
speech("WIKIPEDIA to get do wikipedia search")
speech("OPEN WEBSITE to open website")
speech("SEARCH to do google search")
speech("SONG to start a song")
speech("REMENBER if you want me to remember something")
speech("KNOW if you want me to tell you what you have asked me to remember earlier")
speech("WEATHER to know a weather forcast")
speech(" and speak HELP to repeat these thing again")
if __name__=="__main__":
greatings()
speech("I am ready to take command")
speech("Say help to know all my features else continue to give command ")
while True:
query = takeInstructions().lower()
if 'my introduction' in query:
greatings()
elif 'time' in query:
time()
elif 'date' in query:
date()
elif 'cpu status' in query:
CPUstatus()
elif 'joke' in query:
jokes()
elif 'screenshot' in query:
screenshot()
elif 'camera' in query:
camera()
elif 'wikipedia' in query:
Wikipedia(query)
elif 'open website' in query:
OpenWebsite()
elif 'search' in query:
GoogleSearch()
elif 'song' in query:
Songs()
elif 'remember' in query:
Remember()
elif 'know' in query:
Knowing()
elif 'weather' in query:
Weather()
elif 'help' in query:
help()
elif 'offline' in query:
break
speech("Shutting Down. Have a nice day!")