Last active
September 23, 2020 15:04
-
-
Save gravitymonkey/e2eea4c2f014c87ca4b12454fa47882c to your computer and use it in GitHub Desktop.
script to play with google's AIY voice device
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2017 Google Inc. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
import aiy.audio | |
import aiy.cloudspeech | |
import aiy.voicehat | |
import aiy.tts | |
import requests | |
import os | |
def main(): | |
CAMERA_LIGHT_ON =os.environ['CAMERA_LIGHT_ON'] | |
print(CAMERA_LIGHT_ON) | |
CAMERA_LIGHT_OFF = os.environ['CAMERA_LIGHT_OFF'] | |
print(CAMERA_LIGHT_OFF) | |
aiy.audio.say("ok, reloading from gist", volume=25, pitch=55) | |
button = aiy.voicehat.get_button() | |
led = aiy.voicehat.get_led() | |
aiy.audio.get_recorder().start() | |
recognizer = aiy.cloudspeech.get_recognizer() | |
recognizer.expect_phrase('goodbye') | |
aiy.audio.play_wave("./yo.wav") | |
while True: | |
print('Press the button and speak') | |
aiy.audio.say("Yo-bot is ready. Press the button and speak.", volume=15, pitch=50) | |
button.wait_for_press() | |
led.set_state(aiy.voicehat.LED.ON) | |
print('Listening...') | |
text = recognizer.recognize() | |
led.set_state(aiy.voicehat.LED.BLINK) | |
if not text: | |
led.set_state(aiy.voicehat.LED.OFF) | |
aiy.audio.play_wave("./umm.wav") | |
elif text.lower().strip() == 'light up the sky' or text.lower().strip() == 'zoom light on': | |
r = requests.get(CAMERA_LIGHT_ON) | |
print(r.text) | |
aiy.audio.say("yo-bot turns the light on", volume=25, pitch=60) | |
elif text.lower().strip() == 'leave it all behind' or text.lower().strip() == 'zoom light off': | |
r = requests.get(CAMERA_LIGHT_OFF) | |
print(r.text) | |
aiy.audio.say("yo-bot turns the light off", volume=25, pitch=60) | |
elif text.lower().strip() == 'goodbye': | |
led.set_state(aiy.voicehat.LED.OFF) | |
aiy.audio.say("yo-bot is turning off now", volume=25, pitch=45) | |
print(text) | |
break | |
else: | |
led.set_state(aiy.voicehat.LED.OFF) | |
aiy.audio.play_wave("./yo.wav") | |
aiy.audio.say(text, volume=25, pitch=60) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment