t1m0thyj / AssistantPi

Unofficial installer for Google Assistant on Raspbian
36 stars 7 forks source link

Adding local custom commands to AssistantPi #14

Closed Colin1964 closed 6 years ago

Colin1964 commented 6 years ago

Trying to use this code and followed the instructions by @RichardBronsky. I am editing the AssistantPi.py file located in /home/pi/AIY-projects-python/src to include the local custom commands. I reboot the Pi with the changes made to the file but the local commands do not work. Not sure this is relevant to my issue but I did notice that the original AssistantPi.py file has this code def say_ip(): ip_address = subprocess.check_output("hostname -I | cut -d' ' -f1", shell=True) aiy.audio.say('My IP address is %s' % ip_address.decode('utf-8')) however the response I get from "OK Google, what's my IP?" is "Your Public IP address is 144.123........" and not "My IP address is..." Also none of the "reboot", "shutdown" commands work either so it seems like the AssistantPi.py file is not even being used. Am I editing the right .py file and if so do I have to manually run the file?

t1m0thyj commented 6 years ago

It sounds like you are editing the right .py file, make sure that the phrases you say are exactly identical to the phrases in the `if text == "{phrase}" lines in the code. If I say "Ok Google, what's my IP", I get the same response as you, but if I say the exact phrase "Ok Google, IP address" then the local command works and is in a different voice.

Colin1964 commented 6 years ago

@t1m0thyj thanks. I will give this a try when I get home.

Colin1964 commented 6 years ago

Ok so i tried saying exactly what is in the {phrase] i.e. just the words "OK Google, IP address" but still getting no response at all. I'm wondering if I need to install/activate some other voice recogniser or speech engine for this. You say when you get the local command response it is in a different voice. Is your setup unchanged from the standard install or did you add any custom pieces. It seems strange that the .py file is being called correctly by the AIY service and the Pi responds perfectly to all other commands yet none of the custom commands seem to work? I am running my Pi in headless mode - could that be anything to do with it? Is your Pi connected to a screen or headless?

Colin1964 commented 6 years ago

I decided to try and run AssistantPi in a console via VNC and I seem to be making progress. After the initial install I have always used the Assistant in auto run mode i.e via the Service when the Pi boots up. I've never tried to manually start the thing - it has always just worked when I turn the Pi on! SO.. I'm not entirely convinced I have got the manual starting process fully correct but here's what I did.

First of all CD'd to AIY-projects-python directory and stopped the service with: `sudo service AssistantPi stop"

Then activated dev environment with source env/bin/activate and started AssistantPi using Python src/AssistantPi.py

Now I was getting output to the console as well as speech. I asked a quick test question about Greece first (worked fine) and then said "OK Google, IP address" and below is the error output:

(env) pi@raspberrypi:~/AIY-projects-python $ python src/AssistantPi.py ON_MUTED_CHANGED: {'is_muted': False} /home/pi/AIY-projects-python/src/aiy/_drivers/_led.py:51: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(channel, GPIO.OUT) ON_START_FINISHED Say "OK, Google" then speak, or press Ctrl+C to quit... ON_CONVERSATION_TURN_STARTED ON_END_OF_UTTERANCE ON_RECOGNIZING_SPEECH_FINISHED: {'text': 'tell me about Greece'} You said: tell me about Greece ON_RESPONDING_STARTED: {'is_error_response': False} ON_RESPONDING_FINISHED ON_CONVERSATION_TURN_FINISHED: {'with_follow_on_turn': False} ON_CONVERSATION_TURN_STARTED ON_END_OF_UTTERANCE ON_RECOGNIZING_SPEECH_FINISHED: {'text': 'IP address'} You said: IP address /bin/sh: 1: pico2wave: not found aplay: playback:2787: read error Traceback (most recent call last): File "src/AssistantPi.py", line 110, in main() File "src/AssistantPi.py", line 106, in main process_event(assistant, event) File "src/AssistantPi.py", line 81, in process_event say_ip() File "src/AssistantPi.py", line 53, in say_ip aiy.audio.say('My IP address is %s' % ip_address.decode('utf-8')) File "/home/pi/AIY-projects-python/src/aiy/audio.py", line 133, in say tts.say(words, lang=lang, volume=volume, pitch=pitch) File "/home/pi/AIY-projects-python/src/aiy/voice/tts.py", line 37, in say subprocess.check_call(cmd, shell=True) File "/usr/lib/python3.5/subprocess.py", line 271, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command 'pico2wave --wave /tmp/bd64423545464e8fad5e7fb5db46fc6f.wav --lang en-US "My IP address is 192.168.1.94 " | aplay -D default -' returned non-zero exit status 1 Segmentation fault

It looks like it can't find pico2wave. Is this required just for the local commands and if so how/where do I need to install this?

Colin1964 commented 6 years ago

OK that was easier than I thought.

Installed pico2wav using sudo apt-get install libttspico-utils and now everything is working perfectly. Normal Google voice response when asking standard commands and now the slightly robot version of her voice when responding to local commands. Now off to write some spooky halloween commands!!! @t1m0thyj thanks for all the help and maybe this will help anyone else having the same problem.

t1m0thyj commented 6 years ago

Glad you were able to figure it out, I'll add a line to install.sh to install that package. When I wrote this script I had already set up Assistant on my Pi previously so I missed some of the dependencies.

t1m0thyj commented 6 years ago

Added the libttspico-utils package to install.sh