Tijs Zwinkels commited on
Commit
531418a
·
1 Parent(s): 2270014

Interpolate word timestamps based on word character length

Browse files
Files changed (1) hide show
  1. whisper_online.py +5 -3
whisper_online.py CHANGED
@@ -190,12 +190,14 @@ class OpenaiApiASR(ASRBase):
190
 
191
  # Assign start and end times for each word
192
  # We only have timestamps per segment, so interpolating start and end-times
193
- # assuming equal duration per word
 
194
  segment_duration = segment["end"] - segment["start"]
195
- duration_per_word = segment_duration / len(words)
 
196
  start_time = segment["start"]
197
  for word in words:
198
- end_time = start_time + duration_per_word
199
  o.append((start_time, end_time, word))
200
  start_time = end_time
201
 
 
190
 
191
  # Assign start and end times for each word
192
  # We only have timestamps per segment, so interpolating start and end-times
193
+
194
+
195
  segment_duration = segment["end"] - segment["start"]
196
+ total_characters = sum(len(word) for word in words)
197
+ duration_per_character = segment_duration / total_characters
198
  start_time = segment["start"]
199
  for word in words:
200
+ end_time = start_time + duration_per_character * len(word)
201
  o.append((start_time, end_time, word))
202
  start_time = end_time
203