documentation finalized. Added comments to scripts. Updated README. Updated latex source files.
This commit is contained in:
parent
b62a5a06f6
commit
bc166715b7
Binary file not shown.
BIN
pilight.pdf
Normal file
BIN
pilight.pdf
Normal file
Binary file not shown.
@ -1,11 +1,12 @@
|
|||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
import time
|
import time
|
||||||
|
|
||||||
LED_PIN = 17
|
LED_PIN = 17 # GPIO phisical pin
|
||||||
|
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
GPIO.setup(LED_PIN, GPIO.OUT)
|
GPIO.setup(LED_PIN, GPIO.OUT)
|
||||||
|
|
||||||
|
# Alternate every second, turning an LED on and off. Stopped by CTRL+C
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
GPIO.output(LED_PIN, GPIO.HIGH)
|
GPIO.output(LED_PIN, GPIO.HIGH)
|
||||||
|
|||||||
@ -2,9 +2,11 @@ import speech_recognition as sr
|
|||||||
|
|
||||||
recognizer = sr.Recognizer()
|
recognizer = sr.Recognizer()
|
||||||
with sr.Microphone() as source:
|
with sr.Microphone() as source:
|
||||||
|
# audio input
|
||||||
print("Say something...")
|
print("Say something...")
|
||||||
audio = recognizer.listen(source)
|
audio = recognizer.listen(source)
|
||||||
try:
|
try:
|
||||||
|
# runs the live recored audio through PocketSphinx and print it as text
|
||||||
text = recognizer.recognize_sphinx(audio)
|
text = recognizer.recognize_sphinx(audio)
|
||||||
print("Sphinx recognized: {}".format(text))
|
print("Sphinx recognized: {}".format(text))
|
||||||
except sr.UnknownValueError:
|
except sr.UnknownValueError:
|
||||||
|
|||||||
@ -2,25 +2,30 @@ import speech_recognition as sr
|
|||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
import time
|
import time
|
||||||
|
|
||||||
LED_PIN = 17
|
LED_PIN = 17 # Number of GPIO physical pin
|
||||||
|
|
||||||
# GPIO setup
|
# GPIO setup
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
GPIO.setup(LED_PIN, GPIO.OUT)
|
GPIO.setup(LED_PIN, GPIO.OUT)
|
||||||
|
|
||||||
|
# turn LED on or off with correct command
|
||||||
def trigger_action(command):
|
def trigger_action(command):
|
||||||
|
# turn LED on with command fire
|
||||||
if "fire" in command.lower():
|
if "fire" in command.lower():
|
||||||
GPIO.output(LED_PIN, GPIO.HIGH)
|
GPIO.output(LED_PIN, GPIO.HIGH)
|
||||||
print("Light ON")
|
print("Light ON")
|
||||||
|
# turn LED off with command night
|
||||||
elif "night" in command.lower():
|
elif "night" in command.lower():
|
||||||
GPIO.output(LED_PIN, GPIO.LOW)
|
GPIO.output(LED_PIN, GPIO.LOW)
|
||||||
print("Light OFF")
|
print("Light OFF")
|
||||||
|
|
||||||
recognizer = sr.Recognizer()
|
recognizer = sr.Recognizer()
|
||||||
with sr.Microphone() as source:
|
with sr.Microphone() as source:
|
||||||
|
# audio input
|
||||||
print("Say a command...")
|
print("Say a command...")
|
||||||
audio = recognizer.listen(source)
|
audio = recognizer.listen(source)
|
||||||
try:
|
try:
|
||||||
|
# runs the live recored audio through PocketSphinx. Send the iterpreted audio as text to function trigger_action
|
||||||
cmd = recognizer.recognize_sphinx(audio)
|
cmd = recognizer.recognize_sphinx(audio)
|
||||||
print("Command: {}".format(cmd))
|
print("Command: {}".format(cmd))
|
||||||
trigger_action(cmd)
|
trigger_action(cmd)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user