File tree 1 file changed +17
-1
lines changed
1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,15 @@ if (result.sampleRate < desired_sample_rate) {
89
89
`Up-sampling might produce erratic speech recognition.` ) ;
90
90
}
91
91
92
+ function handleExit ( ) {
93
+ if ( process . versions . electron ) {
94
+ const { app } = require ( "electron" ) ;
95
+ app . quit ( ) ;
96
+ } else {
97
+ process . exit ( 0 ) ;
98
+ }
99
+ }
100
+
92
101
function bufferToStream ( buffer : Buffer ) {
93
102
var stream = new Duplex ( ) ;
94
103
stream . push ( buffer ) ;
@@ -135,7 +144,14 @@ if (!args['stream']) {
135
144
const inference_stop = process . hrtime ( inference_start ) ;
136
145
console . error ( 'Inference took %ds for %ds audio file.' , totalTime ( inference_stop ) , audioLength . toPrecision ( 4 ) ) ;
137
146
Ds . FreeModel ( model ) ;
138
- process . exit ( 0 ) ;
147
+ // Allow some time for resources to exhaust and ensure we finish the
148
+ // process anyway
149
+ setTimeout ( ( ) => {
150
+ handleExit ( ) ;
151
+ } , 1 * 1000 ) ;
152
+ } ) ;
153
+ audioStream . on ( 'close' , ( ) => {
154
+ handleExit ( ) ;
139
155
} ) ;
140
156
} else {
141
157
let stream = model . createStream ( ) ;
You can’t perform that action at this time.
0 commit comments