Skip to content

Commit 9521b85

Browse files
committed
speech/recognize.js: upgrade googleapis
1 parent 01108b0 commit 9521b85

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

speech/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"async": "^1.5.2",
1313
"google-auto-auth": "^0.2.4",
1414
"google-proto-files": "^0.3.0",
15-
"googleapis": "^7.1.0",
15+
"googleapis": "^12.0.0",
1616
"grpc": "^0.15.0"
1717
}
1818
}

speech/recognize.js

+11-27
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
var google = require('googleapis');
1919
var async = require('async');
2020
var fs = require('fs');
21+
22+
// Get a reference to the speech service
23+
var speech = google.speech('v1beta1').speech;
2124
// [END import_libraries]
2225

2326
// [START authenticating]
24-
function getSpeechService (host, callback) {
27+
function getAuthClient (callback) {
2528
// Acquire credentials
2629
google.auth.getApplicationDefault(function (err, authClient) {
2730
if (err) {
@@ -42,25 +45,7 @@ function getSpeechService (host, callback) {
4245
]);
4346
}
4447

45-
// Load the speach service using acquired credentials
46-
console.log('Loading speech service...');
47-
48-
// Url to discovery doc file
49-
// [START discovery_doc]
50-
host = host || 'speech.googleapis.com';
51-
var url = 'https://' + host + '/$discovery/rest';
52-
// [END discovery_doc]
53-
54-
google.discoverAPI({
55-
url: url,
56-
version: 'v1beta1',
57-
auth: authClient
58-
}, function (err, speechService) {
59-
if (err) {
60-
return callback(err);
61-
}
62-
callback(null, speechService, authClient);
63-
});
48+
return callback(null, authClient);
6449
});
6550
}
6651
// [END authenticating]
@@ -87,7 +72,7 @@ function prepareRequest (inputFile, callback) {
8772
}
8873
// [END construct_request]
8974

90-
function main (inputFile, host, callback) {
75+
function main (inputFile, callback) {
9176
var requestPayload;
9277

9378
async.waterfall([
@@ -96,12 +81,12 @@ function main (inputFile, host, callback) {
9681
},
9782
function (payload, cb) {
9883
requestPayload = payload;
99-
getSpeechService(host, cb);
84+
getAuthClient(cb);
10085
},
10186
// [START send_request]
102-
function sendRequest (speechService, authClient, cb) {
87+
function sendRequest (authClient, cb) {
10388
console.log('Analyzing speech...');
104-
speechService.speech.syncrecognize({
89+
speech.syncrecognize({
10590
auth: authClient,
10691
resource: requestPayload
10792
}, function (err, result) {
@@ -119,12 +104,11 @@ function main (inputFile, host, callback) {
119104
// [START run_application]
120105
if (module === require.main) {
121106
if (process.argv.length < 3) {
122-
console.log('Usage: node recognize <inputFile> [speech_api_host]');
107+
console.log('Usage: node recognize <inputFile>');
123108
process.exit();
124109
}
125110
var inputFile = process.argv[2];
126-
var host = process.argv[3];
127-
main(inputFile, host || 'speech.googleapis.com', console.log);
111+
main(inputFile, console.log);
128112
}
129113
// [END run_application]
130114
// [END app]

0 commit comments

Comments
 (0)