Skip to content

Commit a77575a

Browse files
committed
mute some of the console.log logging
1 parent 7ed0726 commit a77575a

File tree

6 files changed

+63
-17
lines changed

6 files changed

+63
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Node-RED Watson Nodes for IBM Cloud
88
<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>
99

1010
### New in version 0.7.0
11-
- Assistant, Discovery, Speech to Text, Text to Speech, Tone Analyzer nodes updated
11+
- Assistant, Discovery, Natural Language Understanding, Speech to Text, Text to Speech, Tone Analyzer nodes updated
1212
to allow for use of iam key for authentication.
1313
- Migrated STT node off deprecated methods.
1414
- Fix to Tone Analyzer Node to preserve credentials on config reopen.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"temp": "^0.8.3",
1111
"qs": "6.x",
1212
"image-type": "^2.0.2",
13-
"watson-developer-cloud": "^3.4.4",
13+
"watson-developer-cloud": "^3.4.5",
1414
"kuromoji": "^0.1.1",
1515
"word-count": "^0.2.2",
1616
"is-docx": "^0.0.3",

services/discovery/v1-document-loader.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ module.exports = function (RED) {
127127
function execute(params, msg, suffix) {
128128
var p = new Promise(function resolver(resolve, reject) {
129129
let discovery = discoveryutils.buildService(username, password, apikey, endpoint);
130+
130131
// modify as getting addJsonDocument will be deprecated messages
131132
if ('.json' === suffix) {
132133
//method = 'addJsonDocument';

services/speech_to_text/stt-utils.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
**/
1616

17-
const pkg = require('../../package.json'),
17+
const pkg = require('../../package.json'),
1818
STTV1 = require('watson-developer-cloud/speech-to-text/v1');
1919

2020
class STTUtils {
@@ -62,6 +62,22 @@ class STTUtils {
6262
return new STTV1(serviceSettings);
6363
}
6464

65+
static determineServiceFromToken(accessToken, endpoint) {
66+
let serviceSettings = {
67+
headers: {
68+
'User-Agent': pkg.name + '-' + pkg.version
69+
}
70+
};
71+
72+
serviceSettings.iam_access_token = accessToken;
73+
74+
if (endpoint) {
75+
serviceSettings.url = endpoint;
76+
}
77+
78+
return new STTV1(serviceSettings);
79+
}
80+
6581
}
6682

6783
module.exports = STTUtils;

services/speech_to_text/v1-corpus-builder.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
module.exports = function (RED) {
1818
const SERVICE_IDENTIFIER = 'speech-to-text';
19-
var url = require('url'),
20-
temp = require('temp'),
19+
var temp = require('temp'),
2120
fs = require('fs'),
2221
fileType = require('file-type'),
2322
serviceutils = require('../../utilities/service-utils'),

services/speech_to_text/v1.js

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = function (RED) {
2525
payloadutils = require('../../utilities/payload-utils'),
2626
sttutils = require('./stt-utils'),
2727
AuthV1 = require('watson-developer-cloud/authorization/v1'),
28+
AuthIAMV1 = require('watson-developer-cloud/iam-token-manager/v1'),
2829
muteMode = true, discardMode = false, autoConnect = true,
2930
username = '', password = '', sUsername = '', sPassword = '',
3031
apikey = '', sApikey = '',
@@ -270,15 +271,30 @@ module.exports = function (RED) {
270271
}
271272

272273
function determineTokenService(stt) {
273-
let tokenService = new AuthV1(stt.getCredentials());
274+
let tokenService = null;
275+
276+
if (apikey) {
277+
// console.log('API Key stuff to go here');
278+
// tokenService = new AuthV1(stt.getCredentials());
279+
// console.log('the keys that we have are ', stt.getCredentials());
280+
// let creds = {}; // stt.getCredentials();
281+
// creds.iamApikey = apikey;
282+
// console.log('Creating token with endpoint ', endpoint);
283+
// tokenService = new AuthIAMV1.IamTokenManagerV1({iamApikey : apikey, iamUrl: endpoint});
284+
tokenService = new AuthIAMV1.IamTokenManagerV1({iamApikey : apikey});
285+
286+
} else {
287+
// console.log('Standard Key');
288+
tokenService = new AuthV1(stt.getCredentials());
289+
}
274290

275291
// Streaming - IAM Key fudge.
276292
// Check if the token service options have the header set. If not then
277293
// create them. This will stop the function from crashing the app,
278294
// altough it will still fail authentication.
279-
if (!tokenService._options.headers) {
280-
tokenService._options.headers = {};
281-
}
295+
//if (!tokenService._options.headers) {
296+
// tokenService._options.headers = {};
297+
//}
282298
return tokenService;
283299
}
284300

@@ -321,6 +337,7 @@ module.exports = function (RED) {
321337
function getToken(stt) {
322338
var p = new Promise(function resolver(resolve, reject) {
323339
var now = Math.floor(Date.now() / 1000);
340+
324341
var tokenService = determineTokenService(stt);
325342

326343
if (tokenPending) {
@@ -335,11 +352,13 @@ module.exports = function (RED) {
335352
tokenPending = true;
336353
tokenService.getToken(function (err, res) {
337354
if (err) {
355+
// console.log('Error getting token ', err);
338356
reject(err);
339357
} else {
340358
tokenPending = false;
341359
tokenTime = now;
342360
token = res;
361+
// console.log('We have the token ', token);
343362
resolve();
344363
}
345364
});
@@ -368,14 +387,19 @@ module.exports = function (RED) {
368387
+ '?watson-token=' + token + '&model=' + model;
369388
}
370389

390+
// console.log('wsURI is : ', wsURI);
391+
371392
if (!websocket && !socketCreationInProcess) {
372393
socketCreationInProcess = true;
394+
// console.log('Attempting creation of web socket');
373395
var ws = new WebSocket(wsURI);
396+
// console.log('Setting up listeners');
374397
ws.on('open', () => {
398+
// console.log('Socket is open');
375399
ws.send(JSON.stringify(startPacket));
376400
websocket = ws;
377401
socketCreationInProcess = false;
378-
//resolve();
402+
// resolve();
379403
});
380404

381405
ws.on('message', (data) => {
@@ -393,7 +417,7 @@ module.exports = function (RED) {
393417
if (!muteMode) {
394418
payloadutils.reportError(node,newMsg,d.error);
395419
}
396-
420+
// console.log('Fetching token');
397421
token = null;
398422
getToken(determineService())
399423
.then(() => {
@@ -428,11 +452,13 @@ module.exports = function (RED) {
428452
ws.on('error', (err) => {
429453
socketListening = false;
430454
if (!muteMode) {
455+
var newMsg = {payload : 'STT Connection Error'};
456+
console.log('Socket Error ', err);
431457
payloadutils.reportError(node,newMsg,err);
432458
}
433459
// console.log('Error Detected');
434460
if (initialConnect) {
435-
//reject(err);
461+
// reject(err);
436462
}
437463
});
438464

@@ -495,10 +521,13 @@ module.exports = function (RED) {
495521
sendTheStack();
496522
if (audioData && audioData.action) {
497523
if ('data' === audioData.action) {
524+
// console.log('Sending data');
498525
websocket.send(audioData.data, (error) => {
499526
if (error) {
527+
// console.log('Error Sending data ', error);
500528
reject(error);
501529
} else {
530+
// console.log('Data was sent');
502531
resolve();
503532
}
504533
});
@@ -517,7 +546,7 @@ module.exports = function (RED) {
517546
.then(() => {
518547
switch (audioData.action) {
519548
case 'start':
520-
//return Promise.reject('Its a start');
549+
// console.log('Its a start');
521550
return processSTTSocketStart(true);
522551
case 'stop':
523552
delay = 2000;
@@ -526,6 +555,7 @@ module.exports = function (RED) {
526555
// Add a Delay to allow the listening thread to kick in
527556
// Delays for Stop is longer, so that it doesn't get actioned
528557
// before the audio buffers.
558+
// console.log('We have data');
529559
setTimeout(() => {
530560
if (socketListening) {
531561
return sendAudioSTTSocket(audioData);
@@ -581,7 +611,7 @@ module.exports = function (RED) {
581611

582612
node.status({});
583613

584-
let service = null;
614+
let sttService = null;
585615

586616
// Now perform checks on the input and parameters, to make sure that all
587617
// is in place before the service is invoked.
@@ -599,15 +629,15 @@ module.exports = function (RED) {
599629
return getService();
600630
})
601631
.then((s) => {
602-
service = s;
632+
sttService = s;
603633
return processInput(msg);
604634
})
605635
.then((audioData) => {
606636
node.status({fill:'blue', shape:'dot', text:'requesting'});
607637
if (config['streaming-mode']) {
608-
return performStreamSTT(service, audioData);
638+
return performStreamSTT(sttService, audioData);
609639
} else {
610-
return performSTT(service, audioData);
640+
return performSTT(sttService, audioData);
611641
}
612642
})
613643
.then((data) => {

0 commit comments

Comments
 (0)