How to execute python code to raspberry pi 3


The codes are already premade, and I’m clueless on how to execute it via python.

for code reference, here’s the link for the actual project.


@arsenio_4112, grab the full file and copy to the PI in a file name…

Then install these dependices (assuming Raspbian)

sudo apt update
sudo apt upgrade
sudo apt install python3-rpi.gpio python3-setuptools python3-pip python3-pyaudio

sudo pip3 install SpeechRecognition

Then just run the demo example…

python3 ./
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")