Skip to content

Commit

Permalink
bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
dubeyji0110 authored Dec 15, 2020
1 parent e4c3905 commit cd655ec
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def talk(text):
def takeCmd():
try:
with sr.Microphone() as src:
listener.pause_threshold = 1
listener.adjust_for_ambient_noise(src)
voice = listener.listen(src)
cmd = listener.recognize_google(voice)
if 'jenny' in cmd:
Expand All @@ -29,13 +31,16 @@ def takeCmd():
except:
# pass
talk("Sorry, I can't understand!")
print('Listening...')
run_Jenny()
# print('Listening...')
# run_Jenny()
return 0
return cmd

# function to execute the command
def run_Jenny():
command = takeCmd()
if command == 0:
return
if 'play' in command:
song = command[command.find('play')+4:]
# song = command.replace('play', '')
Expand All @@ -48,7 +53,7 @@ def run_Jenny():
elif ('tell me a joke' in command) or ('give me a joke' in command):
talk(joke.get_joke())

elif ('time' in command) and ('what' in command):
elif ('the time' in command):
time = datetime.datetime.now().strftime('%I:%M %p')
talk("Current Time is: " + time)

Expand All @@ -59,19 +64,19 @@ def run_Jenny():
elif 'what' in command:
search = command[command.find('what')+8:]
# print(search)
res = wiki.summary(search, 1)
res = wiki.summary(search, 2)
talk(res)

elif 'who' in command:
search = command[command.find('who')+7:]
# print(search)
res = wiki.summary(search, 1)
res = wiki.summary(search, 2)
talk(res)

elif 'find' in command:
search = command[command.find('find')+5:]
# print(search)
res = wiki.summary(search, 1)
res = wiki.summary(search, 2)
talk(res)

elif ('power off' in command) or ('shutdown' in command) or ('shut down' in command):
Expand All @@ -84,12 +89,21 @@ def run_Jenny():

# functoin for initial greeting
def greet():
talk("Greetings! I'am Jenny your personal assisstant!")
hrs = int(datetime.datetime.now().hour)
if hrs < 4 and hrs >= 0:
greeting = 'Good Night!,'
if hrs >= 4 and hrs < 12:
greeting = 'Good Morning!,'
elif hrs >= 12 and hrs > 17:
greeting = 'Good Afternoon!,'
else:
greeting = 'Good Evning!,'
talk(greeting + " I'am Jenny your personal assisstant!")
talk("What can I do for you?")
# print('Listening...')


greet()
while 1:
print('Listining...')
run_Jenny()
if __name__ == "__main__":
greet()
while 1:
print('Listining...')
run_Jenny()

0 comments on commit cd655ec

Please sign in to comment.