From f00df5ff40672942bdc6d1b27c10c49076f994f2 Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Wed, 27 Dec 2017 20:56:41 -0500 Subject: [PATCH] google-assistant-sdk: sync hotword sample library-commit: f11eb210784825fde0d41b121863df1008edffc9 Bug: 71360271 Change-Id: I9ee81a9b8694d3c6982fb9c263ee051427549d84 --- google-assistant-sdk/CHANGELOG.rst | 4 +++ .../assistant/library/hotword.py | 26 ++++++++++++++++--- google-assistant-sdk/setup.py | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/google-assistant-sdk/CHANGELOG.rst b/google-assistant-sdk/CHANGELOG.rst index 9d0bcdb..540f42f 100644 --- a/google-assistant-sdk/CHANGELOG.rst +++ b/google-assistant-sdk/CHANGELOG.rst @@ -1,6 +1,10 @@ Changelog ========= +0.4.1 +----- +- Update outdated `hotword` sample. + 0.4.0 ----- - Add Device actions handling to samples. diff --git a/google-assistant-sdk/googlesamples/assistant/library/hotword.py b/google-assistant-sdk/googlesamples/assistant/library/hotword.py index 22e8b9a..2960e5d 100644 --- a/google-assistant-sdk/googlesamples/assistant/library/hotword.py +++ b/google-assistant-sdk/googlesamples/assistant/library/hotword.py @@ -1,4 +1,5 @@ #!/usr/bin/env python + # Copyright (C) 2017 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,15 +13,22 @@ # 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. + + from __future__ import print_function + import argparse import os.path import json + import google.auth.transport.requests import google.oauth2.credentials + from google.assistant.library import Assistant from google.assistant.library.event import EventType from google.assistant.library.file_helpers import existing_file + + DEVICE_API_URL = 'https://embeddedassistant.googleapis.com/v1alpha2' @@ -41,14 +49,18 @@ def process_device_actions(event, device_id): def process_event(event, device_id): """Pretty prints events. + Prints all events that occur with two spaces between each new conversation and a single space between turns of a conversation. + Args: event(event.Event): The current event to process. """ if event.type == EventType.ON_CONVERSATION_TURN_STARTED: print() + print(event) + if (event.type == EventType.ON_CONVERSATION_TURN_FINISHED and event.args and not event.args['with_follow_on_turn']): print() @@ -59,8 +71,10 @@ def process_event(event, device_id): def register_device(project_id, credentials, device_model_id, device_id): """Register the device if needed. + Registers a new assistant device if an instance with the given id does not already exists for this model. + Args: project_id(str): The project ID used to register device instance. credentials(google.oauth2.credentials.Credentials): The Google @@ -79,6 +93,7 @@ def register_device(project_id, credentials, device_model_id, device_id): r = session.post(base_url, data=json.dumps({ 'id': device_id, 'model_id': device_model_id, + 'client_type': 'SDK_LIBRARY' })) if r.status_code != 200: raise Exception('failed to register device: ' + r.text) @@ -98,22 +113,27 @@ def main(): help='Path to store and read OAuth2 credentials') parser.add_argument('--device_model_id', type=str, metavar='DEVICE_MODEL_ID', required=True, - help='The device model ID registered with Google.') + help='The device model ID registered with Google') parser.add_argument('--project_id', type=str, metavar='PROJECT_ID', required=False, - help='The project ID used to register device ' - + 'instances.') + help=('The project ID used to register' + 'device instances')) + args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) + with Assistant(credentials, args.device_model_id) as assistant: events = assistant.start() + print('device_model_id:', args.device_model_id + '\n' + 'device_id:', assistant.device_id + '\n') + if args.project_id: register_device(args.project_id, credentials, args.device_model_id, assistant.device_id) + for event in events: process_event(event, assistant.device_id) diff --git a/google-assistant-sdk/setup.py b/google-assistant-sdk/setup.py index 289706e..8e9d833 100644 --- a/google-assistant-sdk/setup.py +++ b/google-assistant-sdk/setup.py @@ -39,7 +39,7 @@ def samples_requirements(): setup( name='google-assistant-sdk', - version='0.4.0', + version='0.4.1', author='Google Assistant SDK team', author_email='proppy+assistant-sdk@google.com', description='Samples and Tools the Google Assistant SDK',