Close

Double-Tap

A project log for VoiceBox

Adding a Flask web interface (and other stuff) to the Google AIY Voice Kit.

tmTM 08/06/2018 at 21:530 Comments

A bit out of sequence, as I haven't covered cooling fan control or music streaming yet, but today I added a double-tap feature to VoiceBox.py.

DOUBLEPRESS = 1.0 # Button is double-pressed if twice within 1 second
def button_wait_thread():
    global last_button_time
    button = aiy.voicehat.get_button()
    while mode != 'quit':
        button.wait_for_press()
        button_press_time = time.time()
        if button_press_time - last_button_time < DOUBLEPRESS:
            print('Double-press, killing music and fan')
            fan('off', quiet=True)   # switch off fan without fanfare
            music('off', quiet=True)
        else:
            print('Button pressed, enabling mic')
            response = requests.get('http://localhost:9011/button')
        last_button_time = button_press_time

So, if the button is pressed twice within a second, the music and cooling fan are switched off. I added this feature because when the fan is on, and the radio announcer is talking, Google Assistant can really struggle to understand commands (such as "music off" and "cooling fan off"!).

Before the fix, I was using  the GPIO control tab of piHole at <your-pi's-ip-address>:9012/gpio to switch off the "COOLING FAN". If the radio got really loud I'd have to ssh in and "mpc stop" from the command line to kill the radio manually.

Discussions