Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handle(phrase):
"""
Process the phrase recognized by Pocketsphinx.
Toggle the relay switch connected to GPIO 18 when 'light' is said.
"""
print('Heard: {}'.format(phrase))
if bool(re.search(r'\blight on\b', phrase, re.IGNORECASE)):
GPIO.output(18, GPIO.LOW)
if bool(re.search(r'\blight off\b', phrase, re.IGNORECASE)):
GPIO.output(18, GPIO.HIGH)
try:
# Call "Judy" to get her attention, then say something (within the vocabulary).
judy.listen(vin, vout, handle)
except KeyboardInterrupt:
# Release the GPIO pin.
GPIO.cleanup()