/google-assistant-java-demo

A simple Google Assistant Client in Java

Primary LanguageJavaGNU General Public License v3.0GPL-3.0

Assistant-Java

Goal

A simple client - demo project for the Google Assistant SDK.

This project was built and tested on a Mac with OpenJDK 18

Version

This README file is written for the latest version. Checkout the project at the desired version if you want to get the associated README.

  • v0.3.0 : Released on 07/31/2022 : Fixed a lot of warning / all libs updated / more information in readme to run the project (working on Java 18 now)
  • v0.2.0 : Released on 01/09/2018 : Works with the Google Assistant SDK alpha2. This version allows you to use the Assistant SDK with the new GRPC binding but doesn't implements the new features from the alpha2 yet (as Device Actions).
  • v0.1.0 : Released on 05/01/2017 : Works with the Google Assistant SDK alpha1

Configuration

The project use TypeSafe config for the configuration. The main configuration file is src/main/resources/reference.conf

The project use slf4j and log4j2 for logging. You can configure the logger with the log4j2.xml file in the resources folder.

To authenticate the requests to API, the Google Assistant SDK use the oAuth2 protocol. As specified on this page , you must generate a client id and a client secret for the application. Next you must provide theses values (id and secret) in the reference.conf file.

Since the alpha2 version of the SDK, the API must register a device model and a device instance to use the SDK. See the documentation for more information here. The API handles this registration but you must provide in the reference.conf the id of the project you created during the previous step (to get your oAuth2 credentials). Set this value in the projectId field under deviceRegister in the reference.conf file.

Be careful to not confuse your project name and your project id. You can find the right value on the homepage of your project in the Google Cloud console (it should be composed of letters and numbers) Project id guide

The project use generated bindings (package com.google.assistant.embedded.v1alpha2) from Google Apis (repository in References / Links section). If you want to update theses files, you can follow this guide

Audio / Text - Input / Output

In the reference.conf file, you can choose if you want to make your request with your voice or by entering text (parameter inputMode). You can also choose if you want to play the response in audio with the outputAudio parameter.

Usage

The first time you start the application, you must authorize the application via the oAuth2 protocol. You must copy and paste the authorization code from your browser in your terminal.

If you have an error accessing the oAuth page, be sure to activate the testing mode on the OAuth consent screen page. Also, add your personal address as test user. oAuth Testing Guide

The application will register a device model and a device instance with your project id (see the configuration part if you haven't set your project id). This information will be persisted in the device_model.json and device_instance.json files.

Next you can talk and hit enter to send a request to the API. You will receive a response and send another request if you want.

The application will store your oAuth2 credentials in a file so you will not have to authorize the application each time your run it.

References / Links

Feel free to give me some feedback or ask questions if you have any.

Youtube Demo Video

Youtube Video Demo