Dominik Macháček commited on
Commit
c812334
·
1 Parent(s): 6b968c6

increasing timestamps fixed

Browse files

but the code needs to be simplified and cleaned before merging

Files changed (2) hide show
  1. whisper_online.py +8 -4
  2. whisper_online_vac.py +1 -1
whisper_online.py CHANGED
@@ -235,16 +235,19 @@ class OnlineASRProcessor:
235
 
236
  self.buffer_trimming_way, self.buffer_trimming_sec = buffer_trimming
237
 
238
- def init(self):
239
  """run this when starting or restarting processing"""
240
  self.audio_buffer = np.array([],dtype=np.float32)
241
- self.buffer_time_offset = 0
242
-
243
  self.transcript_buffer = HypothesisBuffer(logfile=self.logfile)
 
 
 
 
 
 
244
  self.commited = []
245
  self.last_chunked_at = 0
246
 
247
- self.silence_iters = 0
248
 
249
  def insert_audio_chunk(self, audio):
250
  self.audio_buffer = np.append(self.audio_buffer, audio)
@@ -400,6 +403,7 @@ class OnlineASRProcessor:
400
  o = self.transcript_buffer.complete()
401
  f = self.to_flush(o)
402
  print("last, noncommited:",f,file=self.logfile)
 
403
  return f
404
 
405
 
 
235
 
236
  self.buffer_trimming_way, self.buffer_trimming_sec = buffer_trimming
237
 
238
+ def init(self, keep_offset=False):
239
  """run this when starting or restarting processing"""
240
  self.audio_buffer = np.array([],dtype=np.float32)
 
 
241
  self.transcript_buffer = HypothesisBuffer(logfile=self.logfile)
242
+ if not keep_offset:
243
+ self.buffer_time_offset = 0
244
+ self.transcript_buffer.last_commited_time = 0
245
+ else:
246
+ self.transcript_buffer.last_commited_time = self.buffer_time_offset
247
+
248
  self.commited = []
249
  self.last_chunked_at = 0
250
 
 
251
 
252
  def insert_audio_chunk(self, audio):
253
  self.audio_buffer = np.append(self.audio_buffer, audio)
 
403
  o = self.transcript_buffer.complete()
404
  f = self.to_flush(o)
405
  print("last, noncommited:",f,file=self.logfile)
406
+ self.buffer_time_offset += len(self.audio_buffer)/16000
407
  return f
408
 
409
 
whisper_online_vac.py CHANGED
@@ -45,7 +45,7 @@ class VACOnlineASRProcessor(OnlineASRProcessor):
45
 
46
  def finish(self):
47
  ret = self.online.finish()
48
- self.online.init()
49
  self.current_online_chunk_buffer_size = 0
50
  return ret
51
 
 
45
 
46
  def finish(self):
47
  ret = self.online.finish()
48
+ self.online.init(keep_offset=True)
49
  self.current_online_chunk_buffer_size = 0
50
  return ret
51