All Projects → androidthings → Sample Googleassistant

androidthings / Sample Googleassistant

Licence: apache-2.0
Google Assistant API sample for Android Things

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Sample Googleassistant

Sample Simplepio
Basic Peripheral I/O examples with Android Things
Stars: ✭ 191 (-58.48%)
Mutual labels:  android-things
atdocs
Android Things Translation 中文翻译
Stars: ✭ 19 (-95.87%)
Mutual labels:  android-things
sample-uartloopback
Echo received characters over a UART with Android Things
Stars: ✭ 71 (-84.57%)
Mutual labels:  android-things
photobooth
Cloud-connected talking photobooth using TensorFlow
Stars: ✭ 40 (-91.3%)
Mutual labels:  android-things
androidthings-mqtt-alarm-panel
Android Things Alarm Control Panel for Home Assistant
Stars: ✭ 69 (-85%)
Mutual labels:  android-things
androidthings-weatherstation
Codelab and solution for the Android Things Weatherstation
Stars: ✭ 16 (-96.52%)
Mutual labels:  android-things
Drivers Samples
Peripheral driver samples
Stars: ✭ 153 (-66.74%)
Mutual labels:  android-things
Doorbell
Cloud-based photo doorbell with companion app
Stars: ✭ 298 (-35.22%)
Mutual labels:  android-things
edison-candle
Production sample using Android Things
Stars: ✭ 42 (-90.87%)
Mutual labels:  android-things
native-libandroidthings
NDK library for exposing Peripheral I/O APIs in C/C++
Stars: ✭ 28 (-93.91%)
Mutual labels:  android-things
FRILLER
FRILLER is a 3D printed compact robot that can change the radius of its wheels to overcome obstacles.
Stars: ✭ 15 (-96.74%)
Mutual labels:  android-things
Fool
Simple Russian voice assistant based on Android Things and Raspberry Pi 3
Stars: ✭ 26 (-94.35%)
Mutual labels:  android-things
android-things-rc522
Android library to communicate with RFID Module RC522
Stars: ✭ 44 (-90.43%)
Mutual labels:  android-things
Weatherstation
Sensor-based peripheral sample using Android Things
Stars: ✭ 210 (-54.35%)
Mutual labels:  android-things
android-things-samples
Samples and projects for platforms running Android Things
Stars: ✭ 23 (-95%)
Mutual labels:  android-things
Sample Bluetooth Le Gattserver
Build a Bluetooth GATT server with Android Things
Stars: ✭ 159 (-65.43%)
Mutual labels:  android-things
sensorhub-cloud-iot
Sensor-based data collection device publishing to Cloud IoT Core
Stars: ✭ 73 (-84.13%)
Mutual labels:  android-things
Lantern
Transform any surface into mixed-reality using Raspberry Pi, a laser projector, and Android Things.
Stars: ✭ 403 (-12.39%)
Mutual labels:  android-things
New Project Template
Stars: ✭ 265 (-42.39%)
Mutual labels:  android-things
ThingsCommander
Things Commander System, based on Android Things developer preview 2
Stars: ✭ 13 (-97.17%)
Mutual labels:  android-things

Google Assistant SDK for devices - Android Things

This sample shows how to call the Google Assistant Service from Android Things using gRPC. It records a spoken request from the connected microphones, sends it to the Google Assistant API and plays back the Assistant's spoken response on the connected speaker.

Pre-requisites

Run the sample

  1. Create or open a project in the Actions Console
  2. Follow the instructions to register a device model
  3. Download client_secret_XXXX.json
  4. Install the google-oauthlib-tool in a Python 3 virtual environment:
python3 -m venv env
env/bin/python -m pip install --upgrade pip setuptools
env/bin/pip install --upgrade google-auth-oauthlib[tool]
source env/bin/activate
google-oauthlib-tool --client-secrets client_secret_XXXX.json \
                     --credentials app/src/main/res/raw/credentials.json \
                     --scope https://www.googleapis.com/auth/assistant-sdk-prototype \
                     --save
  • Make sure to set the Activity Controls for the Google Account using the application.
  • On the first install, grant the sample required permissions for audio and internet access:
./gradlew assembleDebug
adb install -g app/build/outputs/apk/debug/app-debug.apk
  • On Android Studio, click on the "Run" button or on the command line, type:
./gradlew installDebug
adb shell am start com.example.androidthings.assistant/.AssistantActivity
  • Try the assistant demo:

    • Press the button: recording starts.
    • Ask a question in the microphone. After your question is finished, recording will end.
    • The Google Assistant answer should playback on the speaker.

Audio Configuration

By default the sample routes audio to the I2S Voice Hat on Raspberry Pi 3 and default audio on other boards (on-board Line out or HDMI/USB if connected).

You can change those mappings by changing the USE_VOICEHAT_I2S_DAC constant or replacing the audio configuration in the onCreate method of AssistantActivity with one of the following:

// Force using on-board Line out:
audioInputDevice = findAudioDevice(AudioManager.GET_DEVICES_INPUTS, AudioDeviceInfo.TYPE_BUILTIN_MIC);
audioOutputDevice = findAudioDevice(AudioManager.GET_DEVICES_OUTPUTS, AudioDeviceInfo.TYPE_BUILTIN_SPEAKER);

// Force using USB:
audioInputDevice = findAudioDevice(AudioManager.GET_DEVICES_INPUTS, AudioDeviceInfo.TYPE_USB_DEVICE);
audioOutputDevice = findAudioDevice(AudioManager.GET_DEVICES_OUTPUTS, AudioDeviceInfo.TYPE_USB_DEVICE);

// Force using I2S:
audioInputDevice = findAudioDevice(AudioManager.GET_DEVICES_INPUTS, AudioDeviceInfo.TYPE_BUS);
audioOutputDevice = findAudioDevice(AudioManager.GET_DEVICES_OUTPUTS, AudioDeviceInfo.TYPE_BUS);

Device Actions

With Device Actions, you can control hardware connected to your device. In this sample, you can turn on and off the LED attached to your Android Things board.

Follow the guide here to learn how to register your device.

  • After you register your device model and id, replace the device model and instance PLACEHOLDER values in AssistantActivity:
private static final String DEVICE_MODEL_ID = "my-device-model-id";
private static final String DEVICE_INSTANCE_ID = "my-device-instance-id";
  • Handle a Device Actions response if you get one.
mEmbeddedAssistant = new EmbeddedAssistant.Builder()
    ...
    .setConversationCallback(new ConversationCallback() {
        ...
        @Override
        public void onDeviceAction(String intentName, JSONObject parameters) {
            // Check the type of command
            if (intentName.equals("action.devices.commands.OnOff")) {
                try {
                    boolean turnOn = parameters.getBoolean("on");
                    mLed.setValue(turnOn);
                } catch (JSONException e) {
                    Log.e(TAG, "Cannot get value of command", e);
                } catch (IOException e) {
                    Log.e(TAG, "Cannot set value of LED", e);
                }
            }
        }
    }
    ...
...

Try it:

  • "Turn on"
  • "Turn off"

The LED should change states based on your command.

Enable auto-launch behavior

This sample app is currently configured to launch only when deployed from your development machine. To enable the main activity to launch automatically on boot, add the following intent-filter to the app's manifest file:

<activity ...>

    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.HOME"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>

</activity>

License

Copyright 2017 The Android Open Source Project, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].