xtools-at / AssistantPi

Bring both Google Assistant and Alexa to your Raspberry Pi
MIT License
490 stars 50 forks source link
alexa alexa-voice-service alexapi artificial-intelligence assistant google-assistant google-assistant-api google-assistant-sdk google-home raspberry raspberry-pi raspberrypi raspbian smarthome voice-commands

AssistantPi

AssistantPi is basically a tweak of AlexaPi allowing you to run Google Assistant and Amazon's Alexa on a Raspberry Pi. It includes the Google Assistant SDK and uses AlexaPi's hotword recognition to activate either Assistant or Alexa. The installer provides an easy way to get everything set up in just under an hour.

This is just an experimental proof-of-concept without broad support.

Credits / Further Resources:

Requirements

You will need:

  1. A Raspberry Pi and an SD Card with a fresh install of Raspbian Jessie Lite
  2. Audio peripherals:
    • external speaker with 3.5mm Jack
    • USB microphone

Installation

Updating

Bringing your AssistantPi up-to-date is just one command away:

sudo bash /opt/AlexaPi/src/scripts/update.sh

This updates both AssistantPi and the tweaked Assistant SDK without having you to go through the installation process again.

Important Notice: If installed before May 13th 2017 for the first time, please run the setup again after the update and do the Authentication with both Google and Amazon again.

Debugging

To start AssistantPi in debugging mode, stop the service (if running) and run the script with the -d flag:

sudo systemctl stop AlexaPi.service
python /opt/AlexaPi/src/main.py -d

To start the embedded Google Assistant SDK, run

/opt/AlexaPi/env/bin/python -m googlesamples.assistant --credentials /etc/opt/AlexaPi/assistant_credentials.json

# same as running
### source /opt/AlexaPi/env/bin/activate
### python -m googlesamples.assistant --credentials /etc/opt/AlexaPi/assistant_credentials.json

and type assistant_record into the prompt to start a conversation. For more information on Assistant Troubleshooting, check here.

Audio Settings

The base audio config is done for you in the setup for both AlexaPi and Assistant. However, if encountering any audio issues in playback or recording, make sure to check by here:

If Google Assistant audio output is choppy or truncated, check the following. Make sure to run source /opt/AlexaPi/env/bin/activate before running the samples there, to target AssistantPi's Python environment.

You can set the values for the Block- and Flush size in the AssistantPi config, either before Installation in /opt/AlexaPi/src/config.template.yaml or afterwards in /etc/opt/AlexaPi/config.yaml. Go find the attribute sound > assistant and use your values for block_size and flush_size.

Make sure you've been to sudo raspi-config, Advanced Options > Audio and have set the desired audio output (i.e. 3.5mm Jack, not HDMI).

Change Hotwords

To change the hotwords (currently Alexa and Google), either change both these files before running the setup:

.../src/config.template.yaml (phrase and phrase_assistant) and .../src/keyphrase.list

or /etc/opt/AlexaPi/config.yaml and /opt/AlexaPi/src/keyphrase.list after setup.

In the config.yaml, you may use a single String or an Array of Strings for your phrase_assistant (only). Every string there will trigger Assistant, everything else in your keyphrase.list will trigger Alexa.

In the keyphrase.list, you can also tweak the sensitivity of the hotword recognition. From the CMUSphinx Wiki:

Threshold must be tuned for every keyphrase on a test data to get the right balance missed detections and false alarms. You can try values like 1e-5 to 1e-50. For the best accuracy it is better to have keyphrase with 3-4 syllables. Too short phrases are easily confused.

You can also combine wakewords, e.g. "ok google" and/or "hey google". Also make sure that your new hotwords are included in the language model. Check the following directory for a file with .dict or .dic extension and add your hotwords if not already there: /usr/local/lib/python2.7/dist-packages/pocketsphinx/model/

Change Hotword language

The default language coming with Pocketsphinx for the hotword recognition is US English. If you want to change it (which might be necessary if your hotwords aren't recognized well), head over to CMUSphinx Downloads page and get the model files for your language. In particular, you have to place the following files

in /usr/local/lib/python2.7/dist-packages/pocketsphinx/model/ and the contents of

in /usr/local/lib/python2.7/dist-packages/pocketsphinx/model/[lng-lng] (where [lng-lng] is the language code of your imported language, e.g. 'de-de')

Make sure, that FILENAME.dic contains your desired hotwords (i.e. Alexa and Google for default settings), if not, add them.

Afterwards,

Install German language package

find pocketsphinx > language, change to 'de-de'

find pocketsphinx > dictionary, change to 'cmusphinx-voxforge-de.dic'