Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/speech/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@
],
"dependencies": {
"@google-cloud/common": "^0.5.0",
"arguejs": "^0.2.3",
"events-intercept": "^2.0.0",
"extend": "^3.0.0",
"google-gax": "^0.6.0",
"google-proto-files": "^0.7.0",
"is": "^3.1.0",
"modelo": "^4.2.0",
Expand Down
1 change: 1 addition & 0 deletions packages/speech/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,3 +827,4 @@ Speech.prototype.startRecognition = function(file, config, callback) {
};

module.exports = Speech;
module.exports.v1beta1 = require('./v1beta1');
31 changes: 31 additions & 0 deletions packages/speech/src/v1beta1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*!
* Copyright 2016 Google Inc. All Rights Reserved.
*
* 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 speechApi = require('./speech_api');
var gax = require('google-gax');
var extend = require('extend');

function v1beta1(options) {
options = extend({
scopes: v1beta1.ALL_SCOPES
}, options);
var gaxGrpc = gax.grpc(options);
return speechApi(gaxGrpc);
}
v1beta1.SERVICE_ADDRESS = speechApi.SERVICE_ADDRESS;
v1beta1.ALL_SCOPES = speechApi.ALL_SCOPES;
module.exports = v1beta1;
254 changes: 254 additions & 0 deletions packages/speech/src/v1beta1/speech_api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
/*
* Copyright 2016 Google Inc. All rights reserved.
*
* 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.
*
* EDITING INSTRUCTIONS
* This file was generated from the file
* https://github.com/googleapis/googleapis/blob/master/google/cloud/speech/v1beta1/cloud_speech.proto,
* and updates to that file get reflected here through a refresh process.
* For the short term, the refresh process will only be runnable by Google
* engineers.
*
* The only allowed edits are to method and file documentation. A 3-way
* merge preserves those additions if the generated source changes.
*/
/* TODO: introduce line-wrapping so that it never exceeds the limit. */
/* jscs: disable maximumLineLength */
'use strict';

var arguejs = require('arguejs');
var configData = require('./speech_client_config');
var extend = require('extend');
var gax = require('google-gax');

var SERVICE_ADDRESS = 'speech.googleapis.com';

var DEFAULT_SERVICE_PORT = 443;

var CODE_GEN_NAME_VERSION = 'gapic/0.1.0';

var DEFAULT_TIMEOUT = 30;

/**
* The scopes needed to make gRPC calls to all of the methods defined in
* this service.
*/
var ALL_SCOPES = [
'https://www.googleapis.com/auth/cloud-platform'
];

/**
* Service that implements Google Cloud Speech API.
*
* This will be created through a builder function which can be obtained by the module.
* See the following example of how to initialize the module and how to access to the builder.
* @see {@link speechApi}
*
* @example
* var speechV1beta1 = require('@google-cloud/speech').v1beta1({
* // optional auth parameters.
* });
* var api = speechV1beta1.speechApi();
*
* @class
*/
function SpeechApi(gaxGrpc, grpcClients, opts) {
opts = opts || {};
var servicePath = opts.servicePath || SERVICE_ADDRESS;
var port = opts.port || DEFAULT_SERVICE_PORT;
var sslCreds = opts.sslCreds || null;
var clientConfig = opts.clientConfig || {};
var timeout = opts.timeout || DEFAULT_TIMEOUT;
var appName = opts.appName || 'gax';
var appVersion = opts.appVersion || gax.version;

var googleApiClient = [
appName + '/' + appVersion,
CODE_GEN_NAME_VERSION,
'gax/' + gax.version,
'nodejs/' + process.version].join(' ');

var defaults = gaxGrpc.constructSettings(
'google.cloud.speech.v1beta1.Speech',
configData,
clientConfig,
timeout,
null,
null,
{'x-goog-api-client': googleApiClient});

var speechStub = gaxGrpc.createStub(
servicePath,
port,
grpcClients.speechClient.google.cloud.speech.v1beta1.Speech,
{sslCreds: sslCreds});
var speechStubMethods = [
'syncRecognize',
'asyncRecognize'
];
speechStubMethods.forEach(function(methodName) {
this['_' + methodName] = gax.createApiCall(
speechStub.then(function(speechStub) {
return speechStub[methodName].bind(speechStub);
}),
defaults[methodName]);
}.bind(this));
}

// Service calls

/**
* Perform synchronous speech-recognition: receive results after all audio
* has been sent and processed.
*
* @param {Object} config
* [Required] The `config` message provides information to the recognizer
* that specifies how to process the request.
*
* This object should have the same structure as [RecognitionConfig]{@link RecognitionConfig}
* @param {Object} audio
* [Required] The audio data to be recognized.
*
* This object should have the same structure as [RecognitionAudio]{@link RecognitionAudio}
* @param {gax.CallOptions=} options
* Overrides the default settings for this call, e.g, timeout,
* retries, etc.
* @param {function(?Error, ?Object)=} callback
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [SyncRecognizeResponse]{@link SyncRecognizeResponse}
* @returns {gax.EventEmitter} - the event emitter to handle the call
* status.
*
* @example
*
* var api = speechV1beta1.speechApi();
* var config = {};
* var audio = {};
* api.syncRecognize(config, audio, function(err, response) {
* if (err) {
* console.error(err);
* return;
* }
* // doThingsWith(response)
* });
*/
SpeechApi.prototype.syncRecognize = function syncRecognize() {
var args = arguejs({
config: Object,
audio: Object,
options: [gax.CallOptions],
callback: [Function]
}, arguments);
var req = {
config: args.config,
audio: args.audio
};
return this._syncRecognize(req, args.options, args.callback);
};

/**
* Perform asynchronous speech-recognition: receive results via the
* google.longrunning.Operations interface. `Operation.response` returns
* `AsyncRecognizeResponse`.
*
* @param {Object} config
* [Required] The `config` message provides information to the recognizer
* that specifies how to process the request.
*
* This object should have the same structure as [RecognitionConfig]{@link RecognitionConfig}
* @param {Object} audio
* [Required] The audio data to be recognized.
*
* This object should have the same structure as [RecognitionAudio]{@link RecognitionAudio}
* @param {gax.CallOptions=} options
* Overrides the default settings for this call, e.g, timeout,
* retries, etc.
* @param {function(?Error, ?Object)=} callback
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [google.longrunning.Operation]{@link external:"google.longrunning.Operation"}
* @returns {gax.EventEmitter} - the event emitter to handle the call
* status.
*
* @example
*
* var api = speechV1beta1.speechApi();
* var config = {};
* var audio = {};
* api.asyncRecognize(config, audio, function(err, response) {
* if (err) {
* console.error(err);
* return;
* }
* // doThingsWith(response)
* });
*/
SpeechApi.prototype.asyncRecognize = function asyncRecognize() {
var args = arguejs({
config: Object,
audio: Object,
options: [gax.CallOptions],
callback: [Function]
}, arguments);
var req = {
config: args.config,
audio: args.audio
};
return this._asyncRecognize(req, args.options, args.callback);
};

function SpeechApiBuilder(gaxGrpc) {
if (!(this instanceof SpeechApiBuilder)) {
return new SpeechApiBuilder(gaxGrpc);
}

var speechClient = gaxGrpc.load([{
root: require('google-proto-files')('..'),
file: 'google/cloud/speech/v1beta1/cloud_speech.proto'
}]);
extend(this, speechClient.google.cloud.speech.v1beta1);

var grpcClients = {
speechClient: speechClient
};

/**
* Build a new instance of {@link SpeechApi}.
*
* @param {Object=} opts - The optional parameters.
* @param {String=} opts.servicePath
* The domain name of the API remote host.
* @param {number=} opts.port
* The port on which to connect to the remote host.
* @param {grpc.ClientCredentials=} opts.sslCreds
* A ClientCredentials for use with an SSL-enabled channel.
* @param {Object=} opts.clientConfig
* The customized config to build the call settings. See
* {@link gax.constructSettings} for the format.
* @param {number=} opts.timeout
* The default timeout, in seconds, for calls made through this client.
* @param {number=} opts.appName
* The codename of the calling service.
* @param {String=} opts.appVersion
* The version of the calling service.
*/
this.speechApi = function(opts) {
return new SpeechApi(gaxGrpc, grpcClients, opts);
};
extend(this.speechApi, SpeechApi);
}
module.exports = SpeechApiBuilder;
module.exports.SERVICE_ADDRESS = SERVICE_ADDRESS;
module.exports.ALL_SCOPES = ALL_SCOPES;
43 changes: 43 additions & 0 deletions packages/speech/src/v1beta1/speech_client_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"interfaces": {
"google.cloud.speech.v1beta1.Speech": {
"retry_codes": {
"retry_codes_def": {
"idempotent": [
"DEADLINE_EXCEEDED",
"UNAVAILABLE"
],
"non_idempotent": []
}
},
"retry_params": {
"default": {
"initial_retry_delay_millis": 100,
"retry_delay_multiplier": 1.3,
"max_retry_delay_millis": 60000,
"initial_rpc_timeout_millis": 60000,
"rpc_timeout_multiplier": 1.0,
"max_rpc_timeout_millis": 60000,
"total_timeout_millis": 600000
}
},
"methods": {
"SyncRecognize": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "default"
},
"AsyncRecognize": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "default"
},
"StreamingRecognize": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default"
}
}
}
}
}
4 changes: 4 additions & 0 deletions packages/speech/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ describe('Speech', function() {
Speech.detectEncoding_('blah.mp3');
}, /Encoding could not be determined for file: blah\.mp3/);
});

it('should return nothing if the argument is not a string', function() {
assert.equal(Speech.detectEncoding_({}), undefined);

This comment was marked as spam.

This comment was marked as spam.

});
});

describe('findFile_', function() {
Expand Down