@@ -85,44 +85,52 @@ app.use(
8585var sttAuthService = new watson . AuthorizationV1 (
8686 Object . assign (
8787 {
88- url : watson . SpeechToTextV1 . URL ,
8988 username : process . env . SPEECH_TO_TEXT_USERNAME , // or hard-code credentials here
9089 password : process . env . SPEECH_TO_TEXT_PASSWORD
9190 } ,
9291 vcapServices . getCredentials ( 'speech_to_text' ) // pulls credentials from environment in bluemix, otherwise returns {}
9392 )
9493) ;
9594app . use ( '/api/speech-to-text/token' , function ( req , res ) {
96- sttAuthService . getToken ( { } , function ( err , token ) {
97- if ( err ) {
98- console . log ( 'Error retrieving token: ' , err ) ;
99- res . status ( 500 ) . send ( 'Error retrieving token' ) ;
100- return ;
95+ sttAuthService . getToken (
96+ {
97+ url : watson . SpeechToTextV1 . URL
98+ } ,
99+ function ( err , token ) {
100+ if ( err ) {
101+ console . log ( 'Error retrieving token: ' , err ) ;
102+ res . status ( 500 ) . send ( 'Error retrieving token' ) ;
103+ return ;
104+ }
105+ res . send ( token ) ;
101106 }
102- res . send ( token ) ;
103- } ) ;
107+ ) ;
104108} ) ;
105109
106110// text to speech token endpoint
107111var ttsAuthService = new watson . AuthorizationV1 (
108112 Object . assign (
109113 {
110- url : watson . TextToSpeechV1 . URL ,
111114 username : process . env . TEXT_TO_SPEECH_USERNAME , // or hard-code credentials here
112115 password : process . env . TEXT_TO_SPEECH_PASSWORD
113116 } ,
114117 vcapServices . getCredentials ( 'text_to_speech' ) // pulls credentials from environment in bluemix, otherwise returns {}
115118 )
116119) ;
117120app . use ( '/api/text-to-speech/token' , function ( req , res ) {
118- ttsAuthService . getToken ( { } , function ( err , token ) {
119- if ( err ) {
120- console . log ( 'Error retrieving token: ' , err ) ;
121- res . status ( 500 ) . send ( 'Error retrieving token' ) ;
122- return ;
121+ ttsAuthService . getToken (
122+ {
123+ url : watson . TextToSpeechV1 . URL
124+ } ,
125+ function ( err , token ) {
126+ if ( err ) {
127+ console . log ( 'Error retrieving token: ' , err ) ;
128+ res . status ( 500 ) . send ( 'Error retrieving token' ) ;
129+ return ;
130+ }
131+ res . send ( token ) ;
123132 }
124- res . send ( token ) ;
125- } ) ;
133+ ) ;
126134} ) ;
127135
128136const port = process . env . PORT || process . env . VCAP_APP_PORT || 3000 ;
0 commit comments