-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
334 lines (233 loc) · 10 KB
/
main.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
import speech_recognition as sr # To convert speech into text
import pyttsx3 # To convert text into speech
import datetime # To get the date and time
import wikipedia # To get information from wikipedia
import webbrowser # To open websites
import os # To open files
import time # To calculate time
import subprocess # To open files
from tkinter import * # For the graphics
import pyjokes # For some really bad jokes
from playsound import playsound # To playsound
import keyboard # To get keyboard
from PIL import ImageTk,Image;
import pywhatkit
global result1
result1 = '';
name_file = open("Assistant_name", "r")
name_assistant = name_file.read()
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
def speak(text):
engine.say(text)
print(name_assistant + " : " + text)
engine.runAndWait()
def wishMe():
hour = datetime.datetime.now().hour
if hour >= 0 and hour < 12:
speak("Hello,Good Morning")
elif hour >= 12 and hour < 18:
speak("Hello,Good Afternoon")
else:
speak("Hello,Good Evening")
def get_audio():
r = sr.Recognizer()
audio = ''
with sr.Microphone() as source:
print("Listening")
playsound("D:\storage\ACHAL\Assistant_on.wav")
audio = r.listen(source, phrase_time_limit=3)
playsound("D:\storage\ACHAL\Assistant_off.wav")
print("Stop.")
try:
text = r.recognize_google(audio, language='en-US')
print('You: ' + ': ' + text)
return text
except:
return "None"
def note(text):
date = datetime.datetime.now()
file_name = str(date).replace(":", "-") + "-note.txt"
with open(file_name, "w") as f:
f.write(text)
subprocess.Popen(["notepad.exe", file_name])
def date():
now = datetime.datetime.now()
month_name = now.month
day_name = now.day
month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October',
'November', 'December']
ordinalnames = ['1st', '2nd', '3rd', ' 4th', '5th', '6th', '7th', '8th', '9th', '10th', '11th', '12th', '13th',
'14th', '15th', '16th', '17th', '18th', '19th', '20th', '21st', '22nd', '23rd', '24rd', '25th',
'26th', '27th', '28th', '29th', '30th', '31st']
speak("Today is " + month_names[month_name - 1] + " " + ordinalnames[day_name - 1] + '.')
wishMe()
def Process_audio():
run = 1
if __name__ == '__main__':
while run == 1:
# app_string = [""]
# app_link = [r'']
# app_dest = r''
statement = get_audio().lower()
results = ''
run += 1
if "hello" in statement or "hi" in statement:
wishMe()
if "good bye" in statement or "ok bye" in statement or "stop" in statement:
speak('Your personal assistant ' + name_assistant + ' is shutting down, Good bye')
screen.destroy()
break
if 'wikipedia' in statement:
try:
speak('Searching Wikipedia...')
statement = statement.replace("wikipedia", "")
results = wikipedia.summary(statement, sentences=3)
speak("According to Wikipedia")
wikipedia_screen(results)
except:
speak("Error")
if 'joke' in statement:
speak(pyjokes.get_joke())
if 'open youtube' in statement:
webbrowser.open_new_tab("https://www.youtube.com")
speak("youtube is open now")
time.sleep(5)
if 'open google' in statement:
webbrowser.open_new_tab("https://www.google.com")
speak("Google chrome is open now")
time.sleep(5)
if 'open gmail' in statement:
webbrowser.open_new_tab("mail.google.com")
speak("Google Mail open now")
time.sleep(5)
if 'open netflix' in statement:
webbrowser.open_new_tab("netflix.com/browse")
speak("Netflix open now")
if 'open prime video' in statement:
webbrowser.open_new_tab("primevideo.com")
speak("Amazon Prime Video open now")
time.sleep(5)
if 'music' in statement or 'play' in statement:
song = statement.replace('play', '')
pywhatkit.playonyt(song)
speak("music open now")
time.sleep(5)
# if app_string[0] in statement:
# os.startfile(app_dest + app_link[0])
# speak("Microsoft office Word is opening now")
# if app_string[1] in statement:
# os.startfile(app_dest + app_link[1])
# speak("Microsoft office PowerPoint is opening now")
# if app_string[2] in statement:
# os.startfile(app_dest + app_link[2])
# speak("Microsoft office Excel is opening now")
# if app_string[3] in statement:
# os.startfile(app_dest + app_link[3])
# speak("Zoom is opening now")
# if app_string[4] in statement:
# os.startfile(app_dest + app_link[4])
# speak("Notepad is opening now")
# if app_string[5] in statement:
# os.startfile(app_dest + app_link[5])
# speak("Google chrome is opening now")
if 'news' in statement:
news = webbrowser.open_new_tab("https://timesofindia.indiatimes.com/city/mangalore")
speak('Here are some headlines from the Times of India, Happy reading')
time.sleep(6)
if 'cricket' in statement:
news = webbrowser.open_new_tab("cricbuzz.com")
speak('This is live news from cricbuzz')
time.sleep(6)
if 'corona' in statement:
news = webbrowser.open_new_tab("https://www.worldometers.info/coronavirus/")
speak('Here are the latest covid-19 numbers')
time.sleep(6)
if 'time' in statement:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"the time is {strTime}")
if 'date' in statement:
date()
if 'who are you' in statement or 'what can you do' in statement:
speak('I am ' + name_assistant + ' your personal assistant. I am programmed to minor tasks like opening youtube, google chrome, gmail and search wikipedia etcetra')
if "who made you" in statement or "who created you" in statement or "who discovered you" in statement or "made by" in statement or "made" in statement:
speak("I was built by Achal")
if 'make a note' in statement:
statement = statement.replace("make a note", "")
note(statement)
if 'guide' in statement:
speak('Your guide is Professor Sachin Deshpande')
if 'note this' in statement:
statement = statement.replace("note this", "")
note(statement)
print(results)
speak(results)
def change_name():
name_info = name.get()
file = open("Assistant_name", "w")
file.write(name_info)
file.close()
settings_screen.destroy()
screen.destroy()
def change_name_window():
global settings_screen
global name
settings_screen = Toplevel(screen)
settings_screen.title("Settings")
settings_screen.geometry("300x300")
settings_screen.iconbitmap('app_icon.ico')
name = StringVar()
current_label = Label(settings_screen, text="Current name: " + name_assistant)
current_label.pack()
enter_label = Label(settings_screen, text="Please enter your Virtual Assistant's name below")
enter_label.pack(pady=10)
Name_label = Label(settings_screen, text="Name")
Name_label.pack(pady=10)
name_entry = Entry(settings_screen, textvariable=name)
name_entry.pack()
change_name_button = Button(settings_screen, text="Ok", width=10, height=1, command=change_name)
change_name_button.pack(pady=10)
def info():
info_screen = Toplevel(screen)
info_screen.title("Info")
info_screen.iconbitmap('app_icon.ico')
creator_label = Label(info_screen, text="Created by Achal")
creator_label.pack()
Age_label = Label(info_screen, text="at the age of 19 ")
Age_label.pack()
for_label = Label(info_screen, text="For MiniProject")
for_label.pack()
keyboard.add_hotkey("F4", Process_audio)
def wikipedia_screen(text):
wikipedia_screen = Toplevel(screen)
wikipedia_screen.title(text)
wikipedia_screen.iconbitmap('app_icon.ico')
message = Message(wikipedia_screen, text=text)
message.pack()
def main_screen():
global screen
screen = Tk()
screen.title(name_assistant)
screen.geometry("400x400")
screen.iconbitmap('app.ico')
frameCnt = 12
name_label = Label(text=name_assistant, width=300, bg="black", fg="white", font=("Calibri", 13))
name_label.pack()
microphone_photo = Image.open("jarvis1.gif")
resized_image= microphone_photo.resize((100,174), Image.ANTIALIAS)
new_image= ImageTk.PhotoImage(resized_image)
#Add image to the Canvas Items
microphone_button = Button(image=new_image, command=Process_audio,height=100,width=100)
microphone_button.pack(pady=10)
settings_photo = Image.open("settings1.png")
resiz_image= settings_photo.resize((100,177), Image.ANTIALIAS)
new_images= ImageTk.PhotoImage(resiz_image)
settings_button = Button(image=new_images, command=change_name_window, height=100,width=100)
settings_button.pack(pady=10)
info_button = Button(text="Info", command=info)
info_button.pack(pady=10)
label_label = Label(text=results)
label_label.pack(pady=10)
screen.mainloop()
main_screen()