markblue777
Posts: 25
Joined: Thu Sep 01, 2016 1:59 pm
Contact:

New Google assistant SDK for python. With hotword support

Postby markblue777 » Wed May 17, 2017 5:41 pm

Just got notified of the new drop of Google assistant SDK for python that supports python.

Not tried it yet but this should sort out the activate by voice trigger everyone had been longing for (with a bit more accuracy then currently available)

https://developers.google.com/assistant/sdk/overview

Cheers
Mark
bonalybob
Posts: 12
Joined: Sun May 07, 2017 3:59 pm

Re: New Google assistant SDK for python. With hotword suppor

Postby bonalybob » Wed May 17, 2017 6:11 pm

How do you add the hotword? Has anybody tried it?

Thanks
ZooC0d3
Posts: 16
Joined: Mon May 02, 2016 9:10 am

Re: New Google assistant SDK for python. With hotword suppor

Postby ZooC0d3 » Wed May 17, 2017 11:43 pm

Not pleased to see it's currently only for Arm v7 - thereby leaving out the Pi zero which so far has performed admirably.
Disconnect
Posts: 12
Joined: Fri Nov 16, 2012 7:37 pm

Re: New Google assistant SDK for python. With hotword suppor

Postby Disconnect » Thu May 18, 2017 2:14 am

bonalybob wrote:How do you add the hotword? Has anybody tried it?
I just gave it a quick try (on pi3) and it works like a champ. I haven't integrated it with the LED blinker or the automatic start scripts but that shouldn't be too hard.
sheridat
Posts: 110
Joined: Sun May 07, 2017 11:18 am

Re: New Google assistant SDK for python. With hotword suppor

Postby sheridat » Thu May 18, 2017 8:14 am

ZooC0d3 wrote:Not pleased to see it's currently only for Arm v7 - thereby leaving out the Pi zero which so far has performed admirably.
I've been looking for an excuse to replace the piW in my AIY box with a pi 3. This seems to be it.
blackdog65
Posts: 4
Joined: Mon Sep 23, 2013 4:14 pm
Location: Cambridgeshire

Re: New Google assistant SDK for python. With hotword suppor

Postby blackdog65 » Thu May 18, 2017 8:54 am

Assuming you have the original aiyprojects setup all working on an RPi3, would it be just a simple matter of overwriting the existing assistant-sdk-python folder/contents? Or am I missing a glaringly obvious trip hazard?

I'd be interested to hear what you guys think before I try it... and have to start again from scratch :oops:
VR6Pete
Posts: 7
Joined: Sun May 14, 2017 8:10 pm

Re: New Google assistant SDK for python. With hotword suppor

Postby VR6Pete » Thu May 18, 2017 9:28 am

Hi all.

Am I correct in assuming that I can just do a GIT clone from https://github.com/google/aiyprojects-raspbian/ onto my Pi3 to get this feature?

Is there any other configuration that needs to be performed?

Cheers

Pete
ZooC0d3
Posts: 16
Joined: Mon May 02, 2016 9:10 am

Re: New Google assistant SDK for python. With hotword suppor

Postby ZooC0d3 » Thu May 18, 2017 10:04 am

sheridat wrote:I've been looking for an excuse to replace the piW in my AIY box with a pi 3. This seems to be it.
Fair enough.. I imagine it's all down to response time for hotword functionalities etc etc. I can do without it anyway.

Just sad to see that Google's first development step after release was to arbitrarily exclude older architectures - something they have a crappy track record for already. I want to decide it's too slow - not the chocolate factory.
Last edited by ZooC0d3 on Thu May 18, 2017 3:28 pm, edited 1 time in total.
ktinkerer
Posts: 35
Joined: Wed May 10, 2017 8:31 am
Contact:

Re: New Google assistant SDK for python. With hotword suppor

Postby ktinkerer » Thu May 18, 2017 10:08 am

Disconnect wrote:
bonalybob wrote:How do you add the hotword? Has anybody tried it?
I just gave it a quick try (on pi3) and it works like a champ. I haven't integrated it with the LED blinker or the automatic start scripts but that shouldn't be too hard.
How did you upgrade?
Bastiaan Slee
Posts: 7
Joined: Tue May 09, 2017 8:00 pm

Re: New Google assistant SDK for python. With hotword suppor

Postby Bastiaan Slee » Thu May 18, 2017 2:19 pm

Installation of the updated google assistant library: Within your "AIY environment" (the "Start dev terminal" from the desktop), execute this:

Code: Select all

python -m pip install --upgrade https://github.com/googlesamples/assistant-sdk-python/releases/download/0.3.0/google_assistant_library-0.0.2-py2.py3-none-linux_armv7l.whl
Now create a python file in the trigger folder, I've called it "hotword.py", contents are very simple:

Code: Select all

from triggers.trigger import Trigger
import threading
from google.assistant.library import Assistant
from google.assistant.library.event import EventType

class HotwordTrigger(Trigger):
    def __init__(self, credentials):
        self.callback = None
        self.credentials = credentials

    def set_callback(self, callback):
        self.callback = callback

    def start(self):
        threading.Thread(target=self.run_assistant).start()
             
    def run_assistant(self):
        with Assistant(self.credentials) as assistant:
            for event in assistant.start():
                if event.type == EventType.ON_CONVERSATION_TURN_STARTED:
                    break
        self.callback()
In main.py, there needs to be made some small changes to allow calling the trigger "hotword" including sending the credentials.

Within the "def do_recognition" function, add these lines below the "msg = 'Clap your hands'" line:

Code: Select all

    elif args.trigger == 'hotword':
        import triggers.hotword
        triggerer = triggers.hotword.HotwordTrigger(credentials)
        msg = 'Say "Ok Google"'
As we use "credentials" here, that needs to be added in the function header and the call of the function, scroll up and adjust accordingly:

Code: Select all

    with recorder:
        do_recognition(args, recorder, recognizer, player, credentials)

def do_recognition(args, recorder, recognizer, player, credentials):
Now your code is ready. Save the files and search for your config file in "/home/pi/.config/voice-recognizer.ini", replace

Code: Select all

# Select the trigger: gpio (default), clap.
#trigger = clap
with

Code: Select all

# Select the trigger: gpio (default), clap.
trigger = hotword
That's it, you now have a project with hotword recognition!
nervin79
Posts: 16
Joined: Sat May 06, 2017 6:44 am

Re: New Google assistant SDK for python. With hotword suppor

Postby nervin79 » Thu May 18, 2017 3:09 pm

Bastiaan Slee wrote:Installation of the updated google assistant library: Within your "AIY environment" (the "Start dev terminal" from the desktop), execute this:

Code: Select all

python -m pip install --upgrade https://github.com/googlesamples/assistant-sdk-python/releases/download/0.3.0/google_assistant_library-0.0.2-py2.py3-none-linux_armv7l.whl
I did this but it comes up saying it isn't supported on this platform. I am using a pi3. I am also using the AIY version of raspbian.
Bastiaan Slee
Posts: 7
Joined: Tue May 09, 2017 8:00 pm

Re: New Google assistant SDK for python. With hotword suppor

Postby Bastiaan Slee » Thu May 18, 2017 3:17 pm

Might python 2.7 be your default python version? (which would be strange, as the virtual environment defaults to python 3)
Try starting that line with python3 instead of python.
And just to double check, you use the Virtual Environment started from the desktop?
markblue777
Posts: 25
Joined: Thu Sep 01, 2016 1:59 pm
Contact:

Re: New Google assistant SDK for python. With hotword suppor

Postby markblue777 » Thu May 18, 2017 3:19 pm

I needed to use

Code: Select all

sudo  python3
in the update command for it to work, or else with just python I got the wheel is not supported and without sudo I got a permissions issue.

This was on a raspberry pi 2 model b by the way

Cheers
Mark
nervin79
Posts: 16
Joined: Sat May 06, 2017 6:44 am

Re: New Google assistant SDK for python. With hotword suppor

Postby nervin79 » Thu May 18, 2017 4:10 pm

I haven't changed any defaults so I hope it isn't using python 2.
sviper
Posts: 1
Joined: Thu May 18, 2017 5:05 pm

Re: New Google assistant SDK for python. With hotword suppor

Postby sviper » Thu May 18, 2017 5:07 pm

Success! Hotword detection works beautifully after enabling with instructions from Bastiaan Slee's post.
wrumble
Posts: 31
Joined: Tue Dec 27, 2016 10:18 pm

Re: New Google assistant SDK for python. With hotword suppor

Postby wrumble » Thu May 18, 2017 5:41 pm

@Bastiaan Slee Is it possible to change the hotword from 'Ok Google' to something else?
nervin79
Posts: 16
Joined: Sat May 06, 2017 6:44 am

Re: New Google assistant SDK for python. With hotword suppor

Postby nervin79 » Thu May 18, 2017 5:54 pm

Forcing python 3 got me somewhere but now i have an error on main.py
jay_s_uk
Posts: 2
Joined: Thu May 18, 2017 6:12 pm

Re: New Google assistant SDK for python. With hotword suppor

Postby jay_s_uk » Thu May 18, 2017 6:15 pm

@wrumble
Just change the first bit of code you add to main.py from "OK Google" to whatever you like.
Bastiaan Slee
Posts: 7
Joined: Tue May 09, 2017 8:00 pm

Re: New Google assistant SDK for python. With hotword suppor

Postby Bastiaan Slee » Thu May 18, 2017 6:40 pm

The assistant library is a compiled file, with a Python wrapper around it. The hotword recognition is baked inside that. Meaning we cannot tell what words to listen for.

From the Google troubleshooting page: Assistant does not seem to respond to sentences that begin with Ok Google or Hey Google. >> First, note that the hotwords are currently optimized for an American English pronunciation. Try to pronounce the hotwords in this way.
markblue777
Posts: 25
Joined: Thu Sep 01, 2016 1:59 pm
Contact:

Re: New Google assistant SDK for python. With hotword suppor

Postby markblue777 » Thu May 18, 2017 6:52 pm

what error are you getting with you main.py?
wrumble
Posts: 31
Joined: Tue Dec 27, 2016 10:18 pm

Re: New Google assistant SDK for python. With hotword suppor

Postby wrumble » Thu May 18, 2017 7:20 pm

Ok Thanks
Silverlock
Posts: 42
Joined: Wed Apr 10, 2013 3:51 am

Re: New Google assistant SDK for python. With hotword suppor

Postby Silverlock » Fri May 19, 2017 5:53 am

It took all evening but I finally got the hotword trigger working. Making the code changes was the easy part; configuring ALSA to share the microphone between (I assume) the usual Mic object in the main code and whatever was added to support the hotword trigger was the challenge. One of these days I really am going to have to sit down and figure out ALSA.

For anyone else out there who isn't using the AIY kit but has rolled their own like me, the following message in USB Audio adapter gives error when playing 2nd sound was what worked for me. I'm a little surprised that the folks with the kit aren't having the same problem, unless of course the code makes uses of the two mics in the kit to get around sharing a single mic.

The LED is handy for knowing when the code is listening for the command after saying "OK Google". There is about a second delay.

Time for more tinkering. :)
RPi3+external HDD/Raspbian/Pixel desktop
Bastiaan Slee
Posts: 7
Joined: Tue May 09, 2017 8:00 pm

Re: New Google assistant SDK for python. With hotword suppor

Postby Bastiaan Slee » Fri May 19, 2017 9:12 am

Using the same microphone for multiple tasks does indeed have limitations.

To explain what my trigger implementation technically does: it starts a session with the new SDK and listens for the hotword. When the hotword is recognized, it raises a specific event type. At that moment I directly stop this new assistant from listening and trigger the Voice Recognition as if a button was pushed. From that moment on, the existing code will start listening. This to avoid 2 programs using the same microphone (and throwing a "Segmentation fault" error).

Downside is that you don't get the Alarm and Countdown functionality. Also followup conversations don't work.

I'm building a basic Python example with the new Assistant library and the button/clap trigger. But that has it's own downside: you cannot TTS your own responses at the moment.
mattmiller
Posts: 1298
Joined: Thu Feb 05, 2015 11:25 pm

Re: New Google assistant SDK for python. With hotword suppor

Postby mattmiller » Fri May 19, 2017 1:27 pm

Thanks for instructions
Can I suggest some minor edits to make it clearer
Now create a python file in the trigger folder, I've called it "hotword.py", contents are very simple:
to
cd src/triggers and create a python file in that folder, I've called it "hotword.py", contents are very simple:

later
In main.py, there...
to
cd .. back to src folder and in main.py, there....
erwinvol
Posts: 4
Joined: Mon May 08, 2017 2:57 pm

Re: New Google assistant SDK for python. With hotword suppor

Postby erwinvol » Fri May 19, 2017 3:05 pm

I'm not able to change the hotword, detection works fine for 'Ok Google' or 'Hey Google' but I changed the msg = 'Hey Erwin' line in main.py did the restart etc but it continues to listen to the aforementioned.

Anyone has been successful in changing the hotword?