Skip to content

Commit 90a268a

Browse files
committed
fixed codeacy warnings
1 parent 81a7aea commit 90a268a

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

  • services/speech_to_text

services/speech_to_text/v1.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,17 @@ module.exports = function (RED) {
5959

6060
// API used by widget to fetch available models
6161
RED.httpAdmin.get('/watson-speech-to-text/models', function (req, res) {
62-
stt = watson.speech_to_text({
63-
username: username ? username : req.query.un,
64-
password: password ? password : req.query.pwd,
65-
version: 'v1',
66-
url: 'https://stream.watsonplatform.net/speech-to-text/api'
67-
});
62+
var stt = watson.speech_to_text({
63+
username: username ? username : req.query.un,
64+
password: password ? password : req.query.pwd,
65+
version: 'v1',
66+
url: 'https://stream.watsonplatform.net/speech-to-text/api'
67+
});
6868

6969
stt.getModels({}, function(err, models){
7070
if (err) {
7171
res.json(err);
72-
}
73-
else {
72+
} else {
7473
res.json(models);
7574
}
7675
});
@@ -79,8 +78,9 @@ module.exports = function (RED) {
7978
// Utility function to perform a URL validation check
8079
function urlCheck(str) {
8180
var parsed = url.parse(str)
81+
8282
return (!!parsed.hostname && !!parsed.protocol && str.indexOf(' ') < 0);
83-
};
83+
}
8484

8585
// Function that is syncing up the asynchronous nature of the stream
8686
// so that the full file can be sent to the API.
@@ -128,12 +128,11 @@ module.exports = function (RED) {
128128
node.error(err, msg);
129129
}
130130
else {
131-
msg.transcription = '';
131+
var r = data.results;
132132

133-
var r = data.results;
133+
msg.transcription = '';
134134
if (r) {
135135
if (r.length && r[0].alternatives.length) {
136-
var index = r[0].alternatives.length - 1;
137136
msg.fullresult = r;
138137
}
139138
msg.transcription = '';
@@ -186,7 +185,9 @@ module.exports = function (RED) {
186185
}
187186
});
188187

189-
if (cbcleanup) cbcleanup();
188+
if (cbcleanup) {
189+
cbcleanup();
190+
}
190191
}
191192

192193

@@ -256,7 +257,8 @@ module.exports = function (RED) {
256257
case 'ogg':
257258
break;
258259
default:
259-
var message_err_format = 'Audio format (' + f + ') not supported, must be encoded as WAV, FLAC or OGG.';
260+
var message_err_format
261+
= 'Audio format (' + f + ') not supported, must be encoded as WAV, FLAC or OGG.';
260262

261263
node.error(message_err_format, msg)
262264
return;
@@ -265,12 +267,12 @@ module.exports = function (RED) {
265267

266268
// We are now ready to process the input data
267269
// If its a buffer then need to read it all before invoking the service
268-
var params = {};
269270
if (msg.payload instanceof Buffer) {
270271
temp.open({suffix: '.' + fileType(msg.payload).ext}, function (err, info) {
271272
if (err) {
272273
this.status({fill:'red', shape:'ring', text:'unable to open audio stream'});
273274
var message ='Node has been unable to open the audio stream';
275+
274276
node.error(message, msg);
275277
return;
276278
}
@@ -284,8 +286,10 @@ module.exports = function (RED) {
284286
} else if (urlCheck(msg.payload)) {
285287
temp.open({suffix: '.audio'}, function(err, info){
286288
if (err) {
287-
this.status({fill:'red', shape:'ring', text:'unable to open url audio stream'});
289+
this.status({fill:'red', shape:'ring',
290+
text:'unable to open url audio stream'});
288291
var message ='Node has been unable to open the url audio stream';
292+
289293
node.error(message, msg);
290294
return;
291295
}
@@ -298,7 +302,7 @@ module.exports = function (RED) {
298302
});
299303
} else {
300304
this.status({fill:'red', shape:'ring', text:'payload is invalid'});
301-
var message ='Payload must be either an audio buffer or a string representing a url';
305+
var message = 'Payload must be either an audio buffer or a string representing a url';
302306
node.error(message, msg);
303307
return;
304308
}

0 commit comments

Comments
 (0)