speech control LED script
This commit is contained in:
parent
1b6ea0cded
commit
7302f3b2b3
28
py/speech_coltrol_led.py
Normal file
28
py/speech_coltrol_led.py
Normal file
@ -0,0 +1,28 @@
|
||||
import speech_recognition as sr
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
|
||||
LED_PIN = 17
|
||||
|
||||
# GPIO setup
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(LED_PIN, GPIO.OUT)
|
||||
|
||||
def trigger_action(command):
|
||||
if "turn on the light" in command.lower():
|
||||
GPIO.output(LED_PIN, GPIO.HIGH)
|
||||
print("Light ON")
|
||||
elif "turn off the light" in command.lower():
|
||||
GPIO.output(LED_PIN, GPIO.LOW)
|
||||
print("Light OFF")
|
||||
|
||||
recognizer = sr.Recognizer()
|
||||
with sr.Microphone() as source:
|
||||
print("Say a command...")
|
||||
audio = recognizer.listen(source)
|
||||
try:
|
||||
cmd = recognizer.recognize_sphinx(audio)
|
||||
print("Command: {}".format(cmd))
|
||||
trigger_action(cmd)
|
||||
except sr.UnknownValueError:
|
||||
print("Could not understand audio.")
|
||||
Loading…
x
Reference in New Issue
Block a user