Created
February 14, 2018 08:45
-
-
Save Tiriree/73e13d8b75e55508451e14acb6fdc97b to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python3 | |
#tiri for voice class | |
import logging | |
import subprocess | |
import sys | |
import aiy.assistant.auth_helpers | |
import aiy.audio | |
import aiy.voicehat | |
from google.assistant.library import Assistant | |
from google.assistant.library.event import EventType | |
logging.basicConfig( | |
level=logging.INFO, | |
format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s" | |
) | |
def say(something): | |
aiy.audio.say(something) | |
def power_off_pi(): | |
say('Good bye!') | |
subprocess.call('sudo shutdown now', shell=True) | |
def reboot_pi(): | |
say('See you in a bit!') | |
subprocess.call('sudo reboot', shell=True) | |
def say_ip(): | |
ip_address = subprocess.check_output("hostname -I | cut -d' ' -f1", shell=True) | |
say('My IP address is %s' % ip_address.decode('utf-8')) | |
def seb(): | |
say('so tramposo!') | |
subprocess.call('chromium-browser -kiosk http://sebseb.cc', shell=True) | |
def tiri(): | |
say('Teeri') | |
subprocess.call('chromium-browser -kiosk https://tisch.nyu.edu/itp/itp-people/current-students/tiri', shell=True) | |
def yes(): | |
say('yes!') | |
subprocess.call('chromium-browser -kiosk https://giphy.com/gifs/partydownsouth-party-down-south-3oEdvbQ9SwvLaZTY40', shell=True) | |
def process_event(assistant, event): | |
status_ui = aiy.voicehat.get_status_ui() | |
if event.type == EventType.ON_START_FINISHED: | |
status_ui.status('ready') | |
if sys.stdout.isatty(): | |
print('Say "OK, Google" then speak, or press Ctrl+C to quit...') | |
elif event.type == EventType.ON_CONVERSATION_TURN_STARTED: | |
status_ui.status('listening') | |
elif event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED and event.args: | |
print('You said:', event.args['text']) | |
text = event.args['text'].lower() | |
if text == 'power off': | |
assistant.stop_conversation() | |
power_off_pi() | |
elif text == 'reboot': | |
assistant.stop_conversation() | |
reboot_pi() | |
elif text == 'ip address': | |
assistant.stop_conversation() | |
say_ip() | |
elif text == 'this guy': | |
assistant.stop_conversation() | |
seb() | |
elif text == 'sebastian': | |
assistant.stop_conversation() | |
seb() | |
elif text == 'who is an angel': | |
assistant.stop_conversation() | |
tiri() | |
elif text == 'who is the best fortune teller': | |
assistant.stop_conversation() | |
tiri() | |
elif text == 'who is so sleepy now': | |
assistant.stop_conversation() | |
tiri() | |
elif text == 'show me future': | |
assistant.stop_conversation() | |
yes() | |
elif event.type == EventType.ON_END_OF_UTTERANCE: | |
status_ui.status('thinking') | |
elif event.type == EventType.ON_CONVERSATION_TURN_FINISHED: | |
status_ui.status('ready') | |
elif event.type == EventType.ON_ASSISTANT_ERROR and event.args and event.args['is_fatal']: | |
sys.exit(1) | |
def main(): | |
credentials = aiy.assistant.auth_helpers.get_assistant_credentials() | |
with Assistant(credentials) as assistant: | |
for event in assistant.start(): | |
process_event(assistant, event) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment