0% found this document useful (0 votes)
12 views2 pages

Python3 Code

Uploaded by

sakthisiva12747
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Python3 Code

Uploaded by

sakthisiva12747
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import serial #serial import for serial communications

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)

ArduinoSerial = serial.Serial('com3',9600) #Create Serial port object called


arduinoSerialData

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

distance = int(ArduinoSerial.readline()) #read the serial data and print


it as line
dist=str(distance)
print(dist)
if "where is the object" in query:
if (distance<20):
speak("StopStop, Close object in front.")

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")

You might also like