Skip to content

Instantly share code, notes, and snippets.

@monchopena
Created December 22, 2017 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monchopena/f087fbe2dd3d7303edf26d2675d8760c to your computer and use it in GitHub Desktop.
Save monchopena/f087fbe2dd3d7303edf26d2675d8760c to your computer and use it in GitHub Desktop.
Ejemplo de Programa de Arduino conectado por USB a Raspberry PI
"""A demo of the Google CloudSpeech recognizer."""
import os
import aiy.audio
import aiy.cloudspeech
import aiy.voicehat
import serial, time
def main():
arduino = serial.Serial("/dev/ttyACM0", 9600)
aiy.i18n.set_language_code('es-ES')
recognizer = aiy.cloudspeech.get_recognizer()
recognizer.expect_phrase('enciende')
recognizer.expect_phrase('apaga')
recognizer.expect_phrase('blink')
recognizer.expect_phrase('repite esto')
button = aiy.voicehat.get_button()
led = aiy.voicehat.get_led()
aiy.audio.get_recorder().start()
while True:
print('Press the button and speak')
button.wait_for_press()
print('Listening...')
text = recognizer.recognize()
if text is None:
print('Sorry, I did not hear you.')
else:
print('You said "', text, '"')
if 'apaga' in text:
led.set_state(aiy.voicehat.LED.OFF)
time.sleep(2)
arduino.write(b'b')
elif 'enciende' in text:
led.set_state(aiy.voicehat.LED.ON)
time.sleep(2)
arduino.write(b'a')
elif 'blink' in text:
led.set_state(aiy.voicehat.LED.BLINK)
time.sleep(2)
arduino.write(b'c')
elif 'repite esto' in text:
to_repeat = text.replace('repite esto', '', 1)
aiy.audio.say(to_repeat)
elif 'adiós' in text:
arduino.close()
os._exit(0)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment