-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoice_Recgonization.py
1414 lines (1218 loc) · 53.7 KB
/
voice_Recgonization.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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import subprocess
import shutil
import time
from tkinter import *
from tkinter import filedialog
from openpyxl import Workbook
import docx
import pyttsx3
import datetime
import speech_recognition as sr
import wikipedia
import webbrowser
import requests
import random
import os
import smtplib
import psutil
import pyautogui
import keyboard
import cv2
try:
import pywhatkit as p
except:
# print("NO connection !!! Some functions may not work properly\n This program may terminate in few seconds")
time.sleep(3)
import pandas as pd
import math
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
from PyQt5 import QtGui
from PyQt5.QtCore import QTimer, QTime, QDate
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
# from PyQt5.uic import LoadUiType
from alexaUI import Ui_alexaUI
# from Tools.scripts import google
hour = int(datetime.datetime.now().hour)
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
# print(voices[1].id)
"""
open new tab = ctrl + t
close tab = ctrl + w
switch another tab on chrome = ctrl + tab
youtube theater mode = t
youtube Full screen mode = f
"""
engine.setProperty('voice', voices[1].id)
cnt1, cnt1whatsapp = 0,0
GMAIL_ID = 'YOUR_EMAIL_ADDRESS'
GMAIL_PSD = 'YOUR_PASSWORD'
news_api_key = "YOUR API KEY"
weather_api_key = "YOUR API KEY"
order=""
df = pd.read_excel("birthday.xlsx")
attempts,sleepcount,taskcount, commandcount,splitcommand,speak_frequency=0,0,0,0,0,0
timer = ""
def target():
if (not os.path.exists("Task.txt")):
f = open("Task.txt", "w+")
f.close()
speak("No task are assigned sir!!")
return
with open("Task.txt", "r") as f:
task = f.read()
if os.stat("Task.txt").st_size == 0:
speak("No task are assigned sir!!")
else:
speak("Todays tasks are as follows !!!")
speak(task)
speak("these were task assigned !!")
def speak(audio):
global speak_frequency
speak_frequency=1
# print(speak_frequency)
engine.say(audio)
engine.runAndWait()
speak_frequency = 0
def delete_file(filename):
file = open(filename, "r+")
file.truncate(0)
file.close()
def confirmation(msg):
f = open("confirm.txt", "w+")
f.write("Your Message : "+msg)
f.close()
webbrowser.open("confirm.txt")
def pick_aatachment():
speak("choose file that you want to send")
root = Tk()
root.title("file attachment")
root.geometry('300x300')
file_select = filedialog.askopenfilenames()
root.destroy()
root.mainloop()
return file_select
def invalid_login_email(to,sub,message,file_name):
msg = MIMEMultipart()
msg["From"] = "Aditya Wadkar"
msg["To"] = to
msg["subject"] = sub
msg.attach(MIMEText(message, 'plain'))
# filename = os.path.basename(file_name) # file select
attachment = open(file_name, "rb")
part = MIMEBase('application', 'octet-stream')
part.set_payload(attachment.read())
encoders.encode_base64(part)
part.add_header('content-Disposition', f'attachment; filename ={file_name}')
msg.attach(part)
session = smtplib.SMTP('smtp.gmail.com', 587) # use gmail with port
session.starttls() # enable security
session.login(GMAIL_ID, GMAIL_PSD) # login with mail_id and password
text = msg.as_string()
session.sendmail(GMAIL_ID, to, text)
session.quit()
def mail_with_attachment(to, sub, message, name, attach):
file_select = attach
speak(f"Sending email to {name} within few moments !!")
msg = MIMEMultipart()
msg["From"] = "Aditya Wadkar"
msg["To"] = ",".join(to)
msg["subject"] = sub
msg.attach(MIMEText(message, 'plain'))
speak("Finding and validating attachment !!")
for filecount in file_select:
filename = os.path.basename(filecount) # file select
attachment = open(filecount, "rb")
part = MIMEBase('application', 'octet-stream')
part.set_payload(attachment.read())
encoders.encode_base64(part)
part.add_header('content-Disposition', 'attachment; filename = %s' % filename)
msg.attach(part)
session = smtplib.SMTP('smtp.gmail.com', 587) # use gmail with port
session.starttls() # enable security
session.login(GMAIL_ID, GMAIL_PSD) # login with mail_id and password
text = msg.as_string()
speak("attatchment validated Successfully!!Now Uploading attachment and sending email!!This may take few minutes depending upon file size")
try:
session.sendmail(GMAIL_ID, to, text)
speak(f"Email successfully sent!! ")
except:
speak("You cannot send application file or exe file through mail!! so mail not sent")
session.quit()
def sendmail(to, sub, msg, no):
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
try:
s.login(GMAIL_ID, GMAIL_PSD)
s.sendmail("Aditya Wadkar", to, f"subject: {sub} \n\n {msg}")
except Exception as e:
if no==1:
speak("you have written wrong username or password!!! so ! mail has not sent")
else:
if no == 1:
speak("Email successfully sent ")
speak(f"Email successfully sent!! ")
s.quit()
def offline_mode(type=None):
root = Tk()
root.title("command")
root.geometry("400x160")
root.resizable(False, False)
bg = PhotoImage(file="uicomponents//command.png")
def disable_event1():
pass
def next_order():
global order
order = txtfield.get()
txtfield.delete(0, END)
root.destroy()
if type=="task":
command_label='write task'
command_button='Add Task'
elif type == 'search':
command_label = 'Write File Name'
command_button = 'Search File'
elif type == 'time_limit :':
command_label = 'Time Limit'
command_button = 'Set Time Limit'
elif type == 'google_search':
command_label = 'Search Title :'
command_button = 'Search'
elif type == 'youtube_search':
command_label = 'watch Title :'
command_button = 'Search File'
elif type == 'location':
command_label = 'Write Location :'
command_button = 'Locate'
elif type == 'terminate':
command_label = 'Your Answer :'
command_button = 'Perform Task'
else:
command_label = 'write command:'
command_button = 'Perform Task'
# Show image using label
root.iconphoto(False, bg)
label1 = Label(root, image=bg).pack()
heading1 = Label(label1, text=command_label, font="verdena 13 bold")
heading1.place(x=10, y=30)
txtfield = Entry(label1, font="Helvitica 14")
txtfield.place(x=150, y=30, width=240, height=25)
button1 = Button(label1, text=command_button, command=next_order)
button1.place(x=195, y=80)
try:
root.protocol("WM_DELETE_WINDOW", disable_event1)
root.mainloop()
except:
pass
return order
def face_authentication():
global converted_image
cam = cv2.VideoCapture(0) # used to create video which is used to capture images
cascadePath = "uicomponents//haarcascade_frontalface_default.xml"
recognizer = cv2.face.LBPHFaceRecognizer_create()
speak(" !! performing face authentication!!please look at camera ")
recognizer.read('uicomponents//trained_data.yml') # loaded trained model
faceCascade = cv2.CascadeClassifier(cascadePath)
font = cv2.FONT_HERSHEY_SIMPLEX # denotes fonts size
# id = 5 # number of persons your want to recognize
# names = ['', 'Aditya']
cam.set(3, 640)
cam.set(4, 480)
#
# # define min window size to be recognize as a face
minW = 0.1 * cam.get(3)
maxW = 0.1 * cam.get(4)
valid_face = 0
invalid_face = 0
while True:
ret, img = cam.read() # read the frames using above created objects
# cv2.imshow('camera', img)
try:
converted_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # converts image to black and white
except:
pass
faces = faceCascade.detectMultiScale(
converted_image,
scaleFactor=1.2,
minNeighbors=5,
minSize=(int(minW), int(minW)),
)
cv2.imshow("camera", img)
# time.sleep(1)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
id, accuracy = recognizer.predict(converted_image[y:y + h, x:x + w])
# check if accuracy is less than 100 ==> "0" is perfect match
# print(accuracy)
if (accuracy >= 45 and accuracy<=60):
valid_face += 1
if valid_face >=10:
# print(f"valid face : {valid_face}")
# cv2.imshow('frame', converted_image)
# if cv2.waitKey(1) == ord('q'):
# break
speak("face recognization successfull!!hello aditya!!!initializing System!!!!!")
cam.release()
cv2.destroyAllWindows()
pyautogui.press('esc')
return
else:
invalid_face += 1
# print(f"invalid face : {invalid_face}")
if invalid_face >=100:
mal_user = "mal_user.png"
cv2.imwrite(mal_user, img)
shutil.move('mal_user.png', 'uicomponents/')
close_program("uicomponents/mal_user.png")
sys.exit()
break
# cv2.putText(img, str(id), (x + 5, y - 5), font, 1, (255, 0, 255), 2)
# cv2.putText(img, str(accuracy), (x + 5, y + h - 5), font, 1, (255, 255, 0), 1)
k = cv2.waitKey(10) & 0xff
if k == 27:
break
cam.release()
cv2.destroyAllWindows()
def close_program(mal):
invalid_login_email("[email protected]", "Aditi Security alert!!!!",
f"An Unauthorized person tried to access me at {datetime.datetime.now().strftime('%H:%M:%S')}\nThe pic of that user is attached below.\nPlease Take a look in this matter\nIf it was done by you mistakenly. please Ignore This mail !!\n\nYou received this mail to ensure Security of Application ",
mal)
os.remove("uicomponents/mal_user.png")
speak("You are not a valid user . closing this application")
def validation():
global click_event
root = Tk()
root.geometry("540x360")
root.resizable(False,False)
bg = PhotoImage(file="uicomponents//login.png")
speak("!! To confirm !! you are valid user !write secret key Here")
def disable_event():
button2.place(x=395, y=300)
def close_win():
root.destroy()
sys.exit()
def authenticate():
global attempts
password = txtfield.get()
txtfield.delete(0,END)
if password == "KaniWal":
speak("hello Aditya!!!")
speak("initializing System!!!!!")
root.destroy()
# pyautogui.hotkey('alt','F4')
else:
if attempts < 1:
speak("Password is incorrect !!please retype it. !This is last chance!!")
attempts =attempts +1
if attempts ==2:
cam = cv2.VideoCapture(0)
while True:
ret, img = cam.read() # read the frames using above created objects
mal_user = "mal_user.png"
cv2.imwrite(mal_user, img)
shutil.move('mal_user.png', 'uicomponents/')
close_program("uicomponents/mal_user.png")
break
cam.release()
cv2.destroyAllWindows()
sys.exit()
# Show image using label
root.title("Authentication System")
p1 = PhotoImage(file='uicomponents\\login.png')
root.iconphoto(False,p1)
label1 = Label(root, image=bg).pack()
heading = Label(label1, text="Smart Login System", font="verdena 17 bold")
heading.place(x=270, y=30)
heading1 = Label(label1, text="Password:", font="verdena 13 bold")
heading1.place(x=270, y=170)
txtfield = Entry(label1, show="*")
txtfield.place(x=370, y=170)
label2=Label(root, image=bg).pack()
button1 = Button(label1, text="Activate", command=authenticate)
button1.place(x=395, y=200)
button2 = Button(label2, text="close program", command=close_win)
button2.pack_forget()
try:
root.protocol("WM_DELETE_WINDOW", disable_event)
root.mainloop()
except Exception as e:
# print(e)
pass
def find(name):
f = open("filepath.txt", "a")
f.truncate(0)
cnt = 0
speak("Searching file in your system!!!This may take few minutes!!")
speak("Till that time you enjoy some youtube videos")
p.playonyt("https://www.youtube.com/watch?v=VU07jbfe9dU&list=WL&index=2&t=182s")
for root, dirs, files in os.walk('C:\\'):
if name in files:
cnt = 1
f.write(root+"\n")
if cnt == 1:
file_not_found = True
else:
file_not_found = False
if file_not_found == False:
for root, dirs, files in os.walk('D:\\'):
if name in files:
cnt = 1
f.write(root + "\n")
if cnt == 1:
file_not_found = True
else:
file_not_found = False
if file_not_found == False:
speak("File not present in D directory Searching in E directory")
for root, dirs, files in os.walk('E:\\'):
if name in files:
cnt = 1
f.write(root + "\n")
f.close()
if cnt == 0:
speak("sorry !! file is not present in your system")
else:
speak("File found in system !!here's the path of that file")
webbrowser.open("filepath.txt")
def database_fetch(n):
global cnt1whatsapp,order
for index, item in df.iterrows():
if item["name"] == n:
cnt1whatsapp = 1
order="Name present in database"
if cnt1whatsapp != 1:
order="Name not present in database!! Please Update it"
cnt1whatsapp =0
return order
def message(no,msg,n):
import pywhatkit as p
speak(f"sending whatsapp message to {n} within a minute !!! Please be patient ")
try:
hrs = int(datetime.datetime.now().hour)
min = int(datetime.datetime.now().minute) + 1
p.sendwhatmsg('+' + no, msg, hrs, min)
except Exception as e:
# print(e)
try:
min = min + 2
p.sendwhatmsg('+' + no, msg, hrs, min)
except:
speak("Cannot send whatsapp message at this moment!!sorry for inconvience!!please try again later")
return
def whatsappmsg(self):
global cnt1whatsapp
ab=0
try:
speak("To whom your want to send message : ")
querry = self.takecommand1().lower()
n = querry
for index, item in df.iterrows():
if item["name"] == n:
cnt1whatsapp =1
ab = str(math.trunc(item["no"]))
if cnt1whatsapp != 1:
speak(f"Sorry!! The name {n} is not present in database!! Please Update it")
return
speak(f"what message you would like to give to {n}")
whatmsg = self.takecommand1()
confirmation(self.querry)
time.sleep(1)
while True:
speak("have I listen the message correctly ??")
check = self.takecommand1()
if "yes" in check or "correctly" in check or "right" in check:
pyautogui.hotkey("alt", "F4")
delete_file("confirm.txt")
break
elif "no" in check or "incorrect" in check or "wrong" in check:
pyautogui.hotkey("alt", "F4")
delete_file("confirm.txt")
speak("Sorry for that!! Please say that once again!!")
whatmsg = self.takecommand1()
confirmation(self.querry)
elif "cancel" in check:
pyautogui.hotkey("alt", "F4")
delete_file("confirm.txt")
speak("Sending whatsapp message program Cancelled Successfully!!")
return
msg = whatmsg
message(ab,msg,n)
except Exception as e:
# print(e)
root = Tk()
root.title("Whatsapp Messenger")
root.geometry("400x160")
root.resizable(False, False)
bg = PhotoImage(file="uicomponents//whatsapp.png")
def collect_data_whatsapp():
n=txtfield_whatsapp.get()
msg=txtfield1_whatsapp.get()
for index, item in df.iterrows():
if item["name"] == n:
cnt1whatsapp = 1
ab = str(math.trunc(item["no"]))
if cnt1whatsapp != 1:
speak(f"Sorry!! The name {n} is not present in database!! Please Update it")
root.destroy()
message(ab,msg,n)
def name_verify():
global order
order = txtfield_whatsapp.get()
name_verification = database_fetch(order)
name_result.config(text=name_verification)
# Show image using label
root.iconphoto(False, bg)
label1 = Label(root, image=bg).pack()
name_result = Label(label1, font="verdena 10 bold")
name_result.place(x=70, y=9)
heading1 = Label(label1, text="Receiver's Name:", font="verdena 13 bold")
heading1.place(x=10, y=40)
txtfield_whatsapp = Entry(label1, font="Helvitica 10")
txtfield_whatsapp.place(x=155, y=40, width=140, height=22)
verify = Button(label1, text="Verify Name", command=name_verify)
verify.place(x=315, y=40)
heading2 = Label(label1, text="Message :", font="verdena 13 bold")
heading2.place(x=30, y=80)
txtfield1_whatsapp = Entry(label1, font="Helvitica 10")
txtfield1_whatsapp.place(x=155, y=80, width=230, height=22)
button1 = Button(label1, text="Send Message", command=collect_data_whatsapp)
button1.place(x=145, y=120)
try:
# root.protocol("WM_DELETE_WINDOW", disable_event)
root.mainloop()
except:
pass
def mail(self):
try:
mail_id = []
name = []
def receipient1():
global cnt1
speak("To whom you want to send mail : ")
self.querry = self.takecommand1().lower()
to = self.querry
# print(to)
name.append(to)
for index, item in df.iterrows():
if item["name"] == to:
cnt1 = 1
mail_id.append(item['Email'])
if cnt1 != 1:
speak(f"Sorry!! The name {name[-1]} is not present in database!!Please update it")
name.pop()
cnt1 = 0
speak("do you wish to add another recipient ? ")
option = self.takecommand1().lower()
if "no" in option or "do not" in option:
return
elif "yes" in option or "add" in option:
receipient1()
receipient1()
# print(name)
if len(name)==0:
speak("You have not added any receipent!!please add atleast 1")
receipient1()
speak("what subject you want to give")
self.querry = self.takecommand1().lower()
subject = self.querry
confirmation(subject)
time.sleep(1)
while True:
speak("!have I listen the subject correctly ??")
check = self.takecommand1().lower()
if "yes" in check or "correctly" in check or "right" in check:
pyautogui.hotkey("alt","F4")
delete_file("confirm.txt")
break
elif "no" in check or "incorrect" in check or "wrong" in check:
pyautogui.hotkey("alt", "F4")
delete_file("confirm.txt")
speak("Sorry for that!! Please say that once again!!")
subject = self.takecommand1().lower()
confirmation(subject)
elif "cancel" in check or "stop" in check:
pyautogui.hotkey("alt", "F4")
delete_file("confirm.txt")
speak("Sending mail program Cancelled Successfully!!")
return
sub = subject
speak("What message you want to convey : ")
self.querry = self.takecommand1()
email_message=self.querry
confirmation(email_message)
time.sleep(3)
while True:
speak("have I listen the message correctly ??")
check = self.takecommand1()
if "yes" in check or "correctly" in check or "right" in check:
pyautogui.hotkey("alt", "F4")
delete_file("confirm.txt")
break
elif "no" in check or "incorrect" in check or "wrong" in check:
pyautogui.hotkey("alt", "F4")
delete_file("confirm.txt")
speak("Sorry for that!! Please say that once again!!")
email_message = self.takecommand1()
confirmation(email_message)
elif "cancel" in check or "stop" in check:
pyautogui.hotkey("alt", "F4")
delete_file("confirm.txt")
speak("Sending mail program Cancelled Successfully!!")
return
message = email_message
message = message + "\n\n\n\n---\nThanks And Regards,\nMr. Aditya Anand Wadkar\nMOB NO : 8275693296\nEmail: [email protected]"
if "attachment" in message:
attach = pick_aatachment()
mail_with_attachment(mail_id, sub, message, name, attach)
else:
speak("Do you wish to send attachment along with this mail")
self.querry = self.takecommand1().lower()
if "don not" in self.querry or "no" in self.querry:
speak(f"Sending email to {name} within few moments !!")
sendmail(mail_id, sub, message, 1)
elif "yes" in self.querry or "send attachment" in self.querry or "attachment" in self.querry:
attach = pick_aatachment()
mail_with_attachment(mail_id, sub, message, name, attach)
except Exception as e:
root = Tk()
root.title("Email")
root.geometry("400x250")
root.resizable(False, False)
bg = PhotoImage(file="uicomponents//email.png")
def collect_data(option):
global cnt1
mail_id = []
name = []
to = txtfield.get()
sub = txtfield1.get()
message = txtfield2.get()
name.append(to)
for index, item in df.iterrows():
if item["name"] == to:
cnt1 = 1
mail_id.append(item['Email'])
if cnt1 != 1:
speak(f"Sorry!! The name {name[-1]} is not present in database!!Please update it")
name.pop()
cnt1 = 0
message = message + "\n\n\n\n---\nThanks And Regards,\nMr. Aditya Anand Wadkar\nMOB NO : 8275693296\nEmail: [email protected]"
root.destroy()
if option == "mail":
speak(f"Sending email to {name} within few moments !!")
sendmail(mail_id, sub, message, 1)
else:
attach = pick_aatachment()
mail_with_attachment(mail_id, sub, message, name, attach)
def name_verify():
global order
order = txtfield.get()
name_verification = database_fetch(order)
name_result.config(text=name_verification)
root.iconphoto(False, bg)
label1 = Label(root, image=bg).pack()
name_result = Label(label1, font="verdena 10 bold")
name_result.place(x=70, y=9)
heading1 = Label(label1, text="Receiver's name:", font="verdena 13 bold")
heading1.place(x=10, y=40)
txtfield = Entry(label1, font="Helvitica 10")
txtfield.place(x=155, y=40, width=140, height=22)
verify = Button(label1, text="Verify Name", command=name_verify)
verify.place(x=315, y=40)
heading2 = Label(label1, text="Subject :", font="verdena 13 bold")
heading2.place(x=35, y=80)
txtfield1 = Entry(label1, font="Helvitica 10")
txtfield1.place(x=155, y=80, width=230, height=22)
heading3 = Label(label1, text="Message :", font="verdena 13 bold")
heading3.place(x=32, y=120)
txtfield2 = Entry(label1, font="Helvitica 10")
txtfield2.place(x=155, y=120, width=230, height=22)
heading4 = Label(label1, text="Attachment (if any) ", font="verdena 13 bold")
heading4.place(x=10, y=160)
attach = Button(label1, text="Attach File", command=lambda: collect_data("attachment"))
attach.place(x=195, y=160)
button1 = Button(label1, text="Send Email", command=lambda: collect_data("mail"))
button1.place(x=145, y=210)
try:
root.mainloop()
except:
pass
def wishMe():
'''
Greetings to user
:return:
'''
if hour < 12:
speak("good Morning")
elif hour >= 12 and hour < 16:
speak("good Afternoon")
elif hour >= 16 and hour < 22:
speak("good Evening ")
else:
speak("Its late night")
speak(f"Current temperature is {temperature} and the weather is {weather1}")
def news():
url = f"http://newsapi.org/v2/top-headlines?country=in&apiKey={news_api_key}"
main_page = requests.get(url).json()
article = main_page["articles"]
head = []
for ar in article:
head.append(ar["description"])
for i in range(6):
# a = time.sleep(2)
# print(f"{i + 1} {head[i]} ")
speak(f"{i + 1} {head[i]} ")
time.sleep(2)
temperature = ""
weather1 = ""
def weather():
global temperature, weather1
url = "http://api.openweathermap.org/data/2.5/weather?q=Pune&units=metric&appid=710e105ff069d401d319b833c155511f"
main_page = requests.get(url).json()
temp = main_page["main"]['temp']
weather1 = main_page["weather"][0]['main']
temperature = str(temp) + " \N{DEGREE SIGN}C"
def terminate(self):
speak("Thanks for using me.")
speak(" Would you also like to close or restart your system for better performance ??")
try:
self.querry = self.takecommand1().lower()
except Exception as e:
self.querry = offline_mode('terminate')
if 'no' in self.querry:
speak("closing Application within few moments")
startmain.kill()
exit()
sys.exit()
elif 'shutdown' in self.querry or "yes" in self.querry:
os.system("shutdown /s ")
speak("Your system will shutdown within a minute ")
startmain.kill()
exit()
sys.exit()
elif 'restart' in self.querry:
os.system("shutdown /r ")
speak("Your system will restart within a minute ")
startmain.kill()
exit()
sys.exit()
city, country = "", ""
def location():
global city, country
add = requests.get("https://api.ipify.org").text
url = "https://get.geojs.io/v1/ip/geo/" + add + ".json"
geo_request = requests.get(url)
geo_data = geo_request.json()
city = geo_data['city']
country = geo_data['country']
def stop_listening(value,target):
string1 = value
try:
a = int(re.search(r'\d+', string1).group())
except:
speak("I cannot do this right now!! sorry for inconvience")
return
if "second" in string1:
if target =="stop":
speak(f"I will not listen anything for {a} seconds")
else:
speak("setting timer for {a} seconds")
time.sleep(a)
speak(f"{a} seconds are completed !!")
elif "minute" in string1:
if target == "stop":
speak(f"I will not listen anything for {a} minutes")
else:
speak("setting timer for {a} minutes")
time.sleep(60 * a)
if a == 1:
speak(f"{a} minute is completed !!")
else:
speak(f"{a} minutes are completed !!")
else:
speak("sorry!!I cannot stop listening for more than 60 minutes")
speak("Now I am activated as your time is up !!!")
def main2(self):
global sleepcount
sleepcount=1
while True:
if keyboard.is_pressed('pause') == True:
sleepcount = 0
speak("I am activated")
self.main()
if keyboard.is_pressed('Esc') == True:
terminate(self)
def wikipedia_result(str,no):
main_word,last = str.split("is",1)
try:
speak("searching on internet...")
results = wikipedia.summary(last, sentences=no)
speak("according to information on internet...")
# print(results)
speak(results)
except Exception as e:
speak(f"sorry !! I am unable to access information about {last}!due to shortage of information or lack of internet connection!! please try again later ")
def basic_commands(self, querry):
global commandcount
if "how are you" in self.querry:
speak("I am fine sir!! What about you ??")
elif "good" in self.querry or "fine" in self.querry:
speak("Nice to listen that")
elif "thankyou" in self.querry or "thanks" in self.querry:
speak("Its my pleasure sir!! I am always available for you !!!!")
elif "name" in self.querry:
speak("My name is aditi and I am virtual assistant")
elif "yourself" in self.querry or "functions" in self.querry or "what can you do" in self.querry:
speak(" My name is aditi!!! My maker has assemble a great deal of capacities "
"in me!!I can send emails,!whatsapp messages !! can give climate subtleties,"
" news refreshes!!,play tunes, can take you to visit through web surfing !! "
"fetch information about anyone and lots more!! But I am in developing stage!!!"
"my developers are updating me daily!!!!!")
elif "born" in self.querry or "birthday" in self.querry :
speak("I was born on 11 september 2020 as a captone project by my developers")
elif "i love you" in self.querry:
speak("I love you to !!!!!!! but as a friend !!")
elif "marry me" in self.querry:
if (commandcount % 2 == 0):
speak("Sorry I cannot marry you!!Because I am a just few lines of code! and not a girl!!!Infact "
"I suggest you to create your account on any matrimonial Site! so that your can find your life partner!!")
webbrowser.open("https://www.shaadi.com/")
time.sleep(3)
else:
speak("sorry !! I am already in relationship with electricity")
speak("here's a sample matrimonial site for you !!!but to be very honest!!I don't think that any girl "
"would marry you after viewing your profile as no one will like your face")
elif "my" in self.querry and "girlfriend" in self.querry:
speak("sorry !! I can't be your girfriend as I am already engaged with your machine !!")
else:
speak("sorrry I didn't understand that!! ")
self.main()
class MainThread(QThread):
def __init__(self):
super(MainThread, self).__init__()
def kill(self):
pass
def run(self):
# weather()
location()
# wishMe()
self.main()
def takecommand1(self):
'''
take user commands(microphone inputs and returns string output)
:return:
'''
r = sr.Recognizer()
with sr.Microphone() as source:
# print("Listening...... ")
speak("Listening......")
r.pause_threshold = 0.5
audio = r.listen(source)
try:
# print("Recognizing....")
speak("Recognizing....")
self.querry = r.recognize_google(audio, language='en-in')
self.querry = self.querry.lower()
# else:
# self.querry = self.takecommand1().lower()
# print(f"user said :{self.querry}\n")
except Exception as e:
# print(e)
speak(" I coud not hear that !!!! please say that once again !!")
return self.querry
def main(self):
global taskcount,commandcount,splitcommand
while True:
if taskcount == 0:
wishMe()
try:
speak("Sir!!! do you wish to know your Todays task ??")
self.querry = self.takecommand1().lower()
if "do not" in self.querry or 'no' in self.querry:
pass
elif "yes" in self.querry or "task" in self.querry:
target()
except Exception as e:
self.querry = offline_mode()
if "yes" in self.querry:
target()
taskcount = 1
####################### Taking User command #########################
if (commandcount % 2 == 0):
speak("I am ready for next command")
else:
speak("what's my next task ")
commandcount = commandcount + 1
try:
self.querry = self.takecommand1().lower()
except Exception as e:
self.querry = offline_mode()
if "and" in self.querry:
splitcommand=1
s1, s2 = self.querry.split("and", 1)
self.querry=s1
if splitcommand==1:
self.querry=s2
splitcommand=0
mood=random.randint(0,10)
####################### Closing tab #########################
if "close" in self.querry:
if mood == 6:
speak("sir !!! You are becoming too lazy now a days !! just because of me !!"
"so close this window on your own !! give me some other task ")
time.sleep(2)
else:
try:
pyautogui.hotkey("alt", "F4")
except:
speak("sorry !! unable to access your keyboard!!!Please close it manually for this time!!")
####################### Music #########################
elif "play" in self.querry and ("music" in self.querry or "song" in self.querry or "songs" in self.querry):
if mood == 6:
speak("sir !!! it will be better if you play song on your own!! give me some other task !! ")
time.sleep(1)
else:
try:
musicdir = 'C:\\Users\\Admin\\Music'
songs = os.listdir(musicdir)
speak("playing songs from your music directory")
os.startfile(os.path.join(musicdir, songs[random.randint(1, 64)]))
except Exception as e:
speak("which song would you like to listen")
try:
self.querry = self.takecommand1().lower()
except Exception as e: