@@ -126,8 +126,8 @@ def start(self, model_path: str):
126
126
self .is_running = True
127
127
try :
128
128
with sounddevice .InputStream (samplerate = self .sample_rate ,
129
- device = self .input_device_index , dtype = "float32" ,
130
- channels = 1 , callback = self .stream_callback ):
129
+ device = self .input_device_index , dtype = "float32" ,
130
+ channels = 1 , callback = self .stream_callback ):
131
131
while self .is_running :
132
132
self .mutex .acquire ()
133
133
if self .queue .size >= self .n_batch_samples :
@@ -136,7 +136,7 @@ def start(self, model_path: str):
136
136
self .mutex .release ()
137
137
138
138
logging .debug ('Processing next frame, sample size = %s, queue size = %s, amplitude = %s' ,
139
- samples .size , self .queue .size , self .amplitude (samples ))
139
+ samples .size , self .queue .size , self .amplitude (samples ))
140
140
time_started = datetime .datetime .now ()
141
141
142
142
if self .transcription_options .model .model_type == ModelType .WHISPER :
@@ -157,17 +157,17 @@ def start(self, model_path: str):
157
157
else :
158
158
assert isinstance (model , TransformersWhisper )
159
159
result = model .transcribe (audio = samples ,
160
- language = self .transcription_options .language
161
- if self .transcription_options .language is not None else 'en' ,
162
- task = self .transcription_options .task .value )
160
+ language = self .transcription_options .language
161
+ if self .transcription_options .language is not None else 'en' ,
162
+ task = self .transcription_options .task .value )
163
163
164
164
next_text : str = result .get ('text' )
165
165
166
166
# Update initial prompt between successive recording chunks
167
167
initial_prompt += next_text
168
168
169
169
logging .debug ('Received next result, length = %s, time taken = %s' ,
170
- len (next_text ), datetime .datetime .now () - time_started )
170
+ len (next_text ), datetime .datetime .now () - time_started )
171
171
self .transcription .emit (next_text )
172
172
else :
173
173
self .mutex .release ()
@@ -367,19 +367,16 @@ def run(self):
367
367
368
368
self .current_process .join ()
369
369
370
- logging .debug (
371
- 'whisper process completed with code = %s, time taken = %s' ,
372
- self .current_process .exitcode , datetime .datetime .now () - time_started )
373
-
374
370
if self .current_process .exitcode != 0 :
375
371
send_pipe .close ()
376
372
377
373
self .read_line_thread .join ()
378
374
379
- # TODO: fix error handling when process crashes
380
- if self . current_process . exitcode != 0 and self . current_process . exitcode is not None :
381
- self .completed . emit ([] )
375
+ logging . debug (
376
+ 'whisper process completed with code = %s, time taken = %s, number of segments = %s' ,
377
+ self .current_process . exitcode , datetime . datetime . now () - time_started , len ( self . segments ) )
382
378
379
+ self .completed .emit (self .segments )
383
380
self .running = False
384
381
385
382
def stop (self ):
@@ -403,9 +400,7 @@ def read_line(self, pipe: Connection):
403
400
end = segment .get ('end' ),
404
401
text = segment .get ('text' ),
405
402
) for segment in segments_dict ]
406
- self .current_process .join ()
407
- # TODO: move this back to the parent thread
408
- self .completed .emit (segments )
403
+ self .segments = segments
409
404
else :
410
405
try :
411
406
progress = int (line .split ('|' )[0 ].strip ().strip ('%' ))
0 commit comments