makaveli10 commited on
Commit
81cb63c
1 Parent(s): 71a8e88

send LLM output only once after eos=true

Browse files
Files changed (1) hide show
  1. whisper_live/trt_server.py +23 -19
whisper_live/trt_server.py CHANGED
@@ -350,13 +350,16 @@ class ServeClient:
350
 
351
  """
352
  while True:
353
- try:
354
- if self.llm_queue is not None:
355
- llm_output = self.llm_queue.get_nowait()
356
- if llm_output:
357
- self.websocket.send(json.dumps(llm_output))
358
- except queue.Empty:
359
- pass
 
 
 
360
 
361
  if self.exit:
362
  logging.info("Exiting speech to text thread")
@@ -387,18 +390,21 @@ class ServeClient:
387
  if len(last_segment):
388
  segments.append({"text": last_segment})
389
  try:
390
- self.websocket.send(
391
- json.dumps({
392
- "uid": self.client_uid,
393
- "segments": segments,
394
- "eos": self.eos
395
- })
396
- )
397
- logging.info(f"[INFO]: {segments}, eos: {self.eos}")
 
 
 
398
  if self.eos:
399
  # self.append_segment(last_segment)
400
  self.timestamp_offset += duration
401
- self.prompt = ' '.join(segment['text'] for segment in segments)
402
  if self.last_prompt != self.prompt:
403
  self.transcription_queue.put({"uid": self.client_uid, "prompt": self.prompt})
404
 
@@ -406,9 +412,7 @@ class ServeClient:
406
  # self.set_eos(False)
407
  logging.info(f"[INFO:] Processed : {self.timestamp_offset} seconds / {self.frames_np.shape[0] / self.RATE} seconds"
408
  )
409
- else:
410
- self.prompt = ' '.join(segment['text'] for segment in segments)
411
-
412
  if self.last_prompt != self.prompt:
413
  self.transcription_queue.put({"uid": self.client_uid, "prompt": self.prompt})
414
 
 
350
 
351
  """
352
  while True:
353
+ if self.eos:
354
+ try:
355
+ llm_output = None
356
+ if self.llm_queue is not None:
357
+ while not self.llm_queue.empty():
358
+ llm_output = self.llm_queue.get_nowait()
359
+ if llm_output:
360
+ self.websocket.send(json.dumps(llm_output))
361
+ except queue.Empty:
362
+ pass
363
 
364
  if self.exit:
365
  logging.info("Exiting speech to text thread")
 
390
  if len(last_segment):
391
  segments.append({"text": last_segment})
392
  try:
393
+ self.prompt = ' '.join(segment['text'] for segment in segments)
394
+ if self.last_prompt != self.prompt:
395
+ self.websocket.send(
396
+ json.dumps({
397
+ "uid": self.client_uid,
398
+ "segments": segments,
399
+ "eos": self.eos
400
+ })
401
+ )
402
+ logging.info(f"[INFO]: {segments}, eos: {self.eos}")
403
+
404
  if self.eos:
405
  # self.append_segment(last_segment)
406
  self.timestamp_offset += duration
407
+
408
  if self.last_prompt != self.prompt:
409
  self.transcription_queue.put({"uid": self.client_uid, "prompt": self.prompt})
410
 
 
412
  # self.set_eos(False)
413
  logging.info(f"[INFO:] Processed : {self.timestamp_offset} seconds / {self.frames_np.shape[0] / self.RATE} seconds"
414
  )
415
+ else:
 
 
416
  if self.last_prompt != self.prompt:
417
  self.transcription_queue.put({"uid": self.client_uid, "prompt": self.prompt})
418