Uladzislau Bayouski
Published © MIT

Vox: The Google Assistant

Are you interested in learning Google Assistant API? Do not know where to start? Assemble It Yourself (AIY) Google Voice kit is an answer!

BeginnerFull instructions provided2 hours2,120
Vox: The Google Assistant

Things used in this project

Hardware components

AIY Voice
Google AIY Voice
×1
Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Micro SD Card 8GB+
×1

Software apps and online services

Raspbian
Raspberry Pi Raspbian
Python
Microsoft Visual Studio 2017
Assistant SDK
Google Assistant SDK

Story

Read more

Schematics

Raspberry Pi 3

Raspberry Pi GPIO/Pins Scheme

Code

Custom commands python script

Python
Demonstrates custom commands and interactions with other devices, like home network and other smart devices
#!/usr/bin/env python3

import aiy.assistant.grpc
import aiy.audio
import aiy.voicehat
import subprocess
import RPi.GPIO as GPIO  

def main():
    status_ui = aiy.voicehat.get_status_ui()
    status_ui.status('starting')
    assistant = aiy.assistant.grpc.get_assistant()
    button = aiy.voicehat.get_button()
    with aiy.audio.get_recorder():
        while True:
            status_ui.status('ready')
            print('Press the button and speak')
            button.wait_for_press()
            status_ui.status('listening')
            print('Listening...')
            text, audio = assistant.recognize()
            if text:
                print('You said {}'.format(text))
                if text == 'power off':
                    status_ui.status('stopping')
                    aiy.audio.say('Goodbye!', volume=20)
                    subprocess.call('sudo shutdown -h now', shell=True)
                    break
                if text == 'reboot':
                    status_ui.status('stopping')
                    aiy.audio.say('See you soon!', volume=20)
                    subprocess.call('sudo reboot', shell=True)
                    break
                if text == 'weather station':
                    # Here goes your logic to handle custom command.
                    # In my case I connect to my weather station and get its readings.
                    # aiy.audio.say('Readings result', volume=20)
                    continue
            if audio:
                aiy.audio.play_audio(audio, assistant.get_volume())

    GPIO.cleanup()  

if __name__ == '__main__':
    main()

API libraries, samples, and system images for AIY Projects

This repository contains an easy-to-use API for the AIY Kits.

Credits

Uladzislau Bayouski

Uladzislau Bayouski

6 projects • 70 followers

Comments