Raspberry PI 3: Voice CODING HELP

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 stuck 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

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.setup(solenoidPin, GPIO.OUT)
GPIO.output(solenoidPin, GPIO.LOW)

    with sr.Microphone() as source:                                            

        voiceOK = False

        # Keep running until the voice is understood by Google
        while(voiceOK == False):

            audio = r.listen(source)

                speechString = r.recognize_google(audio)
                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")
            GPIO.output(solenoidPin, GPIO.LOW)
            print("ACCESS DENIED")

@boypablo, Correct, an offline speech recognition would yield a faster result, after googling “offline voice recognition” i found this project that might interest you:

You will have to spend some time rewriting your application, just take a look at their demo applications for the PI for reference.