Skip to content

Commit 9dc9c50

Browse files
committed
Merge pull request #119 from chughts/master
STT Crash Fix
2 parents 9d4d447 + 430e222 commit 9dc9c50

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

  • services/speech_to_text

services/speech_to_text/v1.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,18 @@ module.exports = function (RED) {
9999

100100
wstream.on('finish', function () {
101101
fs.readFile(file, function (err, buf) {
102+
var fmt = null;
103+
var error = null;
104+
102105
if (err) {
103-
throw err;
106+
error = err;
107+
}
108+
if (fileType(buf)) {
109+
fmt = fileType(buf).ext;
110+
} else {
111+
error = 'Unrecognised file format';
104112
}
105-
cb(fileType(buf).ext);
113+
cb(error, fmt);
106114
});
107115
});
108116

@@ -272,7 +280,7 @@ module.exports = function (RED) {
272280
if (msg.payload instanceof Buffer) {
273281
temp.open({suffix: '.' + fileType(msg.payload).ext}, function (err, info) {
274282
if (err) {
275-
this.status({fill:'red', shape:'ring', text:'unable to open audio stream'});
283+
node.status({fill:'red', shape:'ring', text:'unable to open audio stream'});
276284
message = 'Node has been unable to open the audio stream';
277285

278286
node.error(message, msg);
@@ -288,22 +296,30 @@ module.exports = function (RED) {
288296
} else if (urlCheck(msg.payload)) {
289297
temp.open({suffix: '.audio'}, function(err, info){
290298
if (err) {
291-
this.status({fill:'red', shape:'ring',
299+
node.status({fill:'red', shape:'ring',
292300
text:'unable to open url audio stream'});
293301
message = 'Node has been unable to open the url audio stream';
294302

295303
node.error(message, msg);
296304
return;
297305
}
298306

299-
stream_url(info.path, msg.payload, function (format) {
307+
stream_url(info.path, msg.payload, function (err, format) {
308+
if (err) {
309+
node.status({fill:'red', shape:'ring',
310+
text:'url stream not recognised as audio'});
311+
message = 'Node did not recognise the url audio stream as audio';
312+
313+
node.error(message, msg);
314+
return;
315+
}
300316
var audio = fs.createReadStream(info.path);
301317

302318
performAction(audio, format, actionComplete, temp.cleanup);
303319
});
304320
});
305321
} else {
306-
this.status({fill:'red', shape:'ring', text:'payload is invalid'});
322+
node.status({fill:'red', shape:'ring', text:'payload is invalid'});
307323
message = 'Payload must be either an audio buffer or a string representing a url';
308324
node.error(message, msg);
309325
return;

0 commit comments

Comments
 (0)