Skip to content

Commit d2436ac

Browse files
committed
speech/recognize.js: upgrade googleapis
1 parent f3513db commit d2436ac

File tree

3 files changed

+12
-30
lines changed

3 files changed

+12
-30
lines changed

speech/package.json

Lines changed: 1 addition & 1 deletion
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

Lines changed: 11 additions & 27 deletions
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]

test/speech/recognize.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ describe('speech:recognize', function () {
2020
it('should recognize speech in audio', function (done) {
2121
recognizeExample.main(
2222
path.join(__dirname, '../../speech/resources/audio.raw'),
23-
process.env.SPEECH_API_HOST || 'speech.googleapis.com',
2423
function (err, result) {
2524
assert(!err);
2625
assert(result);
2726
assert(Array.isArray(result.results));
2827
assert(result.results.length === 1);
2928
assert(result.results[0].alternatives);
3029
assert(console.log.calledWith('Got audio file!'));
31-
assert(console.log.calledWith('Loading speech service...'));
3230
assert(console.log.calledWith('Analyzing speech...'));
3331
done();
3432
}

0 commit comments

Comments
 (0)