From 3a8ccd0c5008b2b65927480338b3bf927dc24680 Mon Sep 17 00:00:00 2001 From: Date: Sat, 30 Dec 2017 13:21:44 +0100 Subject: [PATCH 1/4] Initial commit for Google Assistant API v1alpha2 --- .../v1alpha2/embedded_assistant_grpc_pb.js | 105 + .../v1alpha2/embedded_assistant_pb.js | 2682 +++++++++++++++++ googleapis/google/type/latlng_pb.js | 184 ++ ts/examples/pcm-audio.ts | 9 +- ts/examples/text-conversation.ts | 113 + ts/lib/config.ts | 26 +- ts/lib/constants.ts | 2 + ts/lib/google-assistant.ts | 199 +- ts/lib/options.ts | 5 + 9 files changed, 3232 insertions(+), 93 deletions(-) create mode 100644 googleapis/google/assistant/embedded/v1alpha2/embedded_assistant_grpc_pb.js create mode 100644 googleapis/google/assistant/embedded/v1alpha2/embedded_assistant_pb.js create mode 100644 googleapis/google/type/latlng_pb.js create mode 100644 ts/examples/text-conversation.ts diff --git a/googleapis/google/assistant/embedded/v1alpha2/embedded_assistant_grpc_pb.js b/googleapis/google/assistant/embedded/v1alpha2/embedded_assistant_grpc_pb.js new file mode 100644 index 0000000..7059af2 --- /dev/null +++ b/googleapis/google/assistant/embedded/v1alpha2/embedded_assistant_grpc_pb.js @@ -0,0 +1,105 @@ +// GENERATED CODE -- DO NOT EDIT! + +// Original file comments: +// Copyright 2017 Google Inc. +// +// Licensed 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. +// +'use strict'; +var grpc = require('grpc'); +var google_assistant_embedded_v1alpha2_embedded_assistant_pb = require('../../../../google/assistant/embedded/v1alpha2/embedded_assistant_pb.js'); +var google_api_annotations_pb = require('../../../../google/api/annotations_pb.js'); +var google_type_latlng_pb = require('../../../../google/type/latlng_pb.js'); + +function serialize_google_assistant_embedded_v1alpha2_AssistRequest(arg) { + if (!(arg instanceof google_assistant_embedded_v1alpha2_embedded_assistant_pb.AssistRequest)) { + throw new Error('Expected argument of type google.assistant.embedded.v1alpha2.AssistRequest'); + } + return new Buffer(arg.serializeBinary()); +} + +function deserialize_google_assistant_embedded_v1alpha2_AssistRequest(buffer_arg) { + return google_assistant_embedded_v1alpha2_embedded_assistant_pb.AssistRequest.deserializeBinary(new Uint8Array(buffer_arg)); +} + +function serialize_google_assistant_embedded_v1alpha2_AssistResponse(arg) { + if (!(arg instanceof google_assistant_embedded_v1alpha2_embedded_assistant_pb.AssistResponse)) { + throw new Error('Expected argument of type google.assistant.embedded.v1alpha2.AssistResponse'); + } + return new Buffer(arg.serializeBinary()); +} + +function deserialize_google_assistant_embedded_v1alpha2_AssistResponse(buffer_arg) { + return google_assistant_embedded_v1alpha2_embedded_assistant_pb.AssistResponse.deserializeBinary(new Uint8Array(buffer_arg)); +} + + +// Service that implements the Google Assistant API. +var EmbeddedAssistantService = exports.EmbeddedAssistantService = { + // Initiates or continues a conversation with the embedded Assistant Service. + // Each call performs one round-trip, sending an audio request to the service + // and receiving the audio response. Uses bidirectional streaming to receive + // results, such as the `END_OF_UTTERANCE` event, while sending audio. + // + // A conversation is one or more gRPC connections, each consisting of several + // streamed requests and responses. + // For example, the user says *Add to my shopping list* and the Assistant + // responds *What do you want to add?*. The sequence of streamed requests and + // responses in the first gRPC message could be: + // + // * AssistRequest.config + // * AssistRequest.audio_in + // * AssistRequest.audio_in + // * AssistRequest.audio_in + // * AssistRequest.audio_in + // * AssistResponse.event_type.END_OF_UTTERANCE + // * AssistResponse.speech_results.transcript "add to my shopping list" + // * AssistResponse.dialog_state_out.microphone_mode.DIALOG_FOLLOW_ON + // * AssistResponse.audio_out + // * AssistResponse.audio_out + // * AssistResponse.audio_out + // + // + // The user then says *bagels* and the Assistant responds + // *OK, I've added bagels to your shopping list*. This is sent as another gRPC + // connection call to the `Assist` method, again with streamed requests and + // responses, such as: + // + // * AssistRequest.config + // * AssistRequest.audio_in + // * AssistRequest.audio_in + // * AssistRequest.audio_in + // * AssistResponse.event_type.END_OF_UTTERANCE + // * AssistResponse.dialog_state_out.microphone_mode.CLOSE_MICROPHONE + // * AssistResponse.audio_out + // * AssistResponse.audio_out + // * AssistResponse.audio_out + // * AssistResponse.audio_out + // + // Although the precise order of responses is not guaranteed, sequential + // `AssistResponse.audio_out` messages will always contain sequential portions + // of audio. + assist: { + path: '/google.assistant.embedded.v1alpha2.EmbeddedAssistant/Assist', + requestStream: true, + responseStream: true, + requestType: google_assistant_embedded_v1alpha2_embedded_assistant_pb.AssistRequest, + responseType: google_assistant_embedded_v1alpha2_embedded_assistant_pb.AssistResponse, + requestSerialize: serialize_google_assistant_embedded_v1alpha2_AssistRequest, + requestDeserialize: deserialize_google_assistant_embedded_v1alpha2_AssistRequest, + responseSerialize: serialize_google_assistant_embedded_v1alpha2_AssistResponse, + responseDeserialize: deserialize_google_assistant_embedded_v1alpha2_AssistResponse, + }, +}; + +exports.EmbeddedAssistantClient = grpc.makeGenericClientConstructor(EmbeddedAssistantService); \ No newline at end of file diff --git a/googleapis/google/assistant/embedded/v1alpha2/embedded_assistant_pb.js b/googleapis/google/assistant/embedded/v1alpha2/embedded_assistant_pb.js new file mode 100644 index 0000000..6942e6e --- /dev/null +++ b/googleapis/google/assistant/embedded/v1alpha2/embedded_assistant_pb.js @@ -0,0 +1,2682 @@ +/** + * @fileoverview + * @enhanceable + * @suppress {messageConventions} JS Compiler reports an error if a variable or + * field starts with 'MSG_' and isn't a translatable message. + * @public + */ +// GENERATED CODE -- DO NOT EDIT! + +var jspb = require('google-protobuf'); +var goog = jspb; +var global = Function('return this')(); + +var google_api_annotations_pb = require('../../../../google/api/annotations_pb.js'); +var google_type_latlng_pb = require('../../../../google/type/latlng_pb.js'); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.AssistConfig', null, global); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.AssistRequest', null, global); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.AssistResponse', null, global); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.AssistResponse.EventType', null, global); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.AudioInConfig', null, global); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.AudioInConfig.Encoding', null, global); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.AudioOut', null, global); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.AudioOutConfig', null, global); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.AudioOutConfig.Encoding', null, global); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.DeviceAction', null, global); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.DeviceConfig', null, global); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.DeviceLocation', null, global); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.DialogStateIn', null, global); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.DialogStateOut', null, global); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.DialogStateOut.MicrophoneMode', null, global); +goog.exportSymbol('proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult', null, global); + +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, proto.google.assistant.embedded.v1alpha2.AssistConfig.oneofGroups_); +}; +goog.inherits(proto.google.assistant.embedded.v1alpha2.AssistConfig, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.google.assistant.embedded.v1alpha2.AssistConfig.displayName = 'proto.google.assistant.embedded.v1alpha2.AssistConfig'; +} +/** + * Oneof group definitions for this message. Each group defines the field + * numbers belonging to that group. When of these fields' value is set, all + * other fields in the group are cleared. During deserialization, if multiple + * fields are encountered for a group, only the last value seen will be kept. + * @private {!Array>} + * @const + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.oneofGroups_ = [[1,6]]; + +/** + * @enum {number} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.TypeCase = { + TYPE_NOT_SET: 0, + AUDIO_IN_CONFIG: 1, + TEXT_QUERY: 6 +}; + +/** + * @return {proto.google.assistant.embedded.v1alpha2.AssistConfig.TypeCase} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.getTypeCase = function() { + return /** @type {proto.google.assistant.embedded.v1alpha2.AssistConfig.TypeCase} */(jspb.Message.computeOneofCase(this, proto.google.assistant.embedded.v1alpha2.AssistConfig.oneofGroups_[0])); +}; + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto suitable for use in Soy templates. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. + * @param {boolean=} opt_includeInstance Whether to include the JSPB instance + * for transitional soy proto support: http://goto/soy-param-migration + * @return {!Object} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.toObject = function(opt_includeInstance) { + return proto.google.assistant.embedded.v1alpha2.AssistConfig.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Whether to include the JSPB + * instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.google.assistant.embedded.v1alpha2.AssistConfig} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.toObject = function(includeInstance, msg) { + var f, obj = { + audioInConfig: (f = msg.getAudioInConfig()) && proto.google.assistant.embedded.v1alpha2.AudioInConfig.toObject(includeInstance, f), + textQuery: jspb.Message.getFieldWithDefault(msg, 6, ""), + audioOutConfig: (f = msg.getAudioOutConfig()) && proto.google.assistant.embedded.v1alpha2.AudioOutConfig.toObject(includeInstance, f), + dialogStateIn: (f = msg.getDialogStateIn()) && proto.google.assistant.embedded.v1alpha2.DialogStateIn.toObject(includeInstance, f), + deviceConfig: (f = msg.getDeviceConfig()) && proto.google.assistant.embedded.v1alpha2.DeviceConfig.toObject(includeInstance, f) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.google.assistant.embedded.v1alpha2.AssistConfig} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.google.assistant.embedded.v1alpha2.AssistConfig; + return proto.google.assistant.embedded.v1alpha2.AssistConfig.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.google.assistant.embedded.v1alpha2.AssistConfig} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.google.assistant.embedded.v1alpha2.AssistConfig} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = new proto.google.assistant.embedded.v1alpha2.AudioInConfig; + reader.readMessage(value,proto.google.assistant.embedded.v1alpha2.AudioInConfig.deserializeBinaryFromReader); + msg.setAudioInConfig(value); + break; + case 6: + var value = /** @type {string} */ (reader.readString()); + msg.setTextQuery(value); + break; + case 2: + var value = new proto.google.assistant.embedded.v1alpha2.AudioOutConfig; + reader.readMessage(value,proto.google.assistant.embedded.v1alpha2.AudioOutConfig.deserializeBinaryFromReader); + msg.setAudioOutConfig(value); + break; + case 3: + var value = new proto.google.assistant.embedded.v1alpha2.DialogStateIn; + reader.readMessage(value,proto.google.assistant.embedded.v1alpha2.DialogStateIn.deserializeBinaryFromReader); + msg.setDialogStateIn(value); + break; + case 4: + var value = new proto.google.assistant.embedded.v1alpha2.DeviceConfig; + reader.readMessage(value,proto.google.assistant.embedded.v1alpha2.DeviceConfig.deserializeBinaryFromReader); + msg.setDeviceConfig(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.google.assistant.embedded.v1alpha2.AssistConfig.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.google.assistant.embedded.v1alpha2.AssistConfig} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getAudioInConfig(); + if (f != null) { + writer.writeMessage( + 1, + f, + proto.google.assistant.embedded.v1alpha2.AudioInConfig.serializeBinaryToWriter + ); + } + f = /** @type {string} */ (jspb.Message.getField(message, 6)); + if (f != null) { + writer.writeString( + 6, + f + ); + } + f = message.getAudioOutConfig(); + if (f != null) { + writer.writeMessage( + 2, + f, + proto.google.assistant.embedded.v1alpha2.AudioOutConfig.serializeBinaryToWriter + ); + } + f = message.getDialogStateIn(); + if (f != null) { + writer.writeMessage( + 3, + f, + proto.google.assistant.embedded.v1alpha2.DialogStateIn.serializeBinaryToWriter + ); + } + f = message.getDeviceConfig(); + if (f != null) { + writer.writeMessage( + 4, + f, + proto.google.assistant.embedded.v1alpha2.DeviceConfig.serializeBinaryToWriter + ); + } +}; + + +/** + * optional AudioInConfig audio_in_config = 1; + * @return {?proto.google.assistant.embedded.v1alpha2.AudioInConfig} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.getAudioInConfig = function() { + return /** @type{?proto.google.assistant.embedded.v1alpha2.AudioInConfig} */ ( + jspb.Message.getWrapperField(this, proto.google.assistant.embedded.v1alpha2.AudioInConfig, 1)); +}; + + +/** @param {?proto.google.assistant.embedded.v1alpha2.AudioInConfig|undefined} value */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.setAudioInConfig = function(value) { + jspb.Message.setOneofWrapperField(this, 1, proto.google.assistant.embedded.v1alpha2.AssistConfig.oneofGroups_[0], value); +}; + + +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.clearAudioInConfig = function() { + this.setAudioInConfig(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {!boolean} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.hasAudioInConfig = function() { + return jspb.Message.getField(this, 1) != null; +}; + + +/** + * optional string text_query = 6; + * @return {string} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.getTextQuery = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 6, "")); +}; + + +/** @param {string} value */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.setTextQuery = function(value) { + jspb.Message.setOneofField(this, 6, proto.google.assistant.embedded.v1alpha2.AssistConfig.oneofGroups_[0], value); +}; + + +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.clearTextQuery = function() { + jspb.Message.setOneofField(this, 6, proto.google.assistant.embedded.v1alpha2.AssistConfig.oneofGroups_[0], undefined); +}; + + +/** + * Returns whether this field is set. + * @return {!boolean} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.hasTextQuery = function() { + return jspb.Message.getField(this, 6) != null; +}; + + +/** + * optional AudioOutConfig audio_out_config = 2; + * @return {?proto.google.assistant.embedded.v1alpha2.AudioOutConfig} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.getAudioOutConfig = function() { + return /** @type{?proto.google.assistant.embedded.v1alpha2.AudioOutConfig} */ ( + jspb.Message.getWrapperField(this, proto.google.assistant.embedded.v1alpha2.AudioOutConfig, 2)); +}; + + +/** @param {?proto.google.assistant.embedded.v1alpha2.AudioOutConfig|undefined} value */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.setAudioOutConfig = function(value) { + jspb.Message.setWrapperField(this, 2, value); +}; + + +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.clearAudioOutConfig = function() { + this.setAudioOutConfig(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {!boolean} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.hasAudioOutConfig = function() { + return jspb.Message.getField(this, 2) != null; +}; + + +/** + * optional DialogStateIn dialog_state_in = 3; + * @return {?proto.google.assistant.embedded.v1alpha2.DialogStateIn} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.getDialogStateIn = function() { + return /** @type{?proto.google.assistant.embedded.v1alpha2.DialogStateIn} */ ( + jspb.Message.getWrapperField(this, proto.google.assistant.embedded.v1alpha2.DialogStateIn, 3)); +}; + + +/** @param {?proto.google.assistant.embedded.v1alpha2.DialogStateIn|undefined} value */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.setDialogStateIn = function(value) { + jspb.Message.setWrapperField(this, 3, value); +}; + + +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.clearDialogStateIn = function() { + this.setDialogStateIn(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {!boolean} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.hasDialogStateIn = function() { + return jspb.Message.getField(this, 3) != null; +}; + + +/** + * optional DeviceConfig device_config = 4; + * @return {?proto.google.assistant.embedded.v1alpha2.DeviceConfig} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.getDeviceConfig = function() { + return /** @type{?proto.google.assistant.embedded.v1alpha2.DeviceConfig} */ ( + jspb.Message.getWrapperField(this, proto.google.assistant.embedded.v1alpha2.DeviceConfig, 4)); +}; + + +/** @param {?proto.google.assistant.embedded.v1alpha2.DeviceConfig|undefined} value */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.setDeviceConfig = function(value) { + jspb.Message.setWrapperField(this, 4, value); +}; + + +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.clearDeviceConfig = function() { + this.setDeviceConfig(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {!boolean} + */ +proto.google.assistant.embedded.v1alpha2.AssistConfig.prototype.hasDeviceConfig = function() { + return jspb.Message.getField(this, 4) != null; +}; + + + +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.google.assistant.embedded.v1alpha2.AudioInConfig = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.google.assistant.embedded.v1alpha2.AudioInConfig, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.google.assistant.embedded.v1alpha2.AudioInConfig.displayName = 'proto.google.assistant.embedded.v1alpha2.AudioInConfig'; +} + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto suitable for use in Soy templates. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. + * @param {boolean=} opt_includeInstance Whether to include the JSPB instance + * for transitional soy proto support: http://goto/soy-param-migration + * @return {!Object} + */ +proto.google.assistant.embedded.v1alpha2.AudioInConfig.prototype.toObject = function(opt_includeInstance) { + return proto.google.assistant.embedded.v1alpha2.AudioInConfig.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Whether to include the JSPB + * instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.google.assistant.embedded.v1alpha2.AudioInConfig} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.AudioInConfig.toObject = function(includeInstance, msg) { + var f, obj = { + encoding: jspb.Message.getFieldWithDefault(msg, 1, 0), + sampleRateHertz: jspb.Message.getFieldWithDefault(msg, 2, 0) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.google.assistant.embedded.v1alpha2.AudioInConfig} + */ +proto.google.assistant.embedded.v1alpha2.AudioInConfig.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.google.assistant.embedded.v1alpha2.AudioInConfig; + return proto.google.assistant.embedded.v1alpha2.AudioInConfig.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.google.assistant.embedded.v1alpha2.AudioInConfig} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.google.assistant.embedded.v1alpha2.AudioInConfig} + */ +proto.google.assistant.embedded.v1alpha2.AudioInConfig.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {!proto.google.assistant.embedded.v1alpha2.AudioInConfig.Encoding} */ (reader.readEnum()); + msg.setEncoding(value); + break; + case 2: + var value = /** @type {number} */ (reader.readInt32()); + msg.setSampleRateHertz(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.AudioInConfig.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.google.assistant.embedded.v1alpha2.AudioInConfig.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.google.assistant.embedded.v1alpha2.AudioInConfig} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.AudioInConfig.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getEncoding(); + if (f !== 0.0) { + writer.writeEnum( + 1, + f + ); + } + f = message.getSampleRateHertz(); + if (f !== 0) { + writer.writeInt32( + 2, + f + ); + } +}; + + +/** + * @enum {number} + */ +proto.google.assistant.embedded.v1alpha2.AudioInConfig.Encoding = { + ENCODING_UNSPECIFIED: 0, + LINEAR16: 1, + FLAC: 2 +}; + +/** + * optional Encoding encoding = 1; + * @return {!proto.google.assistant.embedded.v1alpha2.AudioInConfig.Encoding} + */ +proto.google.assistant.embedded.v1alpha2.AudioInConfig.prototype.getEncoding = function() { + return /** @type {!proto.google.assistant.embedded.v1alpha2.AudioInConfig.Encoding} */ (jspb.Message.getFieldWithDefault(this, 1, 0)); +}; + + +/** @param {!proto.google.assistant.embedded.v1alpha2.AudioInConfig.Encoding} value */ +proto.google.assistant.embedded.v1alpha2.AudioInConfig.prototype.setEncoding = function(value) { + jspb.Message.setField(this, 1, value); +}; + + +/** + * optional int32 sample_rate_hertz = 2; + * @return {number} + */ +proto.google.assistant.embedded.v1alpha2.AudioInConfig.prototype.getSampleRateHertz = function() { + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); +}; + + +/** @param {number} value */ +proto.google.assistant.embedded.v1alpha2.AudioInConfig.prototype.setSampleRateHertz = function(value) { + jspb.Message.setField(this, 2, value); +}; + + + +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.google.assistant.embedded.v1alpha2.AudioOutConfig = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.google.assistant.embedded.v1alpha2.AudioOutConfig, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.google.assistant.embedded.v1alpha2.AudioOutConfig.displayName = 'proto.google.assistant.embedded.v1alpha2.AudioOutConfig'; +} + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto suitable for use in Soy templates. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. + * @param {boolean=} opt_includeInstance Whether to include the JSPB instance + * for transitional soy proto support: http://goto/soy-param-migration + * @return {!Object} + */ +proto.google.assistant.embedded.v1alpha2.AudioOutConfig.prototype.toObject = function(opt_includeInstance) { + return proto.google.assistant.embedded.v1alpha2.AudioOutConfig.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Whether to include the JSPB + * instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.google.assistant.embedded.v1alpha2.AudioOutConfig} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.AudioOutConfig.toObject = function(includeInstance, msg) { + var f, obj = { + encoding: jspb.Message.getFieldWithDefault(msg, 1, 0), + sampleRateHertz: jspb.Message.getFieldWithDefault(msg, 2, 0), + volumePercentage: jspb.Message.getFieldWithDefault(msg, 3, 0) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.google.assistant.embedded.v1alpha2.AudioOutConfig} + */ +proto.google.assistant.embedded.v1alpha2.AudioOutConfig.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.google.assistant.embedded.v1alpha2.AudioOutConfig; + return proto.google.assistant.embedded.v1alpha2.AudioOutConfig.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.google.assistant.embedded.v1alpha2.AudioOutConfig} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.google.assistant.embedded.v1alpha2.AudioOutConfig} + */ +proto.google.assistant.embedded.v1alpha2.AudioOutConfig.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {!proto.google.assistant.embedded.v1alpha2.AudioOutConfig.Encoding} */ (reader.readEnum()); + msg.setEncoding(value); + break; + case 2: + var value = /** @type {number} */ (reader.readInt32()); + msg.setSampleRateHertz(value); + break; + case 3: + var value = /** @type {number} */ (reader.readInt32()); + msg.setVolumePercentage(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.AudioOutConfig.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.google.assistant.embedded.v1alpha2.AudioOutConfig.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.google.assistant.embedded.v1alpha2.AudioOutConfig} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.AudioOutConfig.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getEncoding(); + if (f !== 0.0) { + writer.writeEnum( + 1, + f + ); + } + f = message.getSampleRateHertz(); + if (f !== 0) { + writer.writeInt32( + 2, + f + ); + } + f = message.getVolumePercentage(); + if (f !== 0) { + writer.writeInt32( + 3, + f + ); + } +}; + + +/** + * @enum {number} + */ +proto.google.assistant.embedded.v1alpha2.AudioOutConfig.Encoding = { + ENCODING_UNSPECIFIED: 0, + LINEAR16: 1, + MP3: 2, + OPUS_IN_OGG: 3 +}; + +/** + * optional Encoding encoding = 1; + * @return {!proto.google.assistant.embedded.v1alpha2.AudioOutConfig.Encoding} + */ +proto.google.assistant.embedded.v1alpha2.AudioOutConfig.prototype.getEncoding = function() { + return /** @type {!proto.google.assistant.embedded.v1alpha2.AudioOutConfig.Encoding} */ (jspb.Message.getFieldWithDefault(this, 1, 0)); +}; + + +/** @param {!proto.google.assistant.embedded.v1alpha2.AudioOutConfig.Encoding} value */ +proto.google.assistant.embedded.v1alpha2.AudioOutConfig.prototype.setEncoding = function(value) { + jspb.Message.setField(this, 1, value); +}; + + +/** + * optional int32 sample_rate_hertz = 2; + * @return {number} + */ +proto.google.assistant.embedded.v1alpha2.AudioOutConfig.prototype.getSampleRateHertz = function() { + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); +}; + + +/** @param {number} value */ +proto.google.assistant.embedded.v1alpha2.AudioOutConfig.prototype.setSampleRateHertz = function(value) { + jspb.Message.setField(this, 2, value); +}; + + +/** + * optional int32 volume_percentage = 3; + * @return {number} + */ +proto.google.assistant.embedded.v1alpha2.AudioOutConfig.prototype.getVolumePercentage = function() { + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 3, 0)); +}; + + +/** @param {number} value */ +proto.google.assistant.embedded.v1alpha2.AudioOutConfig.prototype.setVolumePercentage = function(value) { + jspb.Message.setField(this, 3, value); +}; + + + +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.google.assistant.embedded.v1alpha2.DialogStateIn, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.google.assistant.embedded.v1alpha2.DialogStateIn.displayName = 'proto.google.assistant.embedded.v1alpha2.DialogStateIn'; +} + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto suitable for use in Soy templates. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. + * @param {boolean=} opt_includeInstance Whether to include the JSPB instance + * for transitional soy proto support: http://goto/soy-param-migration + * @return {!Object} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn.prototype.toObject = function(opt_includeInstance) { + return proto.google.assistant.embedded.v1alpha2.DialogStateIn.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Whether to include the JSPB + * instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.google.assistant.embedded.v1alpha2.DialogStateIn} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn.toObject = function(includeInstance, msg) { + var f, obj = { + conversationState: msg.getConversationState_asB64(), + languageCode: jspb.Message.getFieldWithDefault(msg, 2, ""), + deviceLocation: (f = msg.getDeviceLocation()) && proto.google.assistant.embedded.v1alpha2.DeviceLocation.toObject(includeInstance, f) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.google.assistant.embedded.v1alpha2.DialogStateIn} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.google.assistant.embedded.v1alpha2.DialogStateIn; + return proto.google.assistant.embedded.v1alpha2.DialogStateIn.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.google.assistant.embedded.v1alpha2.DialogStateIn} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.google.assistant.embedded.v1alpha2.DialogStateIn} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {!Uint8Array} */ (reader.readBytes()); + msg.setConversationState(value); + break; + case 2: + var value = /** @type {string} */ (reader.readString()); + msg.setLanguageCode(value); + break; + case 5: + var value = new proto.google.assistant.embedded.v1alpha2.DeviceLocation; + reader.readMessage(value,proto.google.assistant.embedded.v1alpha2.DeviceLocation.deserializeBinaryFromReader); + msg.setDeviceLocation(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.google.assistant.embedded.v1alpha2.DialogStateIn.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.google.assistant.embedded.v1alpha2.DialogStateIn} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getConversationState_asU8(); + if (f.length > 0) { + writer.writeBytes( + 1, + f + ); + } + f = message.getLanguageCode(); + if (f.length > 0) { + writer.writeString( + 2, + f + ); + } + f = message.getDeviceLocation(); + if (f != null) { + writer.writeMessage( + 5, + f, + proto.google.assistant.embedded.v1alpha2.DeviceLocation.serializeBinaryToWriter + ); + } +}; + + +/** + * optional bytes conversation_state = 1; + * @return {!(string|Uint8Array)} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn.prototype.getConversationState = function() { + return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 1, "")); +}; + + +/** + * optional bytes conversation_state = 1; + * This is a type-conversion wrapper around `getConversationState()` + * @return {string} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn.prototype.getConversationState_asB64 = function() { + return /** @type {string} */ (jspb.Message.bytesAsB64( + this.getConversationState())); +}; + + +/** + * optional bytes conversation_state = 1; + * Note that Uint8Array is not supported on all browsers. + * @see http://caniuse.com/Uint8Array + * This is a type-conversion wrapper around `getConversationState()` + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn.prototype.getConversationState_asU8 = function() { + return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( + this.getConversationState())); +}; + + +/** @param {!(string|Uint8Array)} value */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn.prototype.setConversationState = function(value) { + jspb.Message.setField(this, 1, value); +}; + + +/** + * optional string language_code = 2; + * @return {string} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn.prototype.getLanguageCode = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "")); +}; + + +/** @param {string} value */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn.prototype.setLanguageCode = function(value) { + jspb.Message.setField(this, 2, value); +}; + + +/** + * optional DeviceLocation device_location = 5; + * @return {?proto.google.assistant.embedded.v1alpha2.DeviceLocation} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn.prototype.getDeviceLocation = function() { + return /** @type{?proto.google.assistant.embedded.v1alpha2.DeviceLocation} */ ( + jspb.Message.getWrapperField(this, proto.google.assistant.embedded.v1alpha2.DeviceLocation, 5)); +}; + + +/** @param {?proto.google.assistant.embedded.v1alpha2.DeviceLocation|undefined} value */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn.prototype.setDeviceLocation = function(value) { + jspb.Message.setWrapperField(this, 5, value); +}; + + +proto.google.assistant.embedded.v1alpha2.DialogStateIn.prototype.clearDeviceLocation = function() { + this.setDeviceLocation(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {!boolean} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateIn.prototype.hasDeviceLocation = function() { + return jspb.Message.getField(this, 5) != null; +}; + + + +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.google.assistant.embedded.v1alpha2.AudioOut = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.google.assistant.embedded.v1alpha2.AudioOut, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.google.assistant.embedded.v1alpha2.AudioOut.displayName = 'proto.google.assistant.embedded.v1alpha2.AudioOut'; +} + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto suitable for use in Soy templates. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. + * @param {boolean=} opt_includeInstance Whether to include the JSPB instance + * for transitional soy proto support: http://goto/soy-param-migration + * @return {!Object} + */ +proto.google.assistant.embedded.v1alpha2.AudioOut.prototype.toObject = function(opt_includeInstance) { + return proto.google.assistant.embedded.v1alpha2.AudioOut.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Whether to include the JSPB + * instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.google.assistant.embedded.v1alpha2.AudioOut} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.AudioOut.toObject = function(includeInstance, msg) { + var f, obj = { + audioData: msg.getAudioData_asB64() + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.google.assistant.embedded.v1alpha2.AudioOut} + */ +proto.google.assistant.embedded.v1alpha2.AudioOut.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.google.assistant.embedded.v1alpha2.AudioOut; + return proto.google.assistant.embedded.v1alpha2.AudioOut.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.google.assistant.embedded.v1alpha2.AudioOut} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.google.assistant.embedded.v1alpha2.AudioOut} + */ +proto.google.assistant.embedded.v1alpha2.AudioOut.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {!Uint8Array} */ (reader.readBytes()); + msg.setAudioData(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.AudioOut.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.google.assistant.embedded.v1alpha2.AudioOut.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.google.assistant.embedded.v1alpha2.AudioOut} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.AudioOut.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getAudioData_asU8(); + if (f.length > 0) { + writer.writeBytes( + 1, + f + ); + } +}; + + +/** + * optional bytes audio_data = 1; + * @return {!(string|Uint8Array)} + */ +proto.google.assistant.embedded.v1alpha2.AudioOut.prototype.getAudioData = function() { + return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 1, "")); +}; + + +/** + * optional bytes audio_data = 1; + * This is a type-conversion wrapper around `getAudioData()` + * @return {string} + */ +proto.google.assistant.embedded.v1alpha2.AudioOut.prototype.getAudioData_asB64 = function() { + return /** @type {string} */ (jspb.Message.bytesAsB64( + this.getAudioData())); +}; + + +/** + * optional bytes audio_data = 1; + * Note that Uint8Array is not supported on all browsers. + * @see http://caniuse.com/Uint8Array + * This is a type-conversion wrapper around `getAudioData()` + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.AudioOut.prototype.getAudioData_asU8 = function() { + return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( + this.getAudioData())); +}; + + +/** @param {!(string|Uint8Array)} value */ +proto.google.assistant.embedded.v1alpha2.AudioOut.prototype.setAudioData = function(value) { + jspb.Message.setField(this, 1, value); +}; + + + +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.google.assistant.embedded.v1alpha2.DialogStateOut, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.google.assistant.embedded.v1alpha2.DialogStateOut.displayName = 'proto.google.assistant.embedded.v1alpha2.DialogStateOut'; +} + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto suitable for use in Soy templates. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. + * @param {boolean=} opt_includeInstance Whether to include the JSPB instance + * for transitional soy proto support: http://goto/soy-param-migration + * @return {!Object} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.prototype.toObject = function(opt_includeInstance) { + return proto.google.assistant.embedded.v1alpha2.DialogStateOut.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Whether to include the JSPB + * instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.google.assistant.embedded.v1alpha2.DialogStateOut} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.toObject = function(includeInstance, msg) { + var f, obj = { + supplementalDisplayText: jspb.Message.getFieldWithDefault(msg, 1, ""), + conversationState: msg.getConversationState_asB64(), + microphoneMode: jspb.Message.getFieldWithDefault(msg, 3, 0), + volumePercentage: jspb.Message.getFieldWithDefault(msg, 4, 0) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.google.assistant.embedded.v1alpha2.DialogStateOut} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.google.assistant.embedded.v1alpha2.DialogStateOut; + return proto.google.assistant.embedded.v1alpha2.DialogStateOut.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.google.assistant.embedded.v1alpha2.DialogStateOut} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.google.assistant.embedded.v1alpha2.DialogStateOut} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {string} */ (reader.readString()); + msg.setSupplementalDisplayText(value); + break; + case 2: + var value = /** @type {!Uint8Array} */ (reader.readBytes()); + msg.setConversationState(value); + break; + case 3: + var value = /** @type {!proto.google.assistant.embedded.v1alpha2.DialogStateOut.MicrophoneMode} */ (reader.readEnum()); + msg.setMicrophoneMode(value); + break; + case 4: + var value = /** @type {number} */ (reader.readInt32()); + msg.setVolumePercentage(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.google.assistant.embedded.v1alpha2.DialogStateOut.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.google.assistant.embedded.v1alpha2.DialogStateOut} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getSupplementalDisplayText(); + if (f.length > 0) { + writer.writeString( + 1, + f + ); + } + f = message.getConversationState_asU8(); + if (f.length > 0) { + writer.writeBytes( + 2, + f + ); + } + f = message.getMicrophoneMode(); + if (f !== 0.0) { + writer.writeEnum( + 3, + f + ); + } + f = message.getVolumePercentage(); + if (f !== 0) { + writer.writeInt32( + 4, + f + ); + } +}; + + +/** + * @enum {number} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.MicrophoneMode = { + MICROPHONE_MODE_UNSPECIFIED: 0, + CLOSE_MICROPHONE: 1, + DIALOG_FOLLOW_ON: 2 +}; + +/** + * optional string supplemental_display_text = 1; + * @return {string} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.prototype.getSupplementalDisplayText = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); +}; + + +/** @param {string} value */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.prototype.setSupplementalDisplayText = function(value) { + jspb.Message.setField(this, 1, value); +}; + + +/** + * optional bytes conversation_state = 2; + * @return {!(string|Uint8Array)} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.prototype.getConversationState = function() { + return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 2, "")); +}; + + +/** + * optional bytes conversation_state = 2; + * This is a type-conversion wrapper around `getConversationState()` + * @return {string} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.prototype.getConversationState_asB64 = function() { + return /** @type {string} */ (jspb.Message.bytesAsB64( + this.getConversationState())); +}; + + +/** + * optional bytes conversation_state = 2; + * Note that Uint8Array is not supported on all browsers. + * @see http://caniuse.com/Uint8Array + * This is a type-conversion wrapper around `getConversationState()` + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.prototype.getConversationState_asU8 = function() { + return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( + this.getConversationState())); +}; + + +/** @param {!(string|Uint8Array)} value */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.prototype.setConversationState = function(value) { + jspb.Message.setField(this, 2, value); +}; + + +/** + * optional MicrophoneMode microphone_mode = 3; + * @return {!proto.google.assistant.embedded.v1alpha2.DialogStateOut.MicrophoneMode} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.prototype.getMicrophoneMode = function() { + return /** @type {!proto.google.assistant.embedded.v1alpha2.DialogStateOut.MicrophoneMode} */ (jspb.Message.getFieldWithDefault(this, 3, 0)); +}; + + +/** @param {!proto.google.assistant.embedded.v1alpha2.DialogStateOut.MicrophoneMode} value */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.prototype.setMicrophoneMode = function(value) { + jspb.Message.setField(this, 3, value); +}; + + +/** + * optional int32 volume_percentage = 4; + * @return {number} + */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.prototype.getVolumePercentage = function() { + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 4, 0)); +}; + + +/** @param {number} value */ +proto.google.assistant.embedded.v1alpha2.DialogStateOut.prototype.setVolumePercentage = function(value) { + jspb.Message.setField(this, 4, value); +}; + + + +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, proto.google.assistant.embedded.v1alpha2.AssistRequest.oneofGroups_); +}; +goog.inherits(proto.google.assistant.embedded.v1alpha2.AssistRequest, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.google.assistant.embedded.v1alpha2.AssistRequest.displayName = 'proto.google.assistant.embedded.v1alpha2.AssistRequest'; +} +/** + * Oneof group definitions for this message. Each group defines the field + * numbers belonging to that group. When of these fields' value is set, all + * other fields in the group are cleared. During deserialization, if multiple + * fields are encountered for a group, only the last value seen will be kept. + * @private {!Array>} + * @const + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.oneofGroups_ = [[1,2]]; + +/** + * @enum {number} + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.TypeCase = { + TYPE_NOT_SET: 0, + CONFIG: 1, + AUDIO_IN: 2 +}; + +/** + * @return {proto.google.assistant.embedded.v1alpha2.AssistRequest.TypeCase} + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.prototype.getTypeCase = function() { + return /** @type {proto.google.assistant.embedded.v1alpha2.AssistRequest.TypeCase} */(jspb.Message.computeOneofCase(this, proto.google.assistant.embedded.v1alpha2.AssistRequest.oneofGroups_[0])); +}; + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto suitable for use in Soy templates. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. + * @param {boolean=} opt_includeInstance Whether to include the JSPB instance + * for transitional soy proto support: http://goto/soy-param-migration + * @return {!Object} + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.prototype.toObject = function(opt_includeInstance) { + return proto.google.assistant.embedded.v1alpha2.AssistRequest.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Whether to include the JSPB + * instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.google.assistant.embedded.v1alpha2.AssistRequest} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.toObject = function(includeInstance, msg) { + var f, obj = { + config: (f = msg.getConfig()) && proto.google.assistant.embedded.v1alpha2.AssistConfig.toObject(includeInstance, f), + audioIn: msg.getAudioIn_asB64() + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.google.assistant.embedded.v1alpha2.AssistRequest} + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.google.assistant.embedded.v1alpha2.AssistRequest; + return proto.google.assistant.embedded.v1alpha2.AssistRequest.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.google.assistant.embedded.v1alpha2.AssistRequest} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.google.assistant.embedded.v1alpha2.AssistRequest} + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = new proto.google.assistant.embedded.v1alpha2.AssistConfig; + reader.readMessage(value,proto.google.assistant.embedded.v1alpha2.AssistConfig.deserializeBinaryFromReader); + msg.setConfig(value); + break; + case 2: + var value = /** @type {!Uint8Array} */ (reader.readBytes()); + msg.setAudioIn(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.google.assistant.embedded.v1alpha2.AssistRequest.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.google.assistant.embedded.v1alpha2.AssistRequest} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getConfig(); + if (f != null) { + writer.writeMessage( + 1, + f, + proto.google.assistant.embedded.v1alpha2.AssistConfig.serializeBinaryToWriter + ); + } + f = /** @type {!(string|Uint8Array)} */ (jspb.Message.getField(message, 2)); + if (f != null) { + writer.writeBytes( + 2, + f + ); + } +}; + + +/** + * optional AssistConfig config = 1; + * @return {?proto.google.assistant.embedded.v1alpha2.AssistConfig} + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.prototype.getConfig = function() { + return /** @type{?proto.google.assistant.embedded.v1alpha2.AssistConfig} */ ( + jspb.Message.getWrapperField(this, proto.google.assistant.embedded.v1alpha2.AssistConfig, 1)); +}; + + +/** @param {?proto.google.assistant.embedded.v1alpha2.AssistConfig|undefined} value */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.prototype.setConfig = function(value) { + jspb.Message.setOneofWrapperField(this, 1, proto.google.assistant.embedded.v1alpha2.AssistRequest.oneofGroups_[0], value); +}; + + +proto.google.assistant.embedded.v1alpha2.AssistRequest.prototype.clearConfig = function() { + this.setConfig(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {!boolean} + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.prototype.hasConfig = function() { + return jspb.Message.getField(this, 1) != null; +}; + + +/** + * optional bytes audio_in = 2; + * @return {!(string|Uint8Array)} + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.prototype.getAudioIn = function() { + return /** @type {!(string|Uint8Array)} */ (jspb.Message.getFieldWithDefault(this, 2, "")); +}; + + +/** + * optional bytes audio_in = 2; + * This is a type-conversion wrapper around `getAudioIn()` + * @return {string} + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.prototype.getAudioIn_asB64 = function() { + return /** @type {string} */ (jspb.Message.bytesAsB64( + this.getAudioIn())); +}; + + +/** + * optional bytes audio_in = 2; + * Note that Uint8Array is not supported on all browsers. + * @see http://caniuse.com/Uint8Array + * This is a type-conversion wrapper around `getAudioIn()` + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.prototype.getAudioIn_asU8 = function() { + return /** @type {!Uint8Array} */ (jspb.Message.bytesAsU8( + this.getAudioIn())); +}; + + +/** @param {!(string|Uint8Array)} value */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.prototype.setAudioIn = function(value) { + jspb.Message.setOneofField(this, 2, proto.google.assistant.embedded.v1alpha2.AssistRequest.oneofGroups_[0], value); +}; + + +proto.google.assistant.embedded.v1alpha2.AssistRequest.prototype.clearAudioIn = function() { + jspb.Message.setOneofField(this, 2, proto.google.assistant.embedded.v1alpha2.AssistRequest.oneofGroups_[0], undefined); +}; + + +/** + * Returns whether this field is set. + * @return {!boolean} + */ +proto.google.assistant.embedded.v1alpha2.AssistRequest.prototype.hasAudioIn = function() { + return jspb.Message.getField(this, 2) != null; +}; + + + +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, proto.google.assistant.embedded.v1alpha2.AssistResponse.repeatedFields_, null); +}; +goog.inherits(proto.google.assistant.embedded.v1alpha2.AssistResponse, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.google.assistant.embedded.v1alpha2.AssistResponse.displayName = 'proto.google.assistant.embedded.v1alpha2.AssistResponse'; +} +/** + * List of repeated fields within this message type. + * @private {!Array} + * @const + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.repeatedFields_ = [2]; + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto suitable for use in Soy templates. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. + * @param {boolean=} opt_includeInstance Whether to include the JSPB instance + * for transitional soy proto support: http://goto/soy-param-migration + * @return {!Object} + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.toObject = function(opt_includeInstance) { + return proto.google.assistant.embedded.v1alpha2.AssistResponse.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Whether to include the JSPB + * instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.google.assistant.embedded.v1alpha2.AssistResponse} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.toObject = function(includeInstance, msg) { + var f, obj = { + eventType: jspb.Message.getFieldWithDefault(msg, 1, 0), + audioOut: (f = msg.getAudioOut()) && proto.google.assistant.embedded.v1alpha2.AudioOut.toObject(includeInstance, f), + deviceAction: (f = msg.getDeviceAction()) && proto.google.assistant.embedded.v1alpha2.DeviceAction.toObject(includeInstance, f), + speechResultsList: jspb.Message.toObjectList(msg.getSpeechResultsList(), + proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.toObject, includeInstance), + dialogStateOut: (f = msg.getDialogStateOut()) && proto.google.assistant.embedded.v1alpha2.DialogStateOut.toObject(includeInstance, f) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.google.assistant.embedded.v1alpha2.AssistResponse} + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.google.assistant.embedded.v1alpha2.AssistResponse; + return proto.google.assistant.embedded.v1alpha2.AssistResponse.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.google.assistant.embedded.v1alpha2.AssistResponse} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.google.assistant.embedded.v1alpha2.AssistResponse} + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {!proto.google.assistant.embedded.v1alpha2.AssistResponse.EventType} */ (reader.readEnum()); + msg.setEventType(value); + break; + case 3: + var value = new proto.google.assistant.embedded.v1alpha2.AudioOut; + reader.readMessage(value,proto.google.assistant.embedded.v1alpha2.AudioOut.deserializeBinaryFromReader); + msg.setAudioOut(value); + break; + case 6: + var value = new proto.google.assistant.embedded.v1alpha2.DeviceAction; + reader.readMessage(value,proto.google.assistant.embedded.v1alpha2.DeviceAction.deserializeBinaryFromReader); + msg.setDeviceAction(value); + break; + case 2: + var value = new proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult; + reader.readMessage(value,proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.deserializeBinaryFromReader); + msg.addSpeechResults(value); + break; + case 5: + var value = new proto.google.assistant.embedded.v1alpha2.DialogStateOut; + reader.readMessage(value,proto.google.assistant.embedded.v1alpha2.DialogStateOut.deserializeBinaryFromReader); + msg.setDialogStateOut(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.google.assistant.embedded.v1alpha2.AssistResponse.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.google.assistant.embedded.v1alpha2.AssistResponse} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getEventType(); + if (f !== 0.0) { + writer.writeEnum( + 1, + f + ); + } + f = message.getAudioOut(); + if (f != null) { + writer.writeMessage( + 3, + f, + proto.google.assistant.embedded.v1alpha2.AudioOut.serializeBinaryToWriter + ); + } + f = message.getDeviceAction(); + if (f != null) { + writer.writeMessage( + 6, + f, + proto.google.assistant.embedded.v1alpha2.DeviceAction.serializeBinaryToWriter + ); + } + f = message.getSpeechResultsList(); + if (f.length > 0) { + writer.writeRepeatedMessage( + 2, + f, + proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.serializeBinaryToWriter + ); + } + f = message.getDialogStateOut(); + if (f != null) { + writer.writeMessage( + 5, + f, + proto.google.assistant.embedded.v1alpha2.DialogStateOut.serializeBinaryToWriter + ); + } +}; + + +/** + * @enum {number} + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.EventType = { + EVENT_TYPE_UNSPECIFIED: 0, + END_OF_UTTERANCE: 1 +}; + +/** + * optional EventType event_type = 1; + * @return {!proto.google.assistant.embedded.v1alpha2.AssistResponse.EventType} + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.getEventType = function() { + return /** @type {!proto.google.assistant.embedded.v1alpha2.AssistResponse.EventType} */ (jspb.Message.getFieldWithDefault(this, 1, 0)); +}; + + +/** @param {!proto.google.assistant.embedded.v1alpha2.AssistResponse.EventType} value */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.setEventType = function(value) { + jspb.Message.setField(this, 1, value); +}; + + +/** + * optional AudioOut audio_out = 3; + * @return {?proto.google.assistant.embedded.v1alpha2.AudioOut} + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.getAudioOut = function() { + return /** @type{?proto.google.assistant.embedded.v1alpha2.AudioOut} */ ( + jspb.Message.getWrapperField(this, proto.google.assistant.embedded.v1alpha2.AudioOut, 3)); +}; + + +/** @param {?proto.google.assistant.embedded.v1alpha2.AudioOut|undefined} value */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.setAudioOut = function(value) { + jspb.Message.setWrapperField(this, 3, value); +}; + + +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.clearAudioOut = function() { + this.setAudioOut(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {!boolean} + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.hasAudioOut = function() { + return jspb.Message.getField(this, 3) != null; +}; + + +/** + * optional DeviceAction device_action = 6; + * @return {?proto.google.assistant.embedded.v1alpha2.DeviceAction} + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.getDeviceAction = function() { + return /** @type{?proto.google.assistant.embedded.v1alpha2.DeviceAction} */ ( + jspb.Message.getWrapperField(this, proto.google.assistant.embedded.v1alpha2.DeviceAction, 6)); +}; + + +/** @param {?proto.google.assistant.embedded.v1alpha2.DeviceAction|undefined} value */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.setDeviceAction = function(value) { + jspb.Message.setWrapperField(this, 6, value); +}; + + +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.clearDeviceAction = function() { + this.setDeviceAction(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {!boolean} + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.hasDeviceAction = function() { + return jspb.Message.getField(this, 6) != null; +}; + + +/** + * repeated SpeechRecognitionResult speech_results = 2; + * @return {!Array.} + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.getSpeechResultsList = function() { + return /** @type{!Array.} */ ( + jspb.Message.getRepeatedWrapperField(this, proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult, 2)); +}; + + +/** @param {!Array.} value */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.setSpeechResultsList = function(value) { + jspb.Message.setRepeatedWrapperField(this, 2, value); +}; + + +/** + * @param {!proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult=} opt_value + * @param {number=} opt_index + * @return {!proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult} + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.addSpeechResults = function(opt_value, opt_index) { + return jspb.Message.addToRepeatedWrapperField(this, 2, opt_value, proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult, opt_index); +}; + + +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.clearSpeechResultsList = function() { + this.setSpeechResultsList([]); +}; + + +/** + * optional DialogStateOut dialog_state_out = 5; + * @return {?proto.google.assistant.embedded.v1alpha2.DialogStateOut} + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.getDialogStateOut = function() { + return /** @type{?proto.google.assistant.embedded.v1alpha2.DialogStateOut} */ ( + jspb.Message.getWrapperField(this, proto.google.assistant.embedded.v1alpha2.DialogStateOut, 5)); +}; + + +/** @param {?proto.google.assistant.embedded.v1alpha2.DialogStateOut|undefined} value */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.setDialogStateOut = function(value) { + jspb.Message.setWrapperField(this, 5, value); +}; + + +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.clearDialogStateOut = function() { + this.setDialogStateOut(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {!boolean} + */ +proto.google.assistant.embedded.v1alpha2.AssistResponse.prototype.hasDialogStateOut = function() { + return jspb.Message.getField(this, 5) != null; +}; + + + +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.displayName = 'proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult'; +} + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto suitable for use in Soy templates. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. + * @param {boolean=} opt_includeInstance Whether to include the JSPB instance + * for transitional soy proto support: http://goto/soy-param-migration + * @return {!Object} + */ +proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.prototype.toObject = function(opt_includeInstance) { + return proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Whether to include the JSPB + * instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.toObject = function(includeInstance, msg) { + var f, obj = { + transcript: jspb.Message.getFieldWithDefault(msg, 1, ""), + stability: +jspb.Message.getFieldWithDefault(msg, 2, 0.0) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult} + */ +proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult; + return proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult} + */ +proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {string} */ (reader.readString()); + msg.setTranscript(value); + break; + case 2: + var value = /** @type {number} */ (reader.readFloat()); + msg.setStability(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getTranscript(); + if (f.length > 0) { + writer.writeString( + 1, + f + ); + } + f = message.getStability(); + if (f !== 0.0) { + writer.writeFloat( + 2, + f + ); + } +}; + + +/** + * optional string transcript = 1; + * @return {string} + */ +proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.prototype.getTranscript = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); +}; + + +/** @param {string} value */ +proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.prototype.setTranscript = function(value) { + jspb.Message.setField(this, 1, value); +}; + + +/** + * optional float stability = 2; + * @return {number} + */ +proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.prototype.getStability = function() { + return /** @type {number} */ (+jspb.Message.getFieldWithDefault(this, 2, 0.0)); +}; + + +/** @param {number} value */ +proto.google.assistant.embedded.v1alpha2.SpeechRecognitionResult.prototype.setStability = function(value) { + jspb.Message.setField(this, 2, value); +}; + + + +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.google.assistant.embedded.v1alpha2.DeviceConfig = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.google.assistant.embedded.v1alpha2.DeviceConfig, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.google.assistant.embedded.v1alpha2.DeviceConfig.displayName = 'proto.google.assistant.embedded.v1alpha2.DeviceConfig'; +} + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto suitable for use in Soy templates. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. + * @param {boolean=} opt_includeInstance Whether to include the JSPB instance + * for transitional soy proto support: http://goto/soy-param-migration + * @return {!Object} + */ +proto.google.assistant.embedded.v1alpha2.DeviceConfig.prototype.toObject = function(opt_includeInstance) { + return proto.google.assistant.embedded.v1alpha2.DeviceConfig.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Whether to include the JSPB + * instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.google.assistant.embedded.v1alpha2.DeviceConfig} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.DeviceConfig.toObject = function(includeInstance, msg) { + var f, obj = { + deviceId: jspb.Message.getFieldWithDefault(msg, 1, ""), + deviceModelId: jspb.Message.getFieldWithDefault(msg, 3, "") + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.google.assistant.embedded.v1alpha2.DeviceConfig} + */ +proto.google.assistant.embedded.v1alpha2.DeviceConfig.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.google.assistant.embedded.v1alpha2.DeviceConfig; + return proto.google.assistant.embedded.v1alpha2.DeviceConfig.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.google.assistant.embedded.v1alpha2.DeviceConfig} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.google.assistant.embedded.v1alpha2.DeviceConfig} + */ +proto.google.assistant.embedded.v1alpha2.DeviceConfig.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {string} */ (reader.readString()); + msg.setDeviceId(value); + break; + case 3: + var value = /** @type {string} */ (reader.readString()); + msg.setDeviceModelId(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.DeviceConfig.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.google.assistant.embedded.v1alpha2.DeviceConfig.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.google.assistant.embedded.v1alpha2.DeviceConfig} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.DeviceConfig.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getDeviceId(); + if (f.length > 0) { + writer.writeString( + 1, + f + ); + } + f = message.getDeviceModelId(); + if (f.length > 0) { + writer.writeString( + 3, + f + ); + } +}; + + +/** + * optional string device_id = 1; + * @return {string} + */ +proto.google.assistant.embedded.v1alpha2.DeviceConfig.prototype.getDeviceId = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); +}; + + +/** @param {string} value */ +proto.google.assistant.embedded.v1alpha2.DeviceConfig.prototype.setDeviceId = function(value) { + jspb.Message.setField(this, 1, value); +}; + + +/** + * optional string device_model_id = 3; + * @return {string} + */ +proto.google.assistant.embedded.v1alpha2.DeviceConfig.prototype.getDeviceModelId = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, "")); +}; + + +/** @param {string} value */ +proto.google.assistant.embedded.v1alpha2.DeviceConfig.prototype.setDeviceModelId = function(value) { + jspb.Message.setField(this, 3, value); +}; + + + +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.google.assistant.embedded.v1alpha2.DeviceAction = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.google.assistant.embedded.v1alpha2.DeviceAction, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.google.assistant.embedded.v1alpha2.DeviceAction.displayName = 'proto.google.assistant.embedded.v1alpha2.DeviceAction'; +} + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto suitable for use in Soy templates. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. + * @param {boolean=} opt_includeInstance Whether to include the JSPB instance + * for transitional soy proto support: http://goto/soy-param-migration + * @return {!Object} + */ +proto.google.assistant.embedded.v1alpha2.DeviceAction.prototype.toObject = function(opt_includeInstance) { + return proto.google.assistant.embedded.v1alpha2.DeviceAction.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Whether to include the JSPB + * instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.google.assistant.embedded.v1alpha2.DeviceAction} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.DeviceAction.toObject = function(includeInstance, msg) { + var f, obj = { + deviceRequestJson: jspb.Message.getFieldWithDefault(msg, 1, "") + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.google.assistant.embedded.v1alpha2.DeviceAction} + */ +proto.google.assistant.embedded.v1alpha2.DeviceAction.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.google.assistant.embedded.v1alpha2.DeviceAction; + return proto.google.assistant.embedded.v1alpha2.DeviceAction.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.google.assistant.embedded.v1alpha2.DeviceAction} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.google.assistant.embedded.v1alpha2.DeviceAction} + */ +proto.google.assistant.embedded.v1alpha2.DeviceAction.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {string} */ (reader.readString()); + msg.setDeviceRequestJson(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.DeviceAction.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.google.assistant.embedded.v1alpha2.DeviceAction.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.google.assistant.embedded.v1alpha2.DeviceAction} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.DeviceAction.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getDeviceRequestJson(); + if (f.length > 0) { + writer.writeString( + 1, + f + ); + } +}; + + +/** + * optional string device_request_json = 1; + * @return {string} + */ +proto.google.assistant.embedded.v1alpha2.DeviceAction.prototype.getDeviceRequestJson = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); +}; + + +/** @param {string} value */ +proto.google.assistant.embedded.v1alpha2.DeviceAction.prototype.setDeviceRequestJson = function(value) { + jspb.Message.setField(this, 1, value); +}; + + + +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.google.assistant.embedded.v1alpha2.DeviceLocation = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, proto.google.assistant.embedded.v1alpha2.DeviceLocation.oneofGroups_); +}; +goog.inherits(proto.google.assistant.embedded.v1alpha2.DeviceLocation, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.google.assistant.embedded.v1alpha2.DeviceLocation.displayName = 'proto.google.assistant.embedded.v1alpha2.DeviceLocation'; +} +/** + * Oneof group definitions for this message. Each group defines the field + * numbers belonging to that group. When of these fields' value is set, all + * other fields in the group are cleared. During deserialization, if multiple + * fields are encountered for a group, only the last value seen will be kept. + * @private {!Array>} + * @const + */ +proto.google.assistant.embedded.v1alpha2.DeviceLocation.oneofGroups_ = [[1]]; + +/** + * @enum {number} + */ +proto.google.assistant.embedded.v1alpha2.DeviceLocation.TypeCase = { + TYPE_NOT_SET: 0, + COORDINATES: 1 +}; + +/** + * @return {proto.google.assistant.embedded.v1alpha2.DeviceLocation.TypeCase} + */ +proto.google.assistant.embedded.v1alpha2.DeviceLocation.prototype.getTypeCase = function() { + return /** @type {proto.google.assistant.embedded.v1alpha2.DeviceLocation.TypeCase} */(jspb.Message.computeOneofCase(this, proto.google.assistant.embedded.v1alpha2.DeviceLocation.oneofGroups_[0])); +}; + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto suitable for use in Soy templates. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. + * @param {boolean=} opt_includeInstance Whether to include the JSPB instance + * for transitional soy proto support: http://goto/soy-param-migration + * @return {!Object} + */ +proto.google.assistant.embedded.v1alpha2.DeviceLocation.prototype.toObject = function(opt_includeInstance) { + return proto.google.assistant.embedded.v1alpha2.DeviceLocation.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Whether to include the JSPB + * instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.google.assistant.embedded.v1alpha2.DeviceLocation} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.DeviceLocation.toObject = function(includeInstance, msg) { + var f, obj = { + coordinates: (f = msg.getCoordinates()) && google_type_latlng_pb.LatLng.toObject(includeInstance, f) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.google.assistant.embedded.v1alpha2.DeviceLocation} + */ +proto.google.assistant.embedded.v1alpha2.DeviceLocation.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.google.assistant.embedded.v1alpha2.DeviceLocation; + return proto.google.assistant.embedded.v1alpha2.DeviceLocation.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.google.assistant.embedded.v1alpha2.DeviceLocation} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.google.assistant.embedded.v1alpha2.DeviceLocation} + */ +proto.google.assistant.embedded.v1alpha2.DeviceLocation.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = new google_type_latlng_pb.LatLng; + reader.readMessage(value,google_type_latlng_pb.LatLng.deserializeBinaryFromReader); + msg.setCoordinates(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.google.assistant.embedded.v1alpha2.DeviceLocation.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.google.assistant.embedded.v1alpha2.DeviceLocation.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.google.assistant.embedded.v1alpha2.DeviceLocation} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.assistant.embedded.v1alpha2.DeviceLocation.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getCoordinates(); + if (f != null) { + writer.writeMessage( + 1, + f, + google_type_latlng_pb.LatLng.serializeBinaryToWriter + ); + } +}; + + +/** + * optional google.type.LatLng coordinates = 1; + * @return {?proto.google.type.LatLng} + */ +proto.google.assistant.embedded.v1alpha2.DeviceLocation.prototype.getCoordinates = function() { + return /** @type{?proto.google.type.LatLng} */ ( + jspb.Message.getWrapperField(this, google_type_latlng_pb.LatLng, 1)); +}; + + +/** @param {?proto.google.type.LatLng|undefined} value */ +proto.google.assistant.embedded.v1alpha2.DeviceLocation.prototype.setCoordinates = function(value) { + jspb.Message.setOneofWrapperField(this, 1, proto.google.assistant.embedded.v1alpha2.DeviceLocation.oneofGroups_[0], value); +}; + + +proto.google.assistant.embedded.v1alpha2.DeviceLocation.prototype.clearCoordinates = function() { + this.setCoordinates(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {!boolean} + */ +proto.google.assistant.embedded.v1alpha2.DeviceLocation.prototype.hasCoordinates = function() { + return jspb.Message.getField(this, 1) != null; +}; + + +goog.object.extend(exports, proto.google.assistant.embedded.v1alpha2); \ No newline at end of file diff --git a/googleapis/google/type/latlng_pb.js b/googleapis/google/type/latlng_pb.js new file mode 100644 index 0000000..0e2bd93 --- /dev/null +++ b/googleapis/google/type/latlng_pb.js @@ -0,0 +1,184 @@ +/** + * @fileoverview + * @enhanceable + * @suppress {messageConventions} JS Compiler reports an error if a variable or + * field starts with 'MSG_' and isn't a translatable message. + * @public + */ +// GENERATED CODE -- DO NOT EDIT! + +var jspb = require('google-protobuf'); +var goog = jspb; +var global = Function('return this')(); + +goog.exportSymbol('proto.google.type.LatLng', null, global); + +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.google.type.LatLng = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.google.type.LatLng, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.google.type.LatLng.displayName = 'proto.google.type.LatLng'; +} + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto suitable for use in Soy templates. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. + * @param {boolean=} opt_includeInstance Whether to include the JSPB instance + * for transitional soy proto support: http://goto/soy-param-migration + * @return {!Object} + */ +proto.google.type.LatLng.prototype.toObject = function(opt_includeInstance) { + return proto.google.type.LatLng.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Whether to include the JSPB + * instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.google.type.LatLng} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.type.LatLng.toObject = function(includeInstance, msg) { + var f, obj = { + latitude: +jspb.Message.getFieldWithDefault(msg, 1, 0.0), + longitude: +jspb.Message.getFieldWithDefault(msg, 2, 0.0) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.google.type.LatLng} + */ +proto.google.type.LatLng.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.google.type.LatLng; + return proto.google.type.LatLng.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.google.type.LatLng} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.google.type.LatLng} + */ +proto.google.type.LatLng.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {number} */ (reader.readDouble()); + msg.setLatitude(value); + break; + case 2: + var value = /** @type {number} */ (reader.readDouble()); + msg.setLongitude(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.google.type.LatLng.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.google.type.LatLng.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.google.type.LatLng} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.google.type.LatLng.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getLatitude(); + if (f !== 0.0) { + writer.writeDouble( + 1, + f + ); + } + f = message.getLongitude(); + if (f !== 0.0) { + writer.writeDouble( + 2, + f + ); + } +}; + + +/** + * optional double latitude = 1; + * @return {number} + */ +proto.google.type.LatLng.prototype.getLatitude = function() { + return /** @type {number} */ (+jspb.Message.getFieldWithDefault(this, 1, 0.0)); +}; + + +/** @param {number} value */ +proto.google.type.LatLng.prototype.setLatitude = function(value) { + jspb.Message.setField(this, 1, value); +}; + + +/** + * optional double longitude = 2; + * @return {number} + */ +proto.google.type.LatLng.prototype.getLongitude = function() { + return /** @type {number} */ (+jspb.Message.getFieldWithDefault(this, 2, 0.0)); +}; + + +/** @param {number} value */ +proto.google.type.LatLng.prototype.setLongitude = function(value) { + jspb.Message.setField(this, 2, value); +}; + + +goog.object.extend(exports, proto.google.type); \ No newline at end of file diff --git a/ts/examples/pcm-audio.ts b/ts/examples/pcm-audio.ts index 5d68ffe..e587e6d 100644 --- a/ts/examples/pcm-audio.ts +++ b/ts/examples/pcm-audio.ts @@ -41,7 +41,12 @@ let assistant = new GoogleAssistant({ encoding: encoding.LINEAR16, sampleRateHertz: 16000, volumePercentage: 100 - } + }, + device: { + deviceId: 'pcm-audio', + deviceModelId: 'pcm-audio-node', + }, + languageCode: 'en-US', }) // The Assistant is connected to Google and is ready to receive audio @@ -119,4 +124,4 @@ assistant.authenticate(authClient); // Start the conversation with the Google Assistant. // Remember that you should start piping data once the `ready` event has // been fired. -assistant.converse(); +assistant.assist(); diff --git a/ts/examples/text-conversation.ts b/ts/examples/text-conversation.ts new file mode 100644 index 0000000..b87fcc7 --- /dev/null +++ b/ts/examples/text-conversation.ts @@ -0,0 +1,113 @@ + +import GoogleAssistant = require("../lib/google-assistant"); +import * as stream from "stream"; + +const constants = GoogleAssistant.Constants; +const encoding = constants.Encoding; + +const google = require('googleapis'); +const OAuth2 = google.auth.OAuth2; + +//const Speaker = require('speaker'); + +// Setup the speaker for PCM data +/* +let speaker = new Speaker({ + channels: 1, + bitDepth: 16, + sampleRate: 16000 +}) +*/ + +// Start the Assistant to process 16Hz PCM data from the mic, +// and send the data correctly to the speaker. +let assistant = new GoogleAssistant({ + output: { + encoding: encoding.LINEAR16, + sampleRateHertz: 16000, + volumePercentage: 100 + }, + device: { + deviceId: 'ga-desktop', + deviceModelId: 'ga-desktop-electron', + }, + languageCode: 'en-US', +}) + +// The Assistant is connected to Google and is ready to receive audio +// data from the mic. +assistant.on('ready', (conversationStream: stream.Writable) => { + console.log("Ready"); +}) + +// Transcription of the audio recorded by the mic +assistant.on('request-text', (text: string) => { + console.log("Request Text: ", text); +}) + + +// Transcription of the Assistant's response. +// Google sometimes does not send this text, so don't rely +// to heavily on it. +assistant.on('speech-results', (results: any) => { + console.log("Response Text: ", results); +}) + +// This is the Assistant's audio response. Send it to the speakers. +assistant.on('audio-data', (data: Array) => { + //speaker.write(data) +}) + +// There was an error somewhere. Stop the mic and speaker streams. +assistant.on('error', (err: Error) => { + console.error(err); + console.log("Error ocurred. Exiting..."); + //speaker.end(); +}) + +// The conversation is over. Close the microphone and the speakers. +assistant.once('end', () => { + console.log('ended.'); +}) + +assistant.once('unauthorized', () => { + console.log("Not authorized. Exiting..."); +}) + +// Authentication is a bit complicated since Google requires developers +// to create a Google Cloud Platform project to use the Google Assistant. +// You also need to enable the Google Assistant API in your GCP project +// in order to use the SDK. +var authClient = new OAuth2( + '1008767088687-rjpej2ecgpl7ktvtnlmnpkl9hgl4odch.apps.googleusercontent.com' || process.env.CLIENT_ID, + 'Ryn_0H-etWquCeSIJj8y9koX' || process.env.CLIENT_SECRET, +); + +// Retrieve tokens via token exchange explained here: +// https://github.com/google/google-api-nodejs-client +// +// There are also many other methods to obtain an access token from Google. +// Please read the following for more information: +// https://developers.google.com/identity/protocols/OAuth2 +authClient.setCredentials({ + access_token: 'ya29.GlsyBS2ywk7-zhFdHn1Rrc0d2FcPnn8oWVNjgE24-ve7zkJgCSrOOy6Djs5CYVbX2nOL9DoeB-3Pg1hr_RNDM5-pz2HMBSX9Wj43agMoJSS9z6wewwK_iDHqy19k', + refresh_token: '1/hf2ljFUQGDQXG2AczXIuWOn0mRCZBPx6FB7AMJ5smAA' +}); + +const readline = require('readline'); + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + +let textQuery; + +assistant.authenticate(authClient); + +rl.question('What would you like to say to Google Assistant?', (input: any) => { + console.log(`${input}`); + rl.close(); + assistant.assist(input); +}); + diff --git a/ts/lib/config.ts b/ts/lib/config.ts index d93eeae..bb01533 100644 --- a/ts/lib/config.ts +++ b/ts/lib/config.ts @@ -1,4 +1,4 @@ -import { AudioInOptions, AudioOutOptions } from "./options"; +import { AudioInOptions, AudioOutOptions, DeviceOptions } from "./options"; export interface AudioInConfig extends AudioInOptions { setEncoding(encoding: number): void @@ -9,13 +9,31 @@ export interface AudioOutConfig extends AudioOutOptions, AudioInConfig { setVolumePercentage(percentage: number): void } +export interface DialogStateIn { + conversationState: Array | null + languageCode: string | null + setLanguageCode(languageCode: string): void + setConversationState(state: Array | null): void +} + +export interface DeviceConfig extends DeviceOptions { + setDeviceId(id: string): void; + setDeviceModelId(id: string): void; +} + export interface AssistantConfig { - input: AudioInOptions output: AudioOutOptions + input?: AudioInOptions + device: DeviceOptions + languageCode: string } -export interface ConverseConfig { - setConverseState(state: Array): void +export interface AssistConfig { setAudioInConfig(config: AudioInConfig): void setAudioOutConfig(config: AudioOutConfig): void + setDialogStateIn(state: DialogStateIn): void + setDeviceConfig(config: DeviceConfig): void + setTextQuery(value: string): void + clearAudioInConfig(): void + clearTextQuery(): void } diff --git a/ts/lib/constants.ts b/ts/lib/constants.ts index 55caa0d..f2ec2dc 100644 --- a/ts/lib/constants.ts +++ b/ts/lib/constants.ts @@ -4,10 +4,12 @@ export enum State { } export enum Event { + EVENT_TYPE_UNSPECIFIED = 0, END_OF_UTTERANCE = 1 } export enum MicMode { + MICROPHONE_MODE_UNSPECIFIED = 0, CLOSE_MICROPHONE = 1, DIALOG_FOLLOW_ON = 2 } diff --git a/ts/lib/google-assistant.ts b/ts/lib/google-assistant.ts index 776a63e..c9eb68e 100644 --- a/ts/lib/google-assistant.ts +++ b/ts/lib/google-assistant.ts @@ -3,14 +3,14 @@ import * as stream from "stream"; import * as constants from "./constants"; import AudioConverter from "./audio-converter"; import { State, Event, API, MicMode } from "./constants"; -import { AudioInOptions , AudioOutOptions } from "./options"; +import { AudioInOptions , AudioOutOptions, DeviceOptions } from "./options"; import { - ConverseConfig, AudioInConfig, AudioOutConfig, AssistantConfig + AssistConfig, AudioInConfig, AudioOutConfig, AssistantConfig, DialogStateIn, DeviceConfig, } from "./config"; let grpc = require('grpc'); -let messages = require('./googleapis/google/assistant/embedded/v1alpha1/embedded_assistant_pb'); -let services = require('./googleapis/google/assistant/embedded/v1alpha1/embedded_assistant_grpc_pb'); +let messages = require('./googleapis/google/assistant/embedded/v1alpha2/embedded_assistant_pb'); +let services = require('./googleapis/google/assistant/embedded/v1alpha2/embedded_assistant_grpc_pb'); class GoogleAssistant extends events.EventEmitter { static Constants = constants; @@ -18,39 +18,63 @@ class GoogleAssistant extends events.EventEmitter { private state: State private service: any // gRPC Service private channel: any // gRPC Duplex Channel - private converter: AudioConverter; - private converseConfig: ConverseConfig + private converter: AudioConverter + private assistConfig: AssistConfig private conversationState: Array | null + private textQuery: string | null private audioInConfig: AudioInConfig; private audioOutConfig: AudioOutConfig; + private dialogStateIn: DialogStateIn; + private deviceConfig: DeviceConfig; constructor(config: AssistantConfig) { super(); this.converter = new AudioConverter(); - this.converseConfig = new messages.ConverseConfig(); + this.assistConfig = new messages.AssistConfig(); this.audioInConfig = new messages.AudioInConfig(); this.audioOutConfig = new messages.AudioOutConfig(); + this.dialogStateIn = new messages.DialogStateIn(); + this.deviceConfig = new messages.DeviceConfig(); this.setInputConfig(config.input); this.setOutputConfig(config.output); + this.setLanguageCode(config.languageCode); + this.setDeviceConfig(config.device); } - public setInputConfig(config: AudioInOptions) { - this.audioInConfig.setEncoding(config.encoding); - this.audioInConfig.setSampleRateHertz(config.sampleRateHertz); - this._updateConverseConfig(); + public setDeviceConfig(config: DeviceOptions) { + this.deviceConfig.setDeviceId(config.deviceId); + this.deviceConfig.setDeviceModelId(config.deviceModelId); + } + + public setInputConfig(config?: AudioInOptions) { + if(config) { + this.audioInConfig.setEncoding(config.encoding); + this.audioInConfig.setSampleRateHertz(config.sampleRateHertz); + } + } + + public setLanguageCode(languageCode: string) { + this.dialogStateIn.setLanguageCode(languageCode); } public setOutputConfig(config: AudioOutOptions) { this.audioOutConfig.setEncoding(config.encoding); this.audioOutConfig.setSampleRateHertz(config.sampleRateHertz); this.audioOutConfig.setVolumePercentage(config.volumePercentage); - this._updateConverseConfig(); } - private _updateConverseConfig() { - this.converseConfig.setAudioInConfig(this.audioInConfig); - this.converseConfig.setAudioOutConfig(this.audioOutConfig); + private _updateAssistConfig() { + if(this.textQuery) { + this.assistConfig.setTextQuery(this.textQuery); + this.assistConfig.clearAudioInConfig(); + } else { + this.assistConfig.setAudioInConfig(this.audioInConfig); + this.assistConfig.clearTextQuery(); + } + this.assistConfig.setAudioOutConfig(this.audioOutConfig); + this.assistConfig.setDialogStateIn(this.dialogStateIn); + this.assistConfig.setDeviceConfig(this.deviceConfig); } public authenticate(authClient: any) { @@ -66,14 +90,17 @@ class GoogleAssistant extends events.EventEmitter { ); } - public converse() { - if(this.state == State.IN_PROGRESS && this.conversationState != null) { - this.converseConfig.setConverseState(this.conversationState); - this.conversationState = null; - } + public assist(textQuery?: string) { + // [TODO]: Add support for text-input requests + if(this.state == State.IN_PROGRESS && this.dialogStateIn.conversationState != null) { + this.assistConfig.setDialogStateIn(this.dialogStateIn); + this.dialogStateIn.conversationState = null; + } - let request = new messages.ConverseRequest(); - request.setConfig(this.converseConfig); + this.textQuery = textQuery; + this._updateAssistConfig(); + let request = new messages.AssistRequest(); + request.setConfig(this.assistConfig); // GUARD: Make sure service is created and authenticated if(this.service == null) { @@ -81,103 +108,101 @@ class GoogleAssistant extends events.EventEmitter { return; } - this.channel = this.service.converse( + this.channel = this.service.assist( new grpc.Metadata(), request ); // Setup event listeners - this.channel.on('data', this._handleResponse.bind(this)); - this.channel.on('data', this._handleConversationState.bind(this)); + this.channel.on('data', this._handleAssistResponse.bind(this)); this.channel.on('error', this._handleError.bind(this)); this.channel.on('end', this._handleConversationEnd.bind(this)); - // Write first ConverseRequest + // Write first AssistRequest + console.log('Request:'); + console.log(request); this.channel.write(request) this.state = State.IN_PROGRESS; // Wait for any errors to emerge before piping // audio data - setTimeout(() => { - if(this.channel != null) { - // Setup conversion stream - this.converter - .pipe(this.channel) - .on('error', this._handleError.bind(this)); - - // Signal that assistant is ready - this.emit('ready', this.converter); - } - }, 100); - } - - private _handleResult(result: any) { - if(result.getMicrophoneMode()) { - this.emit('mic-mode', result.getMicrophoneMode()); - } - - if(result.getConversationState()) { - this.emit('state', - new Buffer(result.getConversationState()) - ); + if(!this.textQuery) { + setTimeout(() => { + if(this.channel != null) { + // Setup conversion stream + this.converter + .pipe(this.channel) + .on('error', this._handleError.bind(this)); + + // Signal that assistant is ready + this.emit('ready', this.converter); + } + }, 100); + } else { + this.emit('ready', this.textQuery); } + } - if(result.getSpokenResponseText()) { - this.emit('response-text', result.getSpokenResponseText()); + private _handleAssistResponse(response: any) { + if(response.getEventType() == Event.END_OF_UTTERANCE) { + this.emit('end-of-utterance'); } - if(result.getSpokenRequestText()) { - this.emit('request-text', result.getSpokenRequestText()); + if(response.getSpeechResultsList()) { + this.emit('speech-results', response.getSpeechResultsList()); } - } - private _handleResponse(response: any) { - if(response.hasEventType() && - response.getEventType() == Event.END_OF_UTTERANCE) { - this.emit('end-of-utterance'); + if(response.hasDialogStateOut()) { + this._handleDialogStateOut(response.getDialogStateOut()); } - else if(response.hasAudioOut()) { + if(response.hasAudioOut()) { this.emit('audio-data', new Buffer(response.getAudioOut().getAudioData()) ); } - else if(response.hasResult()) { - this._handleResult(response.getResult()); - } - - else if(response.hasError()) { + // [TODO]: Add support for device actions. + /* + if(response.hasError()) { this.emit('error', response.getError()); } + */ } - private _handleConversationState(response: any) { - // Process state-specific results - if(response.hasResult()) { - let result = response.getResult(); - - // Determine state based on microphone mode. - if(result.getMicrophoneMode()) { - let micMode = result.getMicrophoneMode(); - - // Keep state, and expect more input - if(micMode == MicMode.DIALOG_FOLLOW_ON) { - this.state = State.IN_PROGRESS; - } - - // Conversation is over, wait for output to finish streaming - else if(micMode == MicMode.CLOSE_MICROPHONE) { - this.state = State.FINISHED; - } - } + private _handleDialogStateOut(state: any) { + if(state.getSupplementalDisplayText()) { + this.emit('response-text', state.getSupplementalDisplayText()); + } - // Handle continous conversations - if(result.getConversationState()) { - let convState = new messages.ConverseState(); - convState.setConversationState(result.getConversationState()); - this.conversationState = convState; + if(state.getConversationState()) { + this.emit('state', + new Buffer(state.getConversationState()) + ); + this._handleConversationState(state); + } + } + + private _handleConversationState(state: any) { + // Determine state based on microphone mode. + if(state.getMicrophoneMode()) { + this.emit('mic-mode', state.getMicrophoneMode()); + let micMode = state.getMicrophoneMode(); + // Keep state, and expect more input + if(micMode == MicMode.DIALOG_FOLLOW_ON) { + this.state = State.IN_PROGRESS; + } + + // Conversation is over, wait for output to finish streaming + else if(micMode == MicMode.CLOSE_MICROPHONE) { + this.state = State.FINISHED; } } + // Handle continous conversations + if(state.getConversationState()) { + let diaState = new messages.DialogStateIn(this.dialogStateIn); + diaState.setConversationState(state.getConversationState()); + this.dialogStateIn = diaState; + } } public _handleConversationEnd() { diff --git a/ts/lib/options.ts b/ts/lib/options.ts index 201c45d..a6bfc65 100644 --- a/ts/lib/options.ts +++ b/ts/lib/options.ts @@ -6,3 +6,8 @@ export interface AudioInOptions { export interface AudioOutOptions extends AudioInOptions { volumePercentage: number } + +export interface DeviceOptions { + deviceId: string + deviceModelId: string +} \ No newline at end of file From 27d8740f9ec10a2179bf32f4c543c8c8509a512f Mon Sep 17 00:00:00 2001 From: Date: Sat, 30 Dec 2017 15:31:55 +0100 Subject: [PATCH 2/4] fixes and working text-conversation example --- .env.example | 3 + package-lock.json | 1584 ++++++++++++++---------------- package.json | 4 +- ts/examples/text-conversation.ts | 132 ++- ts/lib/google-assistant.ts | 5 +- 5 files changed, 810 insertions(+), 918 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..478b33b --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +CLIENT_ID= +CLIENT_SECRET= +REDIRECT_URL= \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index fe3f489..f3f3e60 100644 --- a/package-lock.json +++ b/package-lock.json @@ -509,6 +509,11 @@ "integrity": "sha1-yc45Okt8vQsFinJck98pkCeGj/k=", "dev": true }, + "dotenv": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-4.0.0.tgz", + "integrity": "sha1-hk7xN5rO1Vzm+V3r7NzhefegzR0=" + }, "duplexer2": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.0.2.tgz", @@ -1121,886 +1126,727 @@ "dev": true }, "grpc": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/grpc/-/grpc-1.4.1.tgz", - "integrity": "sha1-PuSoNGphPygjkoyfj5kIG2No7Hw=", + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/grpc/-/grpc-1.8.0.tgz", + "integrity": "sha512-AwVQiyMdNv09O4kwec3z52HwkPuo1i61Uk1oENWM9CDeLAUiixQLMpXDIJL31MmZdAuKnAYds/naFEXzprbgHg==", "requires": { "arguejs": "0.2.3", "lodash": "4.17.4", - "nan": "2.6.2", - "node-pre-gyp": "0.6.36", + "nan": "2.8.0", + "node-pre-gyp": "0.6.39", "protobufjs": "5.0.2" }, "dependencies": { + "abbrev": { + "version": "1.1.1", + "bundled": true + }, + "ajv": { + "version": "4.11.8", + "bundled": true, + "requires": { + "co": "4.6.0", + "json-stable-stringify": "1.0.1" + } + }, + "ansi-regex": { + "version": "2.1.1", + "bundled": true + }, + "aproba": { + "version": "1.2.0", + "bundled": true + }, + "are-we-there-yet": { + "version": "1.1.4", + "bundled": true, + "requires": { + "delegates": "1.0.0", + "readable-stream": "2.3.3" + } + }, + "asn1": { + "version": "0.2.3", + "bundled": true + }, + "assert-plus": { + "version": "0.2.0", + "bundled": true + }, + "asynckit": { + "version": "0.4.0", + "bundled": true + }, + "aws-sign2": { + "version": "0.6.0", + "bundled": true + }, + "aws4": { + "version": "1.6.0", + "bundled": true + }, + "balanced-match": { + "version": "1.0.0", + "bundled": true + }, + "bcrypt-pbkdf": { + "version": "1.0.1", + "bundled": true, + "optional": true, + "requires": { + "tweetnacl": "0.14.5" + } + }, + "block-stream": { + "version": "0.0.9", + "bundled": true, + "requires": { + "inherits": "2.0.3" + } + }, + "boom": { + "version": "2.10.1", + "bundled": true, + "requires": { + "hoek": "2.16.3" + } + }, + "brace-expansion": { + "version": "1.1.8", + "bundled": true, + "requires": { + "balanced-match": "1.0.0", + "concat-map": "0.0.1" + } + }, + "caseless": { + "version": "0.12.0", + "bundled": true + }, + "co": { + "version": "4.6.0", + "bundled": true + }, + "code-point-at": { + "version": "1.1.0", + "bundled": true + }, + "combined-stream": { + "version": "1.0.5", + "bundled": true, + "requires": { + "delayed-stream": "1.0.0" + } + }, + "concat-map": { + "version": "0.0.1", + "bundled": true + }, + "console-control-strings": { + "version": "1.1.0", + "bundled": true + }, + "core-util-is": { + "version": "1.0.2", + "bundled": true + }, + "cryptiles": { + "version": "2.0.5", + "bundled": true, + "requires": { + "boom": "2.10.1" + } + }, + "dashdash": { + "version": "1.14.1", + "bundled": true, + "requires": { + "assert-plus": "1.0.0" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true + } + } + }, + "debug": { + "version": "2.6.9", + "bundled": true, + "requires": { + "ms": "2.0.0" + } + }, + "deep-extend": { + "version": "0.4.2", + "bundled": true + }, + "delayed-stream": { + "version": "1.0.0", + "bundled": true + }, + "delegates": { + "version": "1.0.0", + "bundled": true + }, + "detect-libc": { + "version": "1.0.3", + "bundled": true + }, + "ecc-jsbn": { + "version": "0.1.1", + "bundled": true, + "optional": true, + "requires": { + "jsbn": "0.1.1" + } + }, + "extend": { + "version": "3.0.1", + "bundled": true + }, + "extsprintf": { + "version": "1.3.0", + "bundled": true + }, + "forever-agent": { + "version": "0.6.1", + "bundled": true + }, + "form-data": { + "version": "2.1.4", + "bundled": true, + "requires": { + "asynckit": "0.4.0", + "combined-stream": "1.0.5", + "mime-types": "2.1.17" + } + }, + "fs.realpath": { + "version": "1.0.0", + "bundled": true + }, + "fstream": { + "version": "1.0.11", + "bundled": true, + "requires": { + "graceful-fs": "4.1.11", + "inherits": "2.0.3", + "mkdirp": "0.5.1", + "rimraf": "2.6.2" + } + }, + "fstream-ignore": { + "version": "1.0.5", + "bundled": true, + "requires": { + "fstream": "1.0.11", + "inherits": "2.0.3", + "minimatch": "3.0.4" + } + }, + "gauge": { + "version": "2.7.4", + "bundled": true, + "requires": { + "aproba": "1.2.0", + "console-control-strings": "1.1.0", + "has-unicode": "2.0.1", + "object-assign": "4.1.1", + "signal-exit": "3.0.2", + "string-width": "1.0.2", + "strip-ansi": "3.0.1", + "wide-align": "1.1.2" + } + }, + "getpass": { + "version": "0.1.7", + "bundled": true, + "requires": { + "assert-plus": "1.0.0" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true + } + } + }, + "glob": { + "version": "7.1.2", + "bundled": true, + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "graceful-fs": { + "version": "4.1.11", + "bundled": true + }, + "har-schema": { + "version": "1.0.5", + "bundled": true + }, + "har-validator": { + "version": "4.2.1", + "bundled": true, + "requires": { + "ajv": "4.11.8", + "har-schema": "1.0.5" + } + }, + "has-unicode": { + "version": "2.0.1", + "bundled": true + }, + "hawk": { + "version": "3.1.3", + "bundled": true, + "requires": { + "boom": "2.10.1", + "cryptiles": "2.0.5", + "hoek": "2.16.3", + "sntp": "1.0.9" + } + }, + "hoek": { + "version": "2.16.3", + "bundled": true + }, + "http-signature": { + "version": "1.1.1", + "bundled": true, + "requires": { + "assert-plus": "0.2.0", + "jsprim": "1.4.1", + "sshpk": "1.13.1" + } + }, + "inflight": { + "version": "1.0.6", + "bundled": true, + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "bundled": true + }, + "ini": { + "version": "1.3.5", + "bundled": true + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "bundled": true, + "requires": { + "number-is-nan": "1.0.1" + } + }, + "is-typedarray": { + "version": "1.0.0", + "bundled": true + }, + "isarray": { + "version": "1.0.0", + "bundled": true + }, + "isstream": { + "version": "0.1.2", + "bundled": true + }, + "jsbn": { + "version": "0.1.1", + "bundled": true, + "optional": true + }, + "json-schema": { + "version": "0.2.3", + "bundled": true + }, + "json-stable-stringify": { + "version": "1.0.1", + "bundled": true, + "requires": { + "jsonify": "0.0.0" + } + }, + "json-stringify-safe": { + "version": "5.0.1", + "bundled": true + }, + "jsonify": { + "version": "0.0.0", + "bundled": true + }, + "jsprim": { + "version": "1.4.1", + "bundled": true, + "requires": { + "assert-plus": "1.0.0", + "extsprintf": "1.3.0", + "json-schema": "0.2.3", + "verror": "1.10.0" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true + } + } + }, + "mime-db": { + "version": "1.30.0", + "bundled": true + }, + "mime-types": { + "version": "2.1.17", + "bundled": true, + "requires": { + "mime-db": "1.30.0" + } + }, + "minimatch": { + "version": "3.0.4", + "bundled": true, + "requires": { + "brace-expansion": "1.1.8" + } + }, + "minimist": { + "version": "0.0.8", + "bundled": true + }, + "mkdirp": { + "version": "0.5.1", + "bundled": true, + "requires": { + "minimist": "0.0.8" + } + }, + "ms": { + "version": "2.0.0", + "bundled": true + }, + "nan": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.8.0.tgz", + "integrity": "sha1-7XFfP+neArV6XmJS2QqWZ14fCFo=" + }, "node-pre-gyp": { - "version": "0.6.36", + "version": "0.6.39", "bundled": true, "requires": { + "detect-libc": "1.0.3", + "hawk": "3.1.3", "mkdirp": "0.5.1", "nopt": "4.0.1", "npmlog": "4.1.2", - "rc": "1.2.1", + "rc": "1.2.2", "request": "2.81.0", - "rimraf": "2.6.1", - "semver": "5.3.0", + "rimraf": "2.6.2", + "semver": "5.4.1", "tar": "2.2.1", - "tar-pack": "3.4.0" + "tar-pack": "3.4.1" + } + }, + "nopt": { + "version": "4.0.1", + "bundled": true, + "requires": { + "abbrev": "1.1.1", + "osenv": "0.1.4" + } + }, + "npmlog": { + "version": "4.1.2", + "bundled": true, + "requires": { + "are-we-there-yet": "1.1.4", + "console-control-strings": "1.1.0", + "gauge": "2.7.4", + "set-blocking": "2.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "bundled": true + }, + "oauth-sign": { + "version": "0.8.2", + "bundled": true + }, + "object-assign": { + "version": "4.1.1", + "bundled": true + }, + "once": { + "version": "1.4.0", + "bundled": true, + "requires": { + "wrappy": "1.0.2" + } + }, + "os-homedir": { + "version": "1.0.2", + "bundled": true + }, + "os-tmpdir": { + "version": "1.0.2", + "bundled": true + }, + "osenv": { + "version": "0.1.4", + "bundled": true, + "requires": { + "os-homedir": "1.0.2", + "os-tmpdir": "1.0.2" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "bundled": true + }, + "performance-now": { + "version": "0.2.0", + "bundled": true + }, + "process-nextick-args": { + "version": "1.0.7", + "bundled": true + }, + "punycode": { + "version": "1.4.1", + "bundled": true + }, + "qs": { + "version": "6.4.0", + "bundled": true + }, + "rc": { + "version": "1.2.2", + "bundled": true, + "requires": { + "deep-extend": "0.4.2", + "ini": "1.3.5", + "minimist": "1.2.0", + "strip-json-comments": "2.0.1" }, "dependencies": { - "mkdirp": { - "version": "0.5.1", - "bundled": true, - "requires": { - "minimist": "0.0.8" - }, - "dependencies": { - "minimist": { - "version": "0.0.8", - "bundled": true - } - } - }, - "nopt": { - "version": "4.0.1", - "bundled": true, - "requires": { - "abbrev": "1.1.0", - "osenv": "0.1.4" - }, - "dependencies": { - "abbrev": { - "version": "1.1.0", - "bundled": true - }, - "osenv": { - "version": "0.1.4", - "bundled": true, - "requires": { - "os-homedir": "1.0.2", - "os-tmpdir": "1.0.2" - }, - "dependencies": { - "os-homedir": { - "version": "1.0.2", - "bundled": true - }, - "os-tmpdir": { - "version": "1.0.2", - "bundled": true - } - } - } - } - }, - "npmlog": { - "version": "4.1.2", - "bundled": true, - "requires": { - "are-we-there-yet": "1.1.4", - "console-control-strings": "1.1.0", - "gauge": "2.7.4", - "set-blocking": "2.0.0" - }, - "dependencies": { - "are-we-there-yet": { - "version": "1.1.4", - "bundled": true, - "requires": { - "delegates": "1.0.0", - "readable-stream": "2.3.2" - }, - "dependencies": { - "delegates": { - "version": "1.0.0", - "bundled": true - }, - "readable-stream": { - "version": "2.3.2", - "bundled": true, - "requires": { - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "1.0.0", - "process-nextick-args": "1.0.7", - "safe-buffer": "5.1.1", - "string_decoder": "1.0.3", - "util-deprecate": "1.0.2" - }, - "dependencies": { - "core-util-is": { - "version": "1.0.2", - "bundled": true - }, - "inherits": { - "version": "2.0.3", - "bundled": true - }, - "isarray": { - "version": "1.0.0", - "bundled": true - }, - "process-nextick-args": { - "version": "1.0.7", - "bundled": true - }, - "safe-buffer": { - "version": "5.1.1", - "bundled": true - }, - "string_decoder": { - "version": "1.0.3", - "bundled": true, - "requires": { - "safe-buffer": "5.1.1" - } - }, - "util-deprecate": { - "version": "1.0.2", - "bundled": true - } - } - } - } - }, - "console-control-strings": { - "version": "1.1.0", - "bundled": true - }, - "gauge": { - "version": "2.7.4", - "bundled": true, - "requires": { - "aproba": "1.1.2", - "console-control-strings": "1.1.0", - "has-unicode": "2.0.1", - "object-assign": "4.1.1", - "signal-exit": "3.0.2", - "string-width": "1.0.2", - "strip-ansi": "3.0.1", - "wide-align": "1.1.2" - }, - "dependencies": { - "aproba": { - "version": "1.1.2", - "bundled": true - }, - "has-unicode": { - "version": "2.0.1", - "bundled": true - }, - "object-assign": { - "version": "4.1.1", - "bundled": true - }, - "signal-exit": { - "version": "3.0.2", - "bundled": true - }, - "string-width": { - "version": "1.0.2", - "bundled": true, - "requires": { - "code-point-at": "1.1.0", - "is-fullwidth-code-point": "1.0.0", - "strip-ansi": "3.0.1" - }, - "dependencies": { - "code-point-at": { - "version": "1.1.0", - "bundled": true - }, - "is-fullwidth-code-point": { - "version": "1.0.0", - "bundled": true, - "requires": { - "number-is-nan": "1.0.1" - }, - "dependencies": { - "number-is-nan": { - "version": "1.0.1", - "bundled": true - } - } - } - } - }, - "strip-ansi": { - "version": "3.0.1", - "bundled": true, - "requires": { - "ansi-regex": "2.1.1" - }, - "dependencies": { - "ansi-regex": { - "version": "2.1.1", - "bundled": true - } - } - }, - "wide-align": { - "version": "1.1.2", - "bundled": true, - "requires": { - "string-width": "1.0.2" - } - } - } - }, - "set-blocking": { - "version": "2.0.0", - "bundled": true - } - } - }, - "rc": { - "version": "1.2.1", - "bundled": true, - "requires": { - "deep-extend": "0.4.2", - "ini": "1.3.4", - "minimist": "1.2.0", - "strip-json-comments": "2.0.1" - }, - "dependencies": { - "deep-extend": { - "version": "0.4.2", - "bundled": true - }, - "ini": { - "version": "1.3.4", - "bundled": true - }, - "minimist": { - "version": "1.2.0", - "bundled": true - }, - "strip-json-comments": { - "version": "2.0.1", - "bundled": true - } - } - }, - "request": { - "version": "2.81.0", - "bundled": true, - "requires": { - "aws-sign2": "0.6.0", - "aws4": "1.6.0", - "caseless": "0.12.0", - "combined-stream": "1.0.5", - "extend": "3.0.1", - "forever-agent": "0.6.1", - "form-data": "2.1.4", - "har-validator": "4.2.1", - "hawk": "3.1.3", - "http-signature": "1.1.1", - "is-typedarray": "1.0.0", - "isstream": "0.1.2", - "json-stringify-safe": "5.0.1", - "mime-types": "2.1.15", - "oauth-sign": "0.8.2", - "performance-now": "0.2.0", - "qs": "6.4.0", - "safe-buffer": "5.1.1", - "stringstream": "0.0.5", - "tough-cookie": "2.3.2", - "tunnel-agent": "0.6.0", - "uuid": "3.1.0" - }, - "dependencies": { - "aws-sign2": { - "version": "0.6.0", - "bundled": true - }, - "aws4": { - "version": "1.6.0", - "bundled": true - }, - "caseless": { - "version": "0.12.0", - "bundled": true - }, - "combined-stream": { - "version": "1.0.5", - "bundled": true, - "requires": { - "delayed-stream": "1.0.0" - }, - "dependencies": { - "delayed-stream": { - "version": "1.0.0", - "bundled": true - } - } - }, - "extend": { - "version": "3.0.1", - "bundled": true - }, - "forever-agent": { - "version": "0.6.1", - "bundled": true - }, - "form-data": { - "version": "2.1.4", - "bundled": true, - "requires": { - "asynckit": "0.4.0", - "combined-stream": "1.0.5", - "mime-types": "2.1.15" - }, - "dependencies": { - "asynckit": { - "version": "0.4.0", - "bundled": true - } - } - }, - "har-validator": { - "version": "4.2.1", - "bundled": true, - "requires": { - "ajv": "4.11.8", - "har-schema": "1.0.5" - }, - "dependencies": { - "ajv": { - "version": "4.11.8", - "bundled": true, - "requires": { - "co": "4.6.0", - "json-stable-stringify": "1.0.1" - }, - "dependencies": { - "co": { - "version": "4.6.0", - "bundled": true - }, - "json-stable-stringify": { - "version": "1.0.1", - "bundled": true, - "requires": { - "jsonify": "0.0.0" - }, - "dependencies": { - "jsonify": { - "version": "0.0.0", - "bundled": true - } - } - } - } - }, - "har-schema": { - "version": "1.0.5", - "bundled": true - } - } - }, - "hawk": { - "version": "3.1.3", - "bundled": true, - "requires": { - "boom": "2.10.1", - "cryptiles": "2.0.5", - "hoek": "2.16.3", - "sntp": "1.0.9" - }, - "dependencies": { - "boom": { - "version": "2.10.1", - "bundled": true, - "requires": { - "hoek": "2.16.3" - } - }, - "cryptiles": { - "version": "2.0.5", - "bundled": true, - "requires": { - "boom": "2.10.1" - } - }, - "hoek": { - "version": "2.16.3", - "bundled": true - }, - "sntp": { - "version": "1.0.9", - "bundled": true, - "requires": { - "hoek": "2.16.3" - } - } - } - }, - "http-signature": { - "version": "1.1.1", - "bundled": true, - "requires": { - "assert-plus": "0.2.0", - "jsprim": "1.4.0", - "sshpk": "1.13.1" - }, - "dependencies": { - "assert-plus": { - "version": "0.2.0", - "bundled": true - }, - "jsprim": { - "version": "1.4.0", - "bundled": true, - "requires": { - "assert-plus": "1.0.0", - "extsprintf": "1.0.2", - "json-schema": "0.2.3", - "verror": "1.3.6" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "bundled": true - }, - "extsprintf": { - "version": "1.0.2", - "bundled": true - }, - "json-schema": { - "version": "0.2.3", - "bundled": true - }, - "verror": { - "version": "1.3.6", - "bundled": true, - "requires": { - "extsprintf": "1.0.2" - } - } - } - }, - "sshpk": { - "version": "1.13.1", - "bundled": true, - "requires": { - "asn1": "0.2.3", - "assert-plus": "1.0.0", - "bcrypt-pbkdf": "1.0.1", - "dashdash": "1.14.1", - "ecc-jsbn": "0.1.1", - "getpass": "0.1.7", - "jsbn": "0.1.1", - "tweetnacl": "0.14.5" - }, - "dependencies": { - "asn1": { - "version": "0.2.3", - "bundled": true - }, - "assert-plus": { - "version": "1.0.0", - "bundled": true - }, - "bcrypt-pbkdf": { - "version": "1.0.1", - "bundled": true, - "optional": true, - "requires": { - "tweetnacl": "0.14.5" - } - }, - "dashdash": { - "version": "1.14.1", - "bundled": true, - "requires": { - "assert-plus": "1.0.0" - } - }, - "ecc-jsbn": { - "version": "0.1.1", - "bundled": true, - "optional": true, - "requires": { - "jsbn": "0.1.1" - } - }, - "getpass": { - "version": "0.1.7", - "bundled": true, - "requires": { - "assert-plus": "1.0.0" - } - }, - "jsbn": { - "version": "0.1.1", - "bundled": true, - "optional": true - }, - "tweetnacl": { - "version": "0.14.5", - "bundled": true, - "optional": true - } - } - } - } - }, - "is-typedarray": { - "version": "1.0.0", - "bundled": true - }, - "isstream": { - "version": "0.1.2", - "bundled": true - }, - "json-stringify-safe": { - "version": "5.0.1", - "bundled": true - }, - "mime-types": { - "version": "2.1.15", - "bundled": true, - "requires": { - "mime-db": "1.27.0" - }, - "dependencies": { - "mime-db": { - "version": "1.27.0", - "bundled": true - } - } - }, - "oauth-sign": { - "version": "0.8.2", - "bundled": true - }, - "performance-now": { - "version": "0.2.0", - "bundled": true - }, - "qs": { - "version": "6.4.0", - "bundled": true - }, - "safe-buffer": { - "version": "5.1.1", - "bundled": true - }, - "stringstream": { - "version": "0.0.5", - "bundled": true - }, - "tough-cookie": { - "version": "2.3.2", - "bundled": true, - "requires": { - "punycode": "1.4.1" - }, - "dependencies": { - "punycode": { - "version": "1.4.1", - "bundled": true - } - } - }, - "tunnel-agent": { - "version": "0.6.0", - "bundled": true, - "requires": { - "safe-buffer": "5.1.1" - } - }, - "uuid": { - "version": "3.1.0", - "bundled": true - } - } - }, - "rimraf": { - "version": "2.6.1", - "bundled": true, - "requires": { - "glob": "7.1.2" - }, - "dependencies": { - "glob": { - "version": "7.1.2", - "bundled": true, - "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" - }, - "dependencies": { - "fs.realpath": { - "version": "1.0.0", - "bundled": true - }, - "inflight": { - "version": "1.0.6", - "bundled": true, - "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" - }, - "dependencies": { - "wrappy": { - "version": "1.0.2", - "bundled": true - } - } - }, - "inherits": { - "version": "2.0.3", - "bundled": true - }, - "minimatch": { - "version": "3.0.4", - "bundled": true, - "requires": { - "brace-expansion": "1.1.8" - }, - "dependencies": { - "brace-expansion": { - "version": "1.1.8", - "bundled": true, - "requires": { - "balanced-match": "1.0.0", - "concat-map": "0.0.1" - }, - "dependencies": { - "balanced-match": { - "version": "1.0.0", - "bundled": true - }, - "concat-map": { - "version": "0.0.1", - "bundled": true - } - } - } - } - }, - "once": { - "version": "1.4.0", - "bundled": true, - "requires": { - "wrappy": "1.0.2" - }, - "dependencies": { - "wrappy": { - "version": "1.0.2", - "bundled": true - } - } - }, - "path-is-absolute": { - "version": "1.0.1", - "bundled": true - } - } - } - } - }, - "semver": { - "version": "5.3.0", + "minimist": { + "version": "1.2.0", "bundled": true - }, - "tar": { - "version": "2.2.1", - "bundled": true, - "requires": { - "block-stream": "0.0.9", - "fstream": "1.0.11", - "inherits": "2.0.3" - }, - "dependencies": { - "block-stream": { - "version": "0.0.9", - "bundled": true, - "requires": { - "inherits": "2.0.3" - } - }, - "fstream": { - "version": "1.0.11", - "bundled": true, - "requires": { - "graceful-fs": "4.1.11", - "inherits": "2.0.3", - "mkdirp": "0.5.1", - "rimraf": "2.6.1" - }, - "dependencies": { - "graceful-fs": { - "version": "4.1.11", - "bundled": true - } - } - }, - "inherits": { - "version": "2.0.3", - "bundled": true - } - } - }, - "tar-pack": { - "version": "3.4.0", - "bundled": true, - "requires": { - "debug": "2.6.8", - "fstream": "1.0.11", - "fstream-ignore": "1.0.5", - "once": "1.4.0", - "readable-stream": "2.3.2", - "rimraf": "2.6.1", - "tar": "2.2.1", - "uid-number": "0.0.6" - }, - "dependencies": { - "debug": { - "version": "2.6.8", - "bundled": true, - "requires": { - "ms": "2.0.0" - }, - "dependencies": { - "ms": { - "version": "2.0.0", - "bundled": true - } - } - }, - "fstream": { - "version": "1.0.11", - "bundled": true, - "requires": { - "graceful-fs": "4.1.11", - "inherits": "2.0.3", - "mkdirp": "0.5.1", - "rimraf": "2.6.1" - }, - "dependencies": { - "graceful-fs": { - "version": "4.1.11", - "bundled": true - }, - "inherits": { - "version": "2.0.3", - "bundled": true - } - } - }, - "fstream-ignore": { - "version": "1.0.5", - "bundled": true, - "requires": { - "fstream": "1.0.11", - "inherits": "2.0.3", - "minimatch": "3.0.4" - }, - "dependencies": { - "inherits": { - "version": "2.0.3", - "bundled": true - }, - "minimatch": { - "version": "3.0.4", - "bundled": true, - "requires": { - "brace-expansion": "1.1.8" - }, - "dependencies": { - "brace-expansion": { - "version": "1.1.8", - "bundled": true, - "requires": { - "balanced-match": "1.0.0", - "concat-map": "0.0.1" - }, - "dependencies": { - "balanced-match": { - "version": "1.0.0", - "bundled": true - }, - "concat-map": { - "version": "0.0.1", - "bundled": true - } - } - } - } - } - } - }, - "once": { - "version": "1.4.0", - "bundled": true, - "requires": { - "wrappy": "1.0.2" - }, - "dependencies": { - "wrappy": { - "version": "1.0.2", - "bundled": true - } - } - }, - "readable-stream": { - "version": "2.3.2", - "bundled": true, - "requires": { - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "1.0.0", - "process-nextick-args": "1.0.7", - "safe-buffer": "5.1.1", - "string_decoder": "1.0.3", - "util-deprecate": "1.0.2" - }, - "dependencies": { - "core-util-is": { - "version": "1.0.2", - "bundled": true - }, - "inherits": { - "version": "2.0.3", - "bundled": true - }, - "isarray": { - "version": "1.0.0", - "bundled": true - }, - "process-nextick-args": { - "version": "1.0.7", - "bundled": true - }, - "safe-buffer": { - "version": "5.1.1", - "bundled": true - }, - "string_decoder": { - "version": "1.0.3", - "bundled": true, - "requires": { - "safe-buffer": "5.1.1" - } - }, - "util-deprecate": { - "version": "1.0.2", - "bundled": true - } - } - }, - "uid-number": { - "version": "0.0.6", - "bundled": true - } - } } } + }, + "readable-stream": { + "version": "2.3.3", + "bundled": true, + "requires": { + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "1.0.0", + "process-nextick-args": "1.0.7", + "safe-buffer": "5.1.1", + "string_decoder": "1.0.3", + "util-deprecate": "1.0.2" + } + }, + "request": { + "version": "2.81.0", + "bundled": true, + "requires": { + "aws-sign2": "0.6.0", + "aws4": "1.6.0", + "caseless": "0.12.0", + "combined-stream": "1.0.5", + "extend": "3.0.1", + "forever-agent": "0.6.1", + "form-data": "2.1.4", + "har-validator": "4.2.1", + "hawk": "3.1.3", + "http-signature": "1.1.1", + "is-typedarray": "1.0.0", + "isstream": "0.1.2", + "json-stringify-safe": "5.0.1", + "mime-types": "2.1.17", + "oauth-sign": "0.8.2", + "performance-now": "0.2.0", + "qs": "6.4.0", + "safe-buffer": "5.1.1", + "stringstream": "0.0.5", + "tough-cookie": "2.3.3", + "tunnel-agent": "0.6.0", + "uuid": "3.1.0" + } + }, + "rimraf": { + "version": "2.6.2", + "bundled": true, + "requires": { + "glob": "7.1.2" + } + }, + "safe-buffer": { + "version": "5.1.1", + "bundled": true + }, + "semver": { + "version": "5.4.1", + "bundled": true + }, + "set-blocking": { + "version": "2.0.0", + "bundled": true + }, + "signal-exit": { + "version": "3.0.2", + "bundled": true + }, + "sntp": { + "version": "1.0.9", + "bundled": true, + "requires": { + "hoek": "2.16.3" + } + }, + "sshpk": { + "version": "1.13.1", + "bundled": true, + "requires": { + "asn1": "0.2.3", + "assert-plus": "1.0.0", + "bcrypt-pbkdf": "1.0.1", + "dashdash": "1.14.1", + "ecc-jsbn": "0.1.1", + "getpass": "0.1.7", + "jsbn": "0.1.1", + "tweetnacl": "0.14.5" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true + } + } + }, + "string-width": { + "version": "1.0.2", + "bundled": true, + "requires": { + "code-point-at": "1.1.0", + "is-fullwidth-code-point": "1.0.0", + "strip-ansi": "3.0.1" + } + }, + "string_decoder": { + "version": "1.0.3", + "bundled": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, + "stringstream": { + "version": "0.0.5", + "bundled": true + }, + "strip-ansi": { + "version": "3.0.1", + "bundled": true, + "requires": { + "ansi-regex": "2.1.1" + } + }, + "strip-json-comments": { + "version": "2.0.1", + "bundled": true + }, + "tar": { + "version": "2.2.1", + "bundled": true, + "requires": { + "block-stream": "0.0.9", + "fstream": "1.0.11", + "inherits": "2.0.3" + } + }, + "tar-pack": { + "version": "3.4.1", + "bundled": true, + "requires": { + "debug": "2.6.9", + "fstream": "1.0.11", + "fstream-ignore": "1.0.5", + "once": "1.4.0", + "readable-stream": "2.3.3", + "rimraf": "2.6.2", + "tar": "2.2.1", + "uid-number": "0.0.6" + } + }, + "tough-cookie": { + "version": "2.3.3", + "bundled": true, + "requires": { + "punycode": "1.4.1" + } + }, + "tunnel-agent": { + "version": "0.6.0", + "bundled": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, + "tweetnacl": { + "version": "0.14.5", + "bundled": true, + "optional": true + }, + "uid-number": { + "version": "0.0.6", + "bundled": true + }, + "util-deprecate": { + "version": "1.0.2", + "bundled": true + }, + "uuid": { + "version": "3.1.0", + "bundled": true + }, + "verror": { + "version": "1.10.0", + "bundled": true, + "requires": { + "assert-plus": "1.0.0", + "core-util-is": "1.0.2", + "extsprintf": "1.3.0" + }, + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "bundled": true + } + } + }, + "wide-align": { + "version": "1.1.2", + "bundled": true, + "requires": { + "string-width": "1.0.2" + } + }, + "wrappy": { + "version": "1.0.2", + "bundled": true } } }, @@ -2825,6 +2671,11 @@ "integrity": "sha1-3hqm1j6indJIc3tp8f+LgALSEIw=", "dev": true }, + "is-wsl": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-1.1.0.tgz", + "integrity": "sha1-HxbkqiKwTRM2tmGIpmrzxgDDpm0=" + }, "isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", @@ -3587,7 +3438,8 @@ "nan": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/nan/-/nan-2.6.2.tgz", - "integrity": "sha1-5P805slf37WuzAjeZZb0NgWn20U=" + "integrity": "sha1-5P805slf37WuzAjeZZb0NgWn20U=", + "dev": true }, "natives": { "version": "1.1.0", @@ -3701,6 +3553,14 @@ "wrappy": "1.0.2" } }, + "opn": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/opn/-/opn-5.1.0.tgz", + "integrity": "sha512-iPNl7SyM8L30Rm1sjGdLLheyHVw5YXVfi3SKWJzBI7efxRwHojfRFjwE/OLM6qp9xJYMgab8WicTU1cPoY+Hpg==", + "requires": { + "is-wsl": "1.1.0" + } + }, "optjs": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/optjs/-/optjs-3.2.2.tgz", diff --git a/package.json b/package.json index f8e19aa..a0d760e 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,10 @@ "author": "Alan Wernick", "license": "ISC", "dependencies": { + "dotenv": "^4.0.0", "google-protobuf": "^3.3.0", - "grpc": "^1.3.8" + "grpc": "^1.8.0", + "opn": "^5.1.0" }, "devDependencies": { "@types/chai": "^4.0.0", diff --git a/ts/examples/text-conversation.ts b/ts/examples/text-conversation.ts index b87fcc7..054a87b 100644 --- a/ts/examples/text-conversation.ts +++ b/ts/examples/text-conversation.ts @@ -1,26 +1,15 @@ +require('dotenv').load(); /** Loading .env file where you can store your API keys for the app */ + import GoogleAssistant = require("../lib/google-assistant"); -import * as stream from "stream"; const constants = GoogleAssistant.Constants; const encoding = constants.Encoding; const google = require('googleapis'); +const opn = require('opn'); const OAuth2 = google.auth.OAuth2; -//const Speaker = require('speaker'); - -// Setup the speaker for PCM data -/* -let speaker = new Speaker({ - channels: 1, - bitDepth: 16, - sampleRate: 16000 -}) -*/ - -// Start the Assistant to process 16Hz PCM data from the mic, -// and send the data correctly to the speaker. let assistant = new GoogleAssistant({ output: { encoding: encoding.LINEAR16, @@ -32,42 +21,41 @@ let assistant = new GoogleAssistant({ deviceModelId: 'ga-desktop-electron', }, languageCode: 'en-US', -}) +}); + +const readline = require('readline'); + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); // The Assistant is connected to Google and is ready to receive audio // data from the mic. -assistant.on('ready', (conversationStream: stream.Writable) => { - console.log("Ready"); -}) - -// Transcription of the audio recorded by the mic -assistant.on('request-text', (text: string) => { - console.log("Request Text: ", text); +assistant.on('ready', () => { + // We're not using this for the text conversation. }) - // Transcription of the Assistant's response. // Google sometimes does not send this text, so don't rely // to heavily on it. -assistant.on('speech-results', (results: any) => { - console.log("Response Text: ", results); +assistant.on('response-text', (text: any) => { + console.log('Google Assistant:', text); }) -// This is the Assistant's audio response. Send it to the speakers. -assistant.on('audio-data', (data: Array) => { - //speaker.write(data) +assistant.on('follow-on', (object: any) => { + startConversation(); }) // There was an error somewhere. Stop the mic and speaker streams. assistant.on('error', (err: Error) => { console.error(err); console.log("Error ocurred. Exiting..."); - //speaker.end(); }) // The conversation is over. Close the microphone and the speakers. -assistant.once('end', () => { - console.log('ended.'); +assistant.on('end', () => { + startConversation(); }) assistant.once('unauthorized', () => { @@ -78,36 +66,74 @@ assistant.once('unauthorized', () => { // to create a Google Cloud Platform project to use the Google Assistant. // You also need to enable the Google Assistant API in your GCP project // in order to use the SDK. +// Defaulting the redirect URL to display the code so we can input it in the console. var authClient = new OAuth2( - '1008767088687-rjpej2ecgpl7ktvtnlmnpkl9hgl4odch.apps.googleusercontent.com' || process.env.CLIENT_ID, - 'Ryn_0H-etWquCeSIJj8y9koX' || process.env.CLIENT_SECRET, + process.env.CLIENT_ID || 'YOUR_CLIENT_ID', + process.env.CLIENT_SECRET || 'YOUR_CLIENT_SECRET', + process.env.REDIRECT_URL || 'urn:ietf:wg:oauth:2.0:oob' // Default to output code oob in window ); -// Retrieve tokens via token exchange explained here: -// https://github.com/google/google-api-nodejs-client -// -// There are also many other methods to obtain an access token from Google. -// Please read the following for more information: -// https://developers.google.com/identity/protocols/OAuth2 -authClient.setCredentials({ - access_token: 'ya29.GlsyBS2ywk7-zhFdHn1Rrc0d2FcPnn8oWVNjgE24-ve7zkJgCSrOOy6Djs5CYVbX2nOL9DoeB-3Pg1hr_RNDM5-pz2HMBSX9Wj43agMoJSS9z6wewwK_iDHqy19k', - refresh_token: '1/hf2ljFUQGDQXG2AczXIuWOn0mRCZBPx6FB7AMJ5smAA' -}); -const readline = require('readline'); +/** Saving profile name for nice chatty output */ +var url = authClient.generateAuthUrl({ + // 'online' (default) or 'offline' (gets refresh_token) + access_type: 'offline', -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout + // If you only need one scope you can pass it as a string + scope: ['https://www.googleapis.com/auth/assistant-sdk-prototype', + 'https://www.googleapis.com/auth/userinfo.profile'], }); -let textQuery; +console.log('Login and get your refresh token.'); +console.log(url) + +try { +opn(url); +} catch (error) { + //trying to open url, if not possible, use url mentioned in console. +} + +let userName: any; + +/** Asking for auth code form authentication URL */ +rl.question('Auth code: ', function(code: any) { + /** Getting tokens from Google to authenticate */ + authClient.getToken(code, function (err: any, tokens: any) { + if (!err) { + authClient.setCredentials(tokens); + console.log('Authentication succesful!'); + + /** Authenticating the Google Assistant */ + assistant.authenticate(authClient); + + /** Getting the user profile information */ + var oauth2 = google.oauth2({ + auth: authClient, + version: 'v2' + }); + + oauth2.userinfo.v2.me.get(function (err: any, result: any) { + /** Saving profile name for nice chatty output */ + userName = result.given_name; + startConversation(); + }); + } else { + console.log('Error happend, exiting....'); + } + }); +}); -assistant.authenticate(authClient); +/** Starting a conversation, getting console input and sending it to google. */ +function startConversation() { + let textQuery; -rl.question('What would you like to say to Google Assistant?', (input: any) => { - console.log(`${input}`); - rl.close(); - assistant.assist(input); + rl.question(userName + ': ', (input: any) => { + if(input) { + assistant.assist(input); + } else { + console.log('Whooppss, seems like you didn\'t say anything.'); + } }); +} + diff --git a/ts/lib/google-assistant.ts b/ts/lib/google-assistant.ts index c9eb68e..f35a071 100644 --- a/ts/lib/google-assistant.ts +++ b/ts/lib/google-assistant.ts @@ -22,6 +22,7 @@ class GoogleAssistant extends events.EventEmitter { private assistConfig: AssistConfig private conversationState: Array | null private textQuery: string | null + private languageCode: string private audioInConfig: AudioInConfig; private audioOutConfig: AudioOutConfig; @@ -55,6 +56,7 @@ class GoogleAssistant extends events.EventEmitter { } public setLanguageCode(languageCode: string) { + this.languageCode = languageCode; this.dialogStateIn.setLanguageCode(languageCode); } @@ -118,8 +120,6 @@ class GoogleAssistant extends events.EventEmitter { this.channel.on('end', this._handleConversationEnd.bind(this)); // Write first AssistRequest - console.log('Request:'); - console.log(request); this.channel.write(request) this.state = State.IN_PROGRESS; @@ -200,6 +200,7 @@ class GoogleAssistant extends events.EventEmitter { // Handle continous conversations if(state.getConversationState()) { let diaState = new messages.DialogStateIn(this.dialogStateIn); + diaState.setLanguageCode(this.languageCode); diaState.setConversationState(state.getConversationState()); this.dialogStateIn = diaState; } From ba97dd54267e779e9779685bbefc965e0c05e51a Mon Sep 17 00:00:00 2001 From: Date: Sat, 30 Dec 2017 15:35:37 +0100 Subject: [PATCH 3/4] updated version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a0d760e..a2a6dda 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "google-assistant-node", - "version": "0.0.15", + "version": "0.1.0", "description": "Google Assistant SDK wrapper for Node", "main": "./lib/google-assistant.js", "types": "./lib/google-assistant.d.ts", From 247f51a4c9e07cabc58df8e767aed5dcb8d4cc1a Mon Sep 17 00:00:00 2001 From: Date: Sun, 31 Dec 2017 04:53:10 +0100 Subject: [PATCH 4/4] feature: support for actions --- package-lock.json | 2 +- package.json | 6 +-- ts/examples/pcm-audio.ts | 88 +++++++++++++++++++++++++++----------- ts/lib/audio-converter.ts | 4 +- ts/lib/google-assistant.ts | 11 ++--- 5 files changed, 73 insertions(+), 38 deletions(-) diff --git a/package-lock.json b/package-lock.json index f3f3e60..e7319cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "google-assistant-node", - "version": "0.0.15", + "version": "0.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a2a6dda..459107d 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "build": "npm run copy-googleapis && tsc", "build:test": "gulp", "build:live": "gulp watch", - "test": "npm run build:test && mocha build/test", + "build-windows": "rd /s /q lib && rd /s /q lib", "copy-googleapis": "mkdir -p lib && cp -r googleapis lib/", "prepublish": "npm run build" }, @@ -24,8 +24,7 @@ "license": "ISC", "dependencies": { "dotenv": "^4.0.0", - "google-protobuf": "^3.3.0", - "grpc": "^1.8.0", + "google-protobuf": "^3.5.0", "opn": "^5.1.0" }, "devDependencies": { @@ -39,7 +38,6 @@ "gulp-typescript": "^3.1.7", "mic": "^2.1.2", "mocha": "^3.4.2", - "speaker": "^0.4.0", "typescript": "^2.3.4" }, "repository": { diff --git a/ts/examples/pcm-audio.ts b/ts/examples/pcm-audio.ts index e587e6d..4bd9f77 100644 --- a/ts/examples/pcm-audio.ts +++ b/ts/examples/pcm-audio.ts @@ -1,3 +1,5 @@ +require('dotenv').load(); /** Loading .env file where you can store your API keys for the app */ + /** * Record audio using the internal microphone, * send it to the Google Assistant and listen to the response @@ -16,6 +18,8 @@ const OAuth2 = google.auth.OAuth2; const Speaker = require('speaker'); const Microphone = require('mic'); +const opn = require('opn'); + // Setup the speaker for PCM data let speaker = new Speaker({ channels: 1, @@ -30,6 +34,13 @@ let mic = new Microphone({ debug: true, }) +const readline = require('readline'); + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + // Start the Assistant to process 16Hz PCM data from the mic, // and send the data correctly to the speaker. let assistant = new GoogleAssistant({ @@ -57,9 +68,9 @@ assistant.on('ready', (conversationStream: stream.Writable) => { }) // Transcription of the audio recorded by the mic -assistant.on('request-text', (text: string) => { - console.log("Request Text: ", text) -}) +assistant.on('speech-results', (results: any) => { + console.log("Speech results: ", results); +}); // Transcription of the Assistant's response. @@ -83,9 +94,8 @@ assistant.on('error', (err: Error) => { }) // The conversation is over. Close the microphone and the speakers. -assistant.once('end', () => { - speaker.end(); - mic.stop(); +assistant.on('end', () => { + startConversation(); }) assistant.once('unauthorized', () => { @@ -98,30 +108,60 @@ assistant.once('unauthorized', () => { // to create a Google Cloud Platform project to use the Google Assistant. // You also need to enable the Google Assistant API in your GCP project // in order to use the SDK. +// Defaulting the redirect URL to display the code so we can input it in the console. var authClient = new OAuth2( - 'YOUR_CLIENT_ID' || process.env.CLIENT_ID, - 'YOUR_CLIENT_SECRET' || process.env.CLIENT_SECRET, - 'YOUR (OPTIONAL) REDIRECT_URL' || process.env.REDIRECT_URL + process.env.CLIENT_ID || 'YOUR_CLIENT_ID', + process.env.CLIENT_SECRET || 'YOUR_CLIENT_SECRET', + process.env.REDIRECT_URL || 'urn:ietf:wg:oauth:2.0:oob' // Default to output code oob in window ); -// Retrieve tokens via token exchange explained here: -// https://github.com/google/google-api-nodejs-client -// -// There are also many other methods to obtain an access token from Google. -// Please read the following for more information: -// https://developers.google.com/identity/protocols/OAuth2 -authClient.setCredentials({ - access_token: 'ACCESS TOKEN HERE', - refresh_token: 'REFRESH TOKEN HERE' - // Optional, provide an expiry_date (milliseconds since the Unix Epoch) - // expiry_date: (new Date()).getTime() + (1000 * 60 * 60 * 24 * 7) + +/** Saving profile name for nice chatty output */ +var url = authClient.generateAuthUrl({ + // 'online' (default) or 'offline' (gets refresh_token) + access_type: 'offline', + + // If you only need one scope you can pass it as a string + scope: ['https://www.googleapis.com/auth/assistant-sdk-prototype', + 'https://www.googleapis.com/auth/userinfo.profile'], +}); + +console.log('Login and get your refresh token.'); +console.log(url) + +try { +opn(url); +} catch (error) { + //trying to open url, if not possible, use url mentioned in console. +} + +let userName: any; + +/** Asking for auth code form authentication URL */ +rl.question('Auth code: ', function(code: any) { + /** Getting tokens from Google to authenticate */ + authClient.getToken(code, function (err: any, tokens: any) { + if (!err) { + authClient.setCredentials(tokens); + console.log('Authentication succesful!'); + + /** Authenticating the Google Assistant */ + assistant.authenticate(authClient); + + startConversation(); + } else { + console.log('Error happend, exiting....'); + } + }); }); // Authenticate the Asssistant using a Google OAuth2Client assistant.authenticate(authClient); -// Start the conversation with the Google Assistant. -// Remember that you should start piping data once the `ready` event has -// been fired. -assistant.assist(); +function startConversation() { + console.log('Press any key to say something to Google, wait for your signal.'); + process.stdin.resume(); + process.stdin.on('data', () => { assistant.assist() }); +} + diff --git a/ts/lib/audio-converter.ts b/ts/lib/audio-converter.ts index 668808b..67869ff 100644 --- a/ts/lib/audio-converter.ts +++ b/ts/lib/audio-converter.ts @@ -1,5 +1,5 @@ import * as stream from "stream"; -let messages = require('./googleapis/google/assistant/embedded/v1alpha1/embedded_assistant_pb'); +let messages = require('./googleapis/google/assistant/embedded/v1alpha2/embedded_assistant_pb'); class AudioConverter extends stream.Transform { constructor() { @@ -14,7 +14,7 @@ class AudioConverter extends stream.Transform { for(var i = 0; i < chunk.length / size; i++) { var nibble = buff.slice(offset, (offset + size)); offset += size; - var request = new messages.ConverseRequest(); + var request = new messages.AssistRequest(); request.setAudioIn(nibble); this.push(request); } diff --git a/ts/lib/google-assistant.ts b/ts/lib/google-assistant.ts index f35a071..adc3d98 100644 --- a/ts/lib/google-assistant.ts +++ b/ts/lib/google-assistant.ts @@ -93,7 +93,6 @@ class GoogleAssistant extends events.EventEmitter { } public assist(textQuery?: string) { - // [TODO]: Add support for text-input requests if(this.state == State.IN_PROGRESS && this.dialogStateIn.conversationState != null) { this.assistConfig.setDialogStateIn(this.dialogStateIn); this.dialogStateIn.conversationState = null; @@ -143,7 +142,7 @@ class GoogleAssistant extends events.EventEmitter { } private _handleAssistResponse(response: any) { - if(response.getEventType() == Event.END_OF_UTTERANCE) { + if(response.getEventType() === Event.END_OF_UTTERANCE) { this.emit('end-of-utterance'); } @@ -161,12 +160,10 @@ class GoogleAssistant extends events.EventEmitter { ); } - // [TODO]: Add support for device actions. - /* - if(response.hasError()) { - this.emit('error', response.getError()); + if(response.hasDeviceAction()) { + this.emit('device-request', + JSON.parse(response.getDeviceAction().toObject().deviceRequestJson)); } - */ } private _handleDialogStateOut(state: any) {