qfuxa commited on
Commit
2ebc949
·
2 Parent(s): 022a086 bd1016f

Merge pull request #45 from QuentinFuxa/solving-ffmpeg-process-freezing-unexpectedly

Browse files
src/whisper_streaming/online_asr.py CHANGED
@@ -85,6 +85,7 @@ class HypothesisBuffer:
85
  self.committed_in_buffer.pop(0)
86
 
87
 
 
88
  class OnlineASRProcessor:
89
  """
90
  Processes incoming audio in a streaming fashion, calling the ASR system
@@ -163,6 +164,13 @@ class OnlineASRProcessor:
163
  context_text = self.asr.sep.join(token.text for token in non_prompt_tokens)
164
  return self.asr.sep.join(prompt_list[::-1]), context_text
165
 
 
 
 
 
 
 
 
166
  def process_iter(self) -> Transcript:
167
  """
168
  Processes the current audio buffer.
@@ -413,4 +421,10 @@ class VACOnlineASRProcessor:
413
  result = self.online.finish()
414
  self.current_online_chunk_buffer_size = 0
415
  self.is_currently_final = False
416
- return result
 
 
 
 
 
 
 
85
  self.committed_in_buffer.pop(0)
86
 
87
 
88
+
89
  class OnlineASRProcessor:
90
  """
91
  Processes incoming audio in a streaming fashion, calling the ASR system
 
164
  context_text = self.asr.sep.join(token.text for token in non_prompt_tokens)
165
  return self.asr.sep.join(prompt_list[::-1]), context_text
166
 
167
+ def get_buffer(self):
168
+ """
169
+ Get the unvalidated buffer in string format.
170
+ """
171
+ return self.concatenate_tokens(self.transcript_buffer.buffer).text
172
+
173
+
174
  def process_iter(self) -> Transcript:
175
  """
176
  Processes the current audio buffer.
 
421
  result = self.online.finish()
422
  self.current_online_chunk_buffer_size = 0
423
  self.is_currently_final = False
424
+ return result
425
+
426
+ def get_buffer(self):
427
+ """
428
+ Get the unvalidated buffer in string format.
429
+ """
430
+ return self.online.concatenate_tokens(self.online.transcript_buffer.buffer).text
whisper_fastapi_online_server.py CHANGED
@@ -158,12 +158,8 @@ async def websocket_endpoint(websocket: WebSocket):
158
  })
159
 
160
  full_transcription += transcription.text
161
- if args.vac:
162
- transcript = online.online.concatenate_tokens(online.online.transcript_buffer.buffer)
163
- else:
164
- transcript = online.concatenate_tokens(online.transcript_buffer.buffer)
165
-
166
- buffer = transcript.text
167
  if buffer in full_transcription: # With VAC, the buffer is not updated until the next chunk is processed
168
  buffer = ""
169
 
 
158
  })
159
 
160
  full_transcription += transcription.text
161
+ buffer = online.get_buffer()
162
+
 
 
 
 
163
  if buffer in full_transcription: # With VAC, the buffer is not updated until the next chunk is processed
164
  buffer = ""
165