I’ve been playing with Google AIY on raspberry pi for nearly an hour now and I love it. If you are lucky you can get your kit from issue 57 of The MagPi Magazine.
Google provided a python based example app that recognises the command you spoke to the box and runs your action. The problem with it is that the command needs to match literally without and option to add variable part (a parameter). In real world I want to give parameters to the commands, for example “Add note my note“. So I’ve hacked the app to do just that. Here are the steps:
1. Modify the actionbase.py to recognize patterns. In class class KeywordHandler(object): change the handle method:
"""Perform the action when the given keyword is in the command."""
def __init__(self, keyword, action):
self.keyword = keyword.lower()
self.action = action
def handle(self, command):
if("*" in self.keyword):
match = re.match(self.keyword.lower(), command.lower())
if self.keyword in command.lower():
2. Make sure the action you are running understands that the param given to it is the variable part. I’ve modified the SpeakAction to do just that:
"""Says the given text via TTS."""
def __init__(self, say, words):
self.say = say
self.words = words
def run(self, voice_command):
3. Add new action in make_actor method:
actor.add_keyword(_('add note (.*)'),SpeakAction(say,"adding $1"))