-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathalpha2.0.py
311 lines (262 loc) · 11.3 KB
/
alpha2.0.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
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
#improyting all the required modules
import speech_recognition as sr
import pyttsx3 as tt
import datetime as date
import shutil
import smtplib
import wikipedia as wiki
import os
import webbrowser as wbb
import pywhatkit as pw
import random
import wolframalpha as wo
import psutil
import time
from selenium.webdriver.common.keys import Keys
from selenium import webdriver as wb
from pynput.mouse import Button, Controller
import datetime
import subprocess
from pygame import mixer
#initilizing the required modules
mouse = Controller()
en = tt.init()
vo = en.getProperty('voices')
en.setProperty('voice', vo[3].id)
en.setProperty('rate', 160)
go = 'https://www.google.com'
yt = 'https://www.youtube.com'
insta = 'https://www.instagram.com'
wp = 'https://web.whatsapp.com/'
woappid = '*****YOUR WOLFRAMALPHA API KEY HERE*****'
#defining the required funcitons
def speak(audio):#used to convert the text to audio
en.say(audio)
en.runAndWait()
def take_command():#convert the audio to text
try:
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
print('listerning....')
audio = r.listen(source)
text = r.recognize_google(audio)
print('you said: ' + text)
return (text.lower())
except:
print('unable to recognize voice')
return 'sr030'
def get_sysinfo():#used to get the system cpu usage
info = []
cpufreq = psutil.cpu_freq()
info.append(f"Current Frequency of the CPU is: {cpufreq.current:.2f} Megahertz")
info.append("CPU Usage Per Core:")
for i, percentage in enumerate(psutil.cpu_percent(percpu=True, interval=1)):
info.append(f"Core {i}: {percentage}%")
info.append(f"Total CPU Usage: {psutil.cpu_percent()}%")
return info
def browser(site):#used to open the browse and search in google
while True:
if ('google' in site):
speak('openning google')
driver = wb.Chrome("*****CHROME DRIVER PATH****")
driver.get(go)
time.sleep(2)
speak('what do you want to search sir..')
search = take_command()
if 'sr030' not in search:
bar = driver.find_element_by_name('q')
bar.send_keys(search, Keys.ENTER)
while True:
print('...........__________.............')
speak('do you what to exit')
exit = take_command()
if 'sr030' not in exit:
if('down' in exit) or ('scroll down' in exit):
for i in range(5):
mouse.scroll(0, -1)
time.sleep(0.5)
elif('up' in exit) or ('scroll up' in exit):
for i in range(5):
mouse.scroll(0, 1)
time.sleep(0.5)
if ('yes' in exit) or ('of course' in exit) or ('close' in exit) or ('exit' in exit):
speak('closing browser..')
driver.close()
return 'exit'
else:
speak('hmm')
continue
else:
speak('try again')
driver.close()
continue
elif 'exit' in site:
print('definition loop')
return 'exit'
else:
speak('could not recognize, try again')
return
def wish_me():
os.startfile('C:\\Program Files\\Rainmeter\\Rainmeter.exe')
speak('awaking system protocols')
speak('checking network protocols')
speak('getting system information , cpu usage..')
info = get_sysinfo()
for i in info:
speak(i)
speak('system is in optimal condition')
hu = int(date.datetime.now().hour)
if(hu > 0 and hu < 12):
speak('Good Morning sir!')
elif(hu > 12 and hu < 18):
speak('Good Afternoon sir!')
else:
speak('Good evening sir!')
speak('i am your personal Assistant, Draster 2 point o')
speak('How can i help you sir?')
def send_email(to, content):
server = smtplib.SMTP('smtp.gmail.com',587)
server.ehlo()
server.starttls()
server.login('****YOUR MAIL ID****','****YOUR MAIL PASSWORD****')
server.sendmail('****YOUR MAIL ID****',to,content)
server.close()
wish_me()
#program starts here
if __name__ =='__main__':
lambda : os.system('cls')# clearing the terminal
mrun = True
while mrun:
task = take_command().lower()#getting the task from the user in voice form
print(task)
if 'wikipedia' in task: #wikipedia searches
speak('analysing your command..')
speak('Searching Wikipedia...')
info = task.replace('wikipedia', '')
try :
res = wiki.summary(info, 3)
speak('According to wikipedia..')
print(res)
speak(res)
except:
speak('not found in wikipedia , searching on google')
speak('these are the results found on google')
pw.search(info)
elif 'send an email to me' in task:
speak('analysing your command..')
try:
speak('What should I send ')
content = take_command()
to = '****YOUR MAIL ID****'
speak('sending email to '+ to)
send_email(to, content)
speak('email has been sent succesfully sir..')
except Exception as e:
print(e)
speak('i am not able to send this email')
elif 'send an email' in task: #send mail to the sepcified emali in the termianl
speak('analysing your command..')
try:
speak('whom should i send')
to = input('enter the email :')
print(to)
speak('what should i send')
content = take_command()
erun = True
while erun:
speak('confirmation needed')
confo = take_command()
if ('send it' in confo) or ('yes' in confo) or ('do it' in confo):
send_email(to, content)
speak('email sent succesfully..')
print('email sent succesfully..')
erun = False
elif ('don\'t send' in confo) or ('wait' in confo) or ('no' in confo):
speak('as your wish sir, cancelling the email')
erun = False
else:
speak('could not recognize , try again')
continue
except:
speak('i am not able to send this email, please try again')
elif 'open browser' in task:
speak('analysing your command..')
site = speak('which site do you want to open?')
run = True
while run:
site = take_command()
print(site)
speak('just a minute sir')
if 'sr030' not in site:
state = browser(site)
if ('exit' in state) or 'close' in state:
run = False
else:
speak('try again')
continue
elif "open youtube" in task: #opens youtube and play the specified sond, try sepaking open youtube and play the song needed
speak('analysing your command..')
speak('openning youtube..\n')
if 'play' in task:
speak('just a minute sir..')
song = task.replace('open','')
song = task.replace('youtube', '')
sond = task.replace('and','')
song = task.replace('play','')
pw.playonyt(song)
else:
wbb.open('youtube.com')
elif 'open google' in task: #open google
speak('analysing your command..')
speak('hear you go to google')
wbb.open('google.com')
elif 'open instagram' in task: #open instagram
speak('analysing your command..')
speak('openning insta')
wbb.open('instagram.com')
elif 'exit' in task: # to exit the loop
speak('Thanks for giving me your time')
speak('see you later')
subprocess.call(['taskkill','/F','/IM','Rainmeter.exe'])
mrun = False
elif 'song' in task or ('music' in task) or('on pc' in task) or ('in pc' in task): #to play a random song from the specified folder
speak('analysing your command..')
i = random.randint(1,'***number of songs +1')
speak('playin a song on pc')
path = "****folder path containing songs"
song_list = os.listdir(path)
os.startfile(os.path.join(path, song_list[i]))
elif 'time' in task: # to know the time
time = datetime.datetime.now().strftime('%I %M %p')
print("the current time is ",time)
speak("the current time is " + time)
elif ('do you know tamil' in task):
speak('enaku tamil theriyathu')
elif ('open notepad' in task) or ('start notepad' in task): #open notepad
speak('opening notepad')
os.startfile('C:\\Windows\\system32\\notepad.exe')
elif ('close notepad' in task) or ( 'exit notepad' in task): #close notepad
speak('terminating notepad')
subprocess.call(['taskkill','/F','/IM','notepad.exe'])
elif ('open paint' in task) or ('open mspaint' in task) or ('start paint' in task): #open paint
speak('opening microsoft paint')
os.startfile('C:\\Windows\\system32\\mspaint.exe')
elif ('close paint' in task) or ('terminate paint' in task) or ('exit paint' in task): #closepaint
speak('terminating microsoft paint')
subprocess.call(['taskkill','/F','/IM','mspaint.exe'])
elif 'who are you' in task:
speak('i am draster , i am your personal assestant . i help you playing youtube videos, musics, getting informations , google searches, excetra')
elif ('what ' in task) or('who' in task) or ('how' in task) or ('when' in task) or ('where' in task) or ('why' in task) or ('tell' in task): # to get informations
speak('analysing your command..')
try:
client = wo.Client(woappid)
res = client.query(task)
ans = next(res.results).text
print(ans)
speak(ans)
except:
speak('these are the results found on google')
pw.search(task)
else:
print('.....')