we are currently using this line of code to open a Solenoid lock using voice activation, however it is taking forever to recognize and is tuck on ‘listening’. How would we make it faster?
or if we were to use an offline speech recognition, what is the code that will yield the same function?
this is operated in a raspberry pi 3 through python and executed through cd Desktop
or if we were to use an offline speech recognition, what is the code that will yield the same function?
this is operated in a raspberry pi 3 through python and executed through cd Desktop
import RPi.GPIO as GPIO import time import speech_recognition as sr Configure Varaibles command = “” password = “open this door please” voiceOK = False r = sr.Recognizer() Configure GPIO solenoidPin = 4 GPIO.setmode(GPIO.BCM) GPIO.setup(solenoidPin, GPIO.OUT) GPIO.output(solenoidPin, GPIO.LOW) while(1): with sr.Microphone() as source: Copy to clipboard voiceOK = False # Keep running until the voice is understood by Google while(voiceOK == False): print("Speak:") audio = r.listen(source) try: speechString = r.recognize_google(audio) print(speechString) voiceOK = True except sr.UnknownValueError: print("Could not understand audio") except sr.RequestError as e: print("Could not request results; {0}".format(e)) # Determine if the password is correct if(speechString == password): GPIO.output(solenoidPin, GPIO.HIGH) print("ACCESS GRANTED") time.sleep(2) GPIO.output(solenoidPin, GPIO.LOW) else: print("ACCESS DENIED")