Skip to content

Commit 4bbc0db

Browse files
committed
Process stop slower than anything else
1 parent b8158aa commit 4bbc0db

File tree

1 file changed

+23
-15
lines changed
  • services/speech_to_text

1 file changed

+23
-15
lines changed

services/speech_to_text/v1.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -435,25 +435,31 @@ module.exports = function (RED) {
435435
return Promise.resolve();
436436
}
437437

438+
function sendTheStack() {
439+
if (audioStack && audioStack.length) {
440+
audioStack.forEach((a) => {
441+
if (a && a.action && 'data' === a.action) {
442+
console.log('sending data from stack');
443+
console.log(a.action);
444+
websocket.send(a.data);
445+
}
446+
});
447+
audioStack = [];
448+
}
449+
}
438450

439451
function sendAudioSTTSocket(audioData) {
440452
var p = new Promise(function resolver(resolve, reject) {
441-
console.log('Sending Audio - outer ');
442-
console.log(audioData);
453+
//console.log('Sending Audio - outer ');
454+
//console.log(audioData);
455+
// send stack First
456+
sendTheStack();
443457
if (audioData && audioData.action) {
458+
console.log('action type is ', audioData.action);
444459
if ('data' === audioData.action) {
445-
console.log('Sending Audio - inner');
446-
447-
// send stack First
448-
if (audioStack && audioStack.length) {
449-
audioStack.forEach((a) => {
450-
if (a && a.action && 'data' === a.action) {
451-
websocket.send(a.data);
452-
}
453-
});
454-
audioStack = [];
455-
}
460+
//console.log('Sending Audio - inner');
456461
//console.log(audioData.data);
462+
console.log('sending data from input');
457463
websocket.send(audioData.data, (error) => {
458464
if (error) {
459465
console.log(error);
@@ -467,7 +473,7 @@ module.exports = function (RED) {
467473
if (audioData.action === 'stop') {
468474
console.log('Signalling Stop');
469475
websocket.send(JSON.stringify(audioData));
470-
//socketListening = false;
476+
socketListening = false;
471477

472478
// Closing as refresh doesn't appear to work
473479
//websocket.close();
@@ -482,13 +488,15 @@ module.exports = function (RED) {
482488

483489
function performStreamSTT(audioData) {
484490
var speech_to_text = determineService();
491+
var delay = 1000;
485492
var p = getToken(speech_to_text)
486493
.then(() => {
487494
switch (audioData.action) {
488495
case 'start':
489496
//return Promise.reject('Its a start');
490497
return processSTTSocketStart();
491498
case 'stop':
499+
delay = 2000;
492500
case 'data':
493501
// Add a Delay to allow the listening thread to kick in
494502
setTimeout(() => {
@@ -497,7 +505,7 @@ module.exports = function (RED) {
497505
} else {
498506
return stackAudioFile(audioData);
499507
}
500-
}, 1000);
508+
}, delay);
501509
//return Promise.reject('Its a data or stop');
502510
default:
503511
return Promise.resolve();

0 commit comments

Comments
 (0)