Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guesser_py modified #382

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Guesser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -24,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
Expand All @@ -36,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):
Expand Down