Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python3
# Based in AIY Google Assistant
# Code for the snowboy hotword detector from https://bitbucket.org/dani_thomas/aiyhotworddetector
import logging
import miaHotword
from os import popen as ospopen
import aiy.assistant.grpc
import aiy.audio
import aiy.voicehat
logging.basicConfig(
level=logging.INFO,
format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s"
)
def pi_temperature():
tempCPU = int(open('/sys/class/thermal/thermal_zone0/temp').read()) / 1e3
_GPU_ = ospopen('vcgencmd measure_temp').readline();
tempGPU = _GPU_.replace("temp=","").replace("'C\n","");
say = 'CPU is at '+str(tempCPU)+' degrees and GPU is at '+str(tempGPU)+' degrees'
print(say)
aiy.audio.say(say)
def process_event(assistant,miaHot,recorder):
#change to true for not needing to repeat hotword inmedially for seconds=x
voice_only=False
seconds=5
status_ui = aiy.voicehat.get_status_ui()
status_ui.status('starting')
miaHot.waitForHotword(recorder,voice_only,seconds)
status_ui.status('listening')
print('Listening...')
text, audio = assistant.recognize()
status_ui.status('thinking')
if text is not None:
print('You said "', text, '"')
if text == 'what\'s your temperature':
pi_temperature()
audio = None
if audio is not None:
aiy.audio.play_audio(audio)
def main():
assistant = aiy.assistant.grpc.get_assistant()
miaHot=miaHotword.miaHotword()
with aiy.audio.get_recorder() as recorder:
while True:
process_event(assistant,miaHot,recorder)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.