Python3 Code
Python3 Code
import time
import pyttsx3
import speech_recognition as sr
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
#print(voices[1].id)
engine.setProperty('voice',voices[1].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takecommand():
#It takes microphone input from the user and returns string as output
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening....")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recogninsing....")
query = r.recognize_google(audio, language = 'en-in')
print(f"User said: {query}\
")
except Exception as e:
print(e)
print("Say that again please...")
return "None"
return query
if __name__ == "__main__":
while True:
query = takecommand().lower()
#logic for executing tasks based on query
elif (20<distance<60):
speak("object is quite a distance away.")
elif (40<distance<100):
speak("object is 1 meter away.")
else:
speak("Object is far away.")
else:
print("nothing")