From 858bfee1c571c9f8b9a0d4f7fb27f79c2d346714 Mon Sep 17 00:00:00 2001 From: MudadlaYogitha Date: Tue, 22 Oct 2024 06:31:03 +0530 Subject: [PATCH 1/2] guesser_py modified --- Guesser.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Guesser.py b/Guesser.py index 6a161b7..d64dccc 100644 --- a/Guesser.py +++ b/Guesser.py @@ -8,8 +8,10 @@ def __init__(self, question): self.yes = None self.no = None +# Initialize pyttsx3 engine globally +engine = pyttsx3.init() + def speak(text): - engine = pyttsx3.init() engine.say(text) engine.runAndWait() From 0d4da8d3c80229a7aa907b2272e16c8baa5c4a1d Mon Sep 17 00:00:00 2001 From: MudadlaYogitha Date: Thu, 24 Oct 2024 19:12:12 +0530 Subject: [PATCH 2/2] improve speech recognition handling and performance --- Guesser.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Guesser.py b/Guesser.py index d64dccc..b3a494a 100644 --- a/Guesser.py +++ b/Guesser.py @@ -26,7 +26,7 @@ def listen(): return answer.lower() except sr.UnknownValueError: speak("Sorry, I didn't catch that. Can you please repeat?") - return listen() + return listen() # Recursion ensures another attempt to capture audio except sr.RequestError: speak("There was a problem with the service. Please try again later.") return None @@ -38,12 +38,17 @@ def ask_question(node): speak(node.question) answer = listen() + # Handle case where speech recognition returns None + if answer is None: + speak("I couldn't understand your response. Let's try again.") + return ask_question(node) + if answer == 'yes': return ask_question(node.yes) elif answer == 'no': return ask_question(node.no) else: - speak("I didn't understand that. Please say 'yes' or 'no'.") + speak("Please answer with 'yes' or 'no'.") return ask_question(node) def add_new_thing(node, question, new_thing):