Set up speech recognition to capture voice commands using your microphone.
import speech_recognition as sr
def listen_command():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
try:
audio = recognizer.listen(source)
command = recognizer.recognize_google(audio)
print(f"You said: {command}")
return command.lower()
except sr.UnknownValueError:
print("Sorry, I didn't catch that.")
return None