Added a nice Avatar for Jade
Updated the main.py with the help of ChatGPT to make sure Jade doesn't run forever while still allowing for her to run forever Included a requirements.txt to allow me to install again if need be.
This commit is contained in:
46
main.py
46
main.py
@ -9,25 +9,39 @@ wake_word = "Jade"
|
||||
def recognize_speech():
|
||||
r = sr.Recognizer()
|
||||
with sr.Microphone() as source:
|
||||
print("Say something!")
|
||||
audio = r.listen(source)
|
||||
try:
|
||||
text = r.recognize_sphinx(audio)
|
||||
print(f"You said: {text}")
|
||||
if wake_word.lower() in text.lower():
|
||||
# Get the intent from the text
|
||||
intent = get_intent(text)
|
||||
response = handle_intent(intent)
|
||||
say(response)
|
||||
except sr.UnknownValueError:
|
||||
print("PocketSphinx could not understand audio")
|
||||
except sr.RequestError as e:
|
||||
print(f"PocketSphinx error; {e}")
|
||||
|
||||
while True:
|
||||
print("Say something!")
|
||||
audio = r.listen(source)
|
||||
try:
|
||||
text = r.recognize_sphinx(audio)
|
||||
print(f"You said: {text}")
|
||||
if wake_word.lower() in text.lower():
|
||||
# Listen for a specific command
|
||||
say("What can I do for you?")
|
||||
command_audio = r.listen(source)
|
||||
command_text = r.recognize_sphinx(command_audio)
|
||||
print(f"You said: {command_text}")
|
||||
# Check if user wants to exit during command
|
||||
if "stop" in command_text.lower() or "exit" in command_text.lower():
|
||||
say("Goodbye!")
|
||||
break
|
||||
# Get the intent from the command text
|
||||
intent = get_intent(command_text)
|
||||
response = handle_intent(intent)
|
||||
say(response)
|
||||
# Check if user wants to exit after command
|
||||
if "stop" in response.lower() or "exit" in response.lower():
|
||||
say("Goodbye!")
|
||||
break
|
||||
except sr.UnknownValueError:
|
||||
print("PocketSphinx could not understand audio")
|
||||
except sr.RequestError as e:
|
||||
print(f"PocketSphinx error; {e}")
|
||||
|
||||
# Define the function to get the intent from text
|
||||
def get_intent(text):
|
||||
# TODO: implement intent recognition
|
||||
return "greeting"
|
||||
|
||||
# Call the speech recognition function
|
||||
recognize_speech()
|
||||
recognize_speech()
|
Reference in New Issue
Block a user