Overview: Combine speech recognition and TTS to create a basic voice interface assistant.
Use Case: Use with robots, kiosks, or basic home automation systems.
Working Code:
import speech_recognition as sr
import pyttsx3
r = sr.Recognizer()
engine = pyttsx3.init()
def speak(text):
engine.say(text)
engine.runAndWait()
with sr.Microphone() as source:
speak("How can I help you?")
audio = r.listen(source)
command = r.recognize_google(audio)
print("Command:", command)
if "time" in command:
speak("It is 5 PM.")
Next Step: Add more commands like “play music” or “start robot” for real functionality.
Try in Colab: Voice Assistant in Colab