From cd655ecbcfbdcddf659e05810040e93eaab2e257 Mon Sep 17 00:00:00 2001 From: Devansh Dubey <69635552+dubeyji0110@users.noreply.github.com> Date: Tue, 15 Dec 2020 11:16:57 +0530 Subject: [PATCH] bug fixed --- main.py | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index a06ef10..141190c 100644 --- a/main.py +++ b/main.py @@ -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: @@ -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', '') @@ -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) @@ -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): @@ -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()