Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CODING HELP
#1
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

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")
Reply
#2
You may need to calibrate for particular words. see: https://github.com/Uberi/speech_recognit...reshold.py
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020