Voice Control by Google Assistant

Install Google Assistant to Orange Pi PC equipped ARMv7l CPU to implement the commands such as searching by keyword, confirming time&date, set a timer and so on by voice. There are two important points to install it, 1. Two types of methods how to access Google API, the only Python method and the gRPC method. 2. ALSA configuration of activating the dmix and dsnoop plug-ins. If you will install it to Raspberry Pi, please check other sites.
■Target Hardware&OS
Orange Pi PC: ARMBIAN 5.25 stable Ubuntu 16.04.2 LTS 3.4.113-sun8i
■Before installing...
Need to register Google API service to make the application on your system communicate with Google.
Access to Configure a Developer Project and Account Settings in Google Assistant SDK.
https://developers.google.com/assistant/sdk/prototype/getting-started-other-platforms/config-dev-project-and-account
Follow the above procedure; 1. create your project. 2. API activation of your project. 3. Create the API authentication information(client_secret_XXXXX.json) and download it.
Next, access to Activity Controls page in Set activity controls for your account, and validate all your activities.
https://myaccount.google.com/activitycontrols
■Install Python3 SDK
To install Google Assistant SDK on Python3 virtual environment, install the following package for Python3.
$ sudo apt-get update
$ sudo apt-get install python3 python3-dev python3-venv
Prepare the virtual environment in your user directory.(the directory is optional)
$ python3 -m venv env
In the virtual environment, install and update Python pip and setuptools modules.
$ env/bin/python -m pip install --upgrade pip setuptools
Activate operation in the virtual environment. All scripts of Python are implemented in the virtual environment.
Displayed "(env)" before username on the console.
$ source env/bin/activate
(env) user@orangepipc:~$ ..........
If you want to exit from the virtual environment, please implement the following command.
(env)$ deactivate
■API Authentication(issue the certification)
Install the Python module for Google API Authentication.
(env)$ pip install --upgrade google-auth-oauthlib[tool]
Assign the client_secret_XXXXX.json downloaded before (Assign the file pass) and proceed the certification issue.
(env)$ google-oauthlib-tool --client-secrets path/to/client_secret_XXXXX.json --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save --headless
After the above command implementation, showed the address to get the code of issuing the certification.
Please visit this URL to authorize this application:https://accounts.google.com/o/oauth2/auth.........................
Access the above link address and proceed the procedure to get the code.
Completed the above procedure, displayed the code.
Enter the code at the following place on the console.
Enter the authorization code:
Got success created the certification ".config/google-oauthlib-tool/credentials.json".
■Install Google Assistant SDK, Google Assistant Library
Access the following Github page.
https://github.com/googlesamples/assistant-sdk-python
Install google-assistant-sdk.
(env)$ pip install --upgrade google-assistant-sdk
Install libraries to record and play sound and Python sample code of Google Assistant.
(env)$ sudo apt-get install portaudio19-dev libffi-dev libssl-dev
(env)$ pip install --upgrade google-assistant-sdk[samples]
Install google-assistant-library.
(env)$ pip install --upgrade google-assistant-library
■ALSA config
Mono microphone is embedded in Orange Pi PC, for using it need to create new configuration file for ALSA.
Make .asoundrc file in a user directory, contents like the following.
pcm.!default {
type asym
playback.pcm "plug:softvol"
capture.pcm "plug:dsnooper"
}
pcm.dmixer {
type dmix
ipc_key 321456 #any unique value
ipc_key_add_uid true
slave {
pcm "hw:0,0"
}
bindings {
0 0
1 1
}
}
pcm.dsnooper {
type dsnoop
ipc_key 821456
slave {
pcm "hw:0,0"
channels 2
}
bindings {
0 0
1 1
}
}
pcm.softvol {
type softvol
slave { pcm "dmixer" }
control {
name "Master"
card 0
}
}
ctl.softvol {
type hw
card 0
}
ctl.!default {
type hw
card 0
}
■Python sample codes of Google Assistant
Implement the sample code of Google Assistant SDK.
(env$) googlesamples-assistant-hotword
or, implement the demo code of Google Assistant Library.
(env)$ google-assistant-demo
Confirm whether to detect the voice "OK Google" or "Hey Google" hot words.
(env)$ googlesamples-assistant-hotword
ON_MUTED_CHANGED:
{'is_muted': False}
ON_START_FINISHED
Displayed the below words, got success the detection of voice.
ON_CONVERSATION_TURN_STARTED
Voice of "weather", output the weather information from the speaker.
ON_END_OF_UTTERANCE
ON_RECOGNIZING_SPEECH_FINISHED:
{'text': 'weather'}
ON_RESPONDING_STARTED:
{'is_error_response': False}
ON_RESPONDING_FINISHED
ON_CONVERSATION_TURN_FINISHED:
{'with_follow_on_turn': False}
■gRPC API of Google Assistant
If you want to use gRPC API, install the below package.
(env)$ pip install --upgrade google-assistant-grpc
Sample code for gRPC API of Google Assistant already has installed when you installed google-assistant-sdk sample codes.
(env)$ googlesamples-assistant-pushtotalk
In the case of gRPC, adopted the same .asoundrc file as the demo and the hotword sample commands.