Skip to content

Commit 223a450

Browse files
committed
improved STT module
1 parent 6e6139a commit 223a450

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/modules/stt-socket-worker.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ function init(){
102102

103103
//Requests
104104

105-
function gateControl(open, gateOptions){
105+
function gateControl(open, gateOptions, triggeredOnError){
106+
//console.error("gateControl - open:", open); //DEBUG
106107
if (!gateOptions) gateOptions = {}; //TODO: use e.g. for ?
107108
var msg = {
108109
moduleEvent: true, //use 'moduleEvent' to distinguish from normal processing result
@@ -152,7 +153,7 @@ function gateControl(open, gateOptions){
152153
}
153154

154155
//send WAV?
155-
if (returnAudioFile && recordedBuffers.length){
156+
if (!triggeredOnError && returnAudioFile && recordedBuffers.length){
156157
setTimeout(function(){
157158
sendWaveFileArrayBuffer(getWave());
158159
}, 100);
@@ -246,6 +247,7 @@ function constructWorker(options){
246247
onReady: function(activeOptions){
247248
if (doDebug) console.error("SttSocketWorker - DEBUG - CONNECTION READY", activeOptions);
248249
sendConnectionEvent("ready");
250+
//make sure stream starts or continues
249251
startOrContinueStream();
250252
},
251253
onClose: function(){
@@ -279,6 +281,10 @@ function constructWorker(options){
279281
}else{
280282
sendDefaultErrorEvent(err);
281283
}
284+
//make sure stream stops
285+
if (gateIsOpen){
286+
gateControl(false, {}, true);
287+
}
282288
}
283289
};
284290
sttServer = new SepiaSttSocketClient(socketUrl, clientId, accessToken, engineOptions, serverOptions);
@@ -437,7 +443,9 @@ function maxLengthReached(){
437443
recordedBuffers.splice(0, shift);
438444
}else{
439445
//close
440-
gateControl(false);
446+
if (gateIsOpen){
447+
gateControl(false);
448+
}
441449
}
442450
//TODO: do more ... ?
443451
}

src/sepia-recorder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
SepiaVoiceRecorder.onSpeechRecognitionEvent(msg.recognitionEvent);
9797
}
9898
if (msg.connectionEvent){
99-
//TODO: use? - type: open, ready, close
99+
//TODO: use? - type: open, ready, closed
100100
}
101101
//In debug or test-mode the module might send the recording:
102102
if (msg.output && msg.output.wav){

0 commit comments

Comments
 (0)