@@ -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}
0 commit comments