18
18
var google = require ( 'googleapis' ) ;
19
19
var async = require ( 'async' ) ;
20
20
var fs = require ( 'fs' ) ;
21
+
22
+ // Get a reference to the speech service
23
+ var speech = google . speech ( 'v1beta1' ) . speech ;
21
24
// [END import_libraries]
22
25
23
26
// [START authenticating]
24
- function getSpeechService ( host , callback ) {
27
+ function getAuthClient ( callback ) {
25
28
// Acquire credentials
26
29
google . auth . getApplicationDefault ( function ( err , authClient ) {
27
30
if ( err ) {
@@ -42,25 +45,7 @@ function getSpeechService (host, callback) {
42
45
] ) ;
43
46
}
44
47
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 ) ;
64
49
} ) ;
65
50
}
66
51
// [END authenticating]
@@ -87,7 +72,7 @@ function prepareRequest (inputFile, callback) {
87
72
}
88
73
// [END construct_request]
89
74
90
- function main ( inputFile , host , callback ) {
75
+ function main ( inputFile , callback ) {
91
76
var requestPayload ;
92
77
93
78
async . waterfall ( [
@@ -96,12 +81,12 @@ function main (inputFile, host, callback) {
96
81
} ,
97
82
function ( payload , cb ) {
98
83
requestPayload = payload ;
99
- getSpeechService ( host , cb ) ;
84
+ getAuthClient ( cb ) ;
100
85
} ,
101
86
// [START send_request]
102
- function sendRequest ( speechService , authClient , cb ) {
87
+ function sendRequest ( authClient , cb ) {
103
88
console . log ( 'Analyzing speech...' ) ;
104
- speechService . speech . syncrecognize ( {
89
+ speech . syncrecognize ( {
105
90
auth : authClient ,
106
91
resource : requestPayload
107
92
} , function ( err , result ) {
@@ -119,12 +104,11 @@ function main (inputFile, host, callback) {
119
104
// [START run_application]
120
105
if ( module === require . main ) {
121
106
if ( process . argv . length < 3 ) {
122
- console . log ( 'Usage: node recognize <inputFile> [speech_api_host] ' ) ;
107
+ console . log ( 'Usage: node recognize <inputFile>' ) ;
123
108
process . exit ( ) ;
124
109
}
125
110
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 ) ;
128
112
}
129
113
// [END run_application]
130
114
// [END app]
0 commit comments