send only segments to client
This commit is contained in:
+10
-21
@@ -143,44 +143,35 @@ class ServeClient:
|
|||||||
result = self.transcriber.transcribe(input_sample, initial_prompt=initial_prompt)
|
result = self.transcriber.transcribe(input_sample, initial_prompt=initial_prompt)
|
||||||
if len(result):
|
if len(result):
|
||||||
self.t_start = None
|
self.t_start = None
|
||||||
output, last_segment = self.update_segments(result, duration)
|
last_segment = self.update_segments(result, duration)
|
||||||
if len(self.transcript) < self.send_last_n_segments:
|
if len(self.transcript) < self.send_last_n_segments:
|
||||||
segments = self.transcript
|
segments = self.transcript
|
||||||
else:
|
else:
|
||||||
segments = self.transcript[-self.send_last_n_segments:]
|
segments = self.transcript[-self.send_last_n_segments:]
|
||||||
if last_segment is not None:
|
if last_segment is not None:
|
||||||
segments = segments + [last_segment]
|
segments = segments + [last_segment]
|
||||||
out_dict = {
|
|
||||||
'text': output,
|
|
||||||
'segments': segments
|
|
||||||
}
|
|
||||||
try:
|
try:
|
||||||
self.websocket.send(json.dumps(out_dict))
|
self.websocket.send(json.dumps(segments))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.info(f"[ERROR]: {e}")
|
logging.info(f"[ERROR]: {e}")
|
||||||
else:
|
else:
|
||||||
# show previous output if there is pause i.e. no output from whisper
|
# show previous output if there is pause i.e. no output from whisper
|
||||||
output = ''
|
segments = []
|
||||||
if self.t_start is None: self.t_start = time.time()
|
if self.t_start is None: self.t_start = time.time()
|
||||||
if time.time() - self.t_start < self.show_prev_out_thresh:
|
if time.time() - self.t_start < self.show_prev_out_thresh:
|
||||||
output = self.fill_output('')
|
if len(self.transcript) < self.send_last_n_segments:
|
||||||
|
segments = self.transcript
|
||||||
|
else:
|
||||||
|
segments = self.transcript[-self.send_last_n_segments:]
|
||||||
|
|
||||||
# add a blank if there is no speech for 3 seconds
|
# add a blank if there is no speech for 3 seconds
|
||||||
if len(self.text) and self.text[-1] != '':
|
if len(self.text) and self.text[-1] != '':
|
||||||
if time.time() - self.t_start > self.add_pause_thresh:
|
if time.time() - self.t_start > self.add_pause_thresh:
|
||||||
self.text.append('')
|
self.text.append('')
|
||||||
if len(self.transcript) < self.send_last_n_segments:
|
|
||||||
segments = self.transcript
|
|
||||||
else:
|
|
||||||
segments = self.transcript[-self.send_last_n_segments:]
|
|
||||||
# publish outputs
|
|
||||||
out_dict = {
|
|
||||||
'text': output,
|
|
||||||
'segments': segments
|
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.websocket.send(json.dumps(out_dict))
|
self.websocket.send(json.dumps(segments))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.info(f"[INFO]: {e}")
|
logging.info(f"[INFO]: {e}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -253,9 +244,7 @@ class ServeClient:
|
|||||||
if offset is not None:
|
if offset is not None:
|
||||||
self.timestamp_offset += offset
|
self.timestamp_offset += offset
|
||||||
|
|
||||||
# format and return output
|
return last_segment
|
||||||
output = self.current_out
|
|
||||||
return self.fill_output(output), last_segment
|
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
logging.info("Cleaning up.")
|
logging.info("Cleaning up.")
|
||||||
|
|||||||
Reference in New Issue
Block a user