-
Notifications
You must be signed in to change notification settings - Fork 674
Introduce auto-generated Gapic client for speech API #1614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
32f660e
Introduce auto-generated Gapic client for speech API
jmuk 5d196e1
Fix a typo
jmuk 191474d
Coverage ignorance for a line.
jmuk d602ee1
Add test case for detectEncoding_ for better coverage.
jmuk 34f69ff
Fix assertion line to make sure returning undefined exactly.
jmuk b9507ef
Merge branch 'master' into speech
jmuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.