-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVoice Project
More file actions
299 lines (243 loc) · 11.4 KB
/
Voice Project
File metadata and controls
299 lines (243 loc) · 11.4 KB
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
import webbrowser
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes
import sys
import requests
import calendar
import random
import pyshorteners as sh
from tkinter import *
import tkinter as tk
from PIL import Image, ImageTk
from tkinter import messagebox
print("welcome")
pos = N
#listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty("voices")
engine.setProperty('voice',voices[1].id) # Set femal voice
def engine_talk(text):
engine.say(text)
engine.runAndWait()
def InsertText(text):
output.delete('1.0',END)
output.insert(tk.INSERT,text)
def click():
wishMe()
#once click on NAME button
#entered_text = textentry.get() #stored data in text box
#definition = "Hello " +str(entered_text)+ " I'm Genia your virtual assistant\npress ASK to ask for anything"
#output.insert(END,definition)
# output.insert(END,definition)
#engine_talk(definition)
#nameButton = Button(window, text= "Enter your Name", width = 20, command = click, fg = "#272324", bg= "#A9A9A9",state="disabled").grid(row=3, column=0 ,sticky=pos)
def refresh(): #once click on ASK button
definition = "I'm listening.."
#InsertText(definition)
engine_talk(definition)
main()
def user_commands():
listener = sr.Recognizer()
with sr.Microphone() as Source:
print("start saying")
listener.pause_threshold = 0.7
listener.phrase_threshold = 0.2
listener.energy_threshold = 365
voice = listener.listen(Source)
if voice == ' ':
usr = user_commands()
#pass
print("We got it , please wait")
command = ''
try:
command = listener.recognize_google(voice)
print("You Said : " + command)
except Exception as e:
print("Exception : Sorry .. I Coulnt recognize what you said" + str(e))
print("Say that again Please...")
engine_talk("Could you please say that again")
return command
def getDate():
now = datetime.datetime.now()
my_date =datetime.datetime.today()
weakday = calendar.day_name[my_date.weekday()]
monthNum = now.month
dayNum = now.day
MONTHS = ['January', 'February' , 'March' , 'April' , 'May' , 'June' ,
'July' , 'August' , 'September' , 'October' , 'November' ,'December']
ordinalNumbers = ['1st' , '2nd' , '3rd' , '4th' , '5th ', '6th' , '7th' , '8th' , '9th' , '10th' , '11th',
'12th' , '13th' , '14th' , '15th' , '16th' , '17th' ,'18th' , '19th' , '20th' , '21st' ,
'22nd', '23rd' , '24th' , '25th' , '26th', '27th' , '28th' , '29th' , '30th' , '31st'
]
return 'Today is {} {} {}'.format(ordinalNumbers[dayNum -1],MONTHS[monthNum -1],weakday)
def wishMe():
GREETING_INPUTS = ['hi' , 'hey' , 'wassup' , 'hello']
GREETING_RESPONSES = ['hello' , 'hey there' ]
HELP_GREET_RESPONSES = ['how may I help you' , 'I am now ready to take your commands' ,
'Please tell me what I can do for you']
hour = int(datetime.datetime.now().hour)
entered_text = textentry.get() #stored data in text box
#definition = "Hello " +str(entered_text)+ " I'm Genia your virtual assistant\npress ASK to ask for anything"
#output.insert(END,definition)
#output.insert(END,definition)
#engine_talk(definition)
#nameButton = Button(window, text= "Enter your Name", width = 20, command = click, fg = "#272324", bg= "#A9A9A9",state="disabled").grid(row=3, column=0 ,sticky=pos)
if hour > 0 and hour <12 :
engine_talk('Good Morning {}'.format(str(entered_text)) + '\nI am alexa.... Your Virtal Assistant')
engine_talk(getDate())
engine_talk(random.choice(HELP_GREET_RESPONSES))
engine_talk('\npress ASK to ask for anything')
elif hour >=12 and hour <= 18 :
engine_talk('Good Afternoon {}'.format(str(entered_text)) + '\nI am alexa.... Your Virtal Assistant')
engine_talk(getDate())
engine_talk(random.choice(HELP_GREET_RESPONSES))
engine_talk('\npress ASK to ask for anything')
else:
engine_talk('Good Night {}'.format(str(entered_text)) + '\nI am alexa.... Your Virtal Assistant')
engine_talk(getDate())
engine_talk(random.choice(HELP_GREET_RESPONSES))
engine_talk('\npress ASK to ask for anything')
def main():
import tkinter as tk
#a = 'stop exit shutdown goodbye sleep see you later'
usercommand = user_commands().lower() # open song
while(usercommand != None):
if ('audible' in usercommand) or ('can you hear me' in usercommand):
engine_talk("Yes you are audiable")
break
if ('short link' in usercommand):
engine_talk("Please Enter link")
link = input("Please Enter Link")
s = sh.Shortener()
x = (s.tinyurl.short(link))
engine_talk("Here Is your Short Link")
InsertText(x)
print(x)
break
if(('play song' in usercommand) or ('start song' in usercommand) or ('music' in usercommand) or ('song' in usercommand)):
engine_talk("why not")
song = usercommand.replace('play song',' ')
song = usercommand.replace('start song',' ')
song = usercommand.replace('music',' ')
song = usercommand.replace('song',' ')
pywhatkit.playonyt(song)
break
if ('start youtube' in usercommand) or ('open youtube' in usercommand):
engine_talk("why not")
webbrowser.open('www.youtube.com')
break
if ('facebook' in usercommand):
webbrowser.open('www.facebook.com')
break
if 'linkedin' in usercommand:
engine_talk("lets get professional")
webbrowser.open('www.linkedin.com')
break
if 'open stack over flow' in usercommand or 'stackoverflow' in usercommand or 'stack overflow' in usercommand:
engine_talk("Yaa Sure")
webbrowser.open('https://stackoverflow.com/')
break
if 'time' in usercommand:
time = datetime.datetime.now().strftime('%I:%M %p')
InsertText(time)
engine_talk('The current time is' +time)
break
if(('who is' in usercommand) or ("something about" in usercommand)):
name = usercommand.replace('who is','')
info = wikipedia.summary(name,1)
InsertText(info)
print(info)
engine_talk(info)
break
if 'joke' in usercommand:
engine_talk(pyjokes.get_joke())
break
if 'show me' in usercommand or 'search for' in usercommand or 'google' in usercommand:
show = usercommand.replace('show me',' ')
show = usercommand.replace('search for',' ')
engine_talk("here is" +show)
webbrowser.open_new_tab('https://www.google.com/search?q='+show)
break
if(('stop' in usercommand) or ('exit' in usercommand) or ('shut down' in usercommand) or ('goodbye' in usercommand) or ('sleep' in usercommand) or ('see you later' in usercommand)):
#if usercommand in a:
engine_talk("Good Bye Sir... hope we meet soon")
sys.exit()
if 'amazon' in usercommand:
webbrowser.open_new_tab('https://www.amazon.in/')
break
if ('love you' in usercommand or 'would you marry me' in usercommand):
engine_talk('oh, you are so sweet')
InsertText('oh, you are so sweet')
break
if 'bmi' in usercommand or 'b m i' in usercommand or 'body mass index' in usercommand:
Height=float(input("Enter your height in centimeters: "))
Weight=float(input("Enter your Weight in Kg: "))
Height = Height/100
BMI=Weight/(Height*Height)
print("your Body Mass Index is: ",BMI)
if(BMI>0):
if(BMI<=16):
print("you are severely underweight")
elif(BMI<=18.5):
print("you are underweight")
elif(BMI<=25):
print("you are Healthy")
elif(BMI<=30):
print("you are overweight")
else: print("you are severely overweight")
else:("enter valid details")
break
if "what can you do" in usercommand.lower():
engine_talk("here is a list of what i can do")
messagebox.showinfo("DREAM functions", "1.Try saying 'Hi','Hello'" +
"\n2.Try asking 'What is Time now'" +
"\n3. You can open Facebook by saying.. 'Open Facebook'" +
"\n4. You can open stackoverflow By saying.. 'Open stackoverflow'" +
"\n5. You Can Open Amazon By saying .. 'open amazon'"+
"\n6. You can listen joke by saying ..'Tell me is a joke'" +
"\n7. You can open linkedin by saying .. 'open linkedin'" +
"\n8. You can short a link by saying ..'short a link for me'" +
"\n9.You search in google by saying...'Search (or) Google <anything>'" +
"\n10.Play youtube by saying'YouTube... <video_name>'" +
"\n11.Search in Wikipedia by saying...'wikipedia...<anything>'" +
"\n12.To close say 'stop' or 'exit' or 'goobye' or 'Sleep' or 'See you later' or 'shutdown' " +
"\n13. You can check you are audiable or not." +
"\n14.You Can Calculate your BMI (Body Mass Index) ")
break
else:
engine_talk("Im not sure I understand")
InsertText("Im not sure I understand")
usercommand = user_commands().lower()
def close_window():
window.destroy()
sys.exit()
window = Tk()
window.title("Ujjwal")
window.iconbitmap('C:\\Users\\Shubham\\Desktop\\brain_sWy_icon.ico')
window.configure(background = 'black')
window.geometry('430x420') #'640x720
#Photo Label
AssisstancePhoto = 'C:\\Users\\Shubham\\Desktop\\rt.png'
photo1 = PhotoImage(file=AssisstancePhoto)
Label (window , image = photo1, bg ='black') .grid(row=0, column = 0, sticky=pos)
#create a text entry box
textentry = Entry(window, width = 40 ,bg="white", fg = 'black')
textentry.grid(row =2 , column=0, sticky =pos)
# text = textentry.get()
#Add a submit button
nameButton = Button(window, text= "Enter your Name", width = 20, command = wishMe, fg = "#272324", bg= "#A9A9A9").grid(row=3, column=0 ,sticky=pos)
askButton = Button(window, text= "ASK", width= 20, command = refresh, fg = "#272324", bg= "#A9A9A9").grid(row=4, column= 0 , sticky=pos)
#textbox
output = Text(window, width=40 , height = 5, wrap = WORD, bg= 'black',fg = "#00D1FF")
output.grid(row=5, column=0, columnspan=2, sticky=pos)
output.config(state=NORMAL)
#Exit Text Label
Label (window,text="Click to Exit", bg= 'black',fg = "white",font = "none 10 bold" ).grid (row=6 ,column =0, sticky=pos)
#Exit Button
Button(window, text= "EXIT", width= 20, command=close_window, fg = "#272324", bg= "#A9A9A9").grid(row=7, column= 0 , sticky=pos)
Label(window,text="© Made By Code Terror", bg= 'black',fg = "white",font = "none 7 bold" ).grid (row=8 ,column =0, sticky=S)
window.mainloop()