Tijs Zwinkels 2024-02-09
Interpolate word timestamps based on word character length
@46598adf1cac165204e66fec7869b18e3c70a22b
whisper_online.py
--- whisper_online.py
+++ whisper_online.py
@@ -190,12 +190,14 @@
 
             # Assign start and end times for each word
             # We only have timestamps per segment, so interpolating start and end-times
-            # assuming equal duration per word
+
+            
             segment_duration = segment["end"] - segment["start"]
-            duration_per_word = segment_duration / len(words)
+            total_characters = sum(len(word) for word in words)
+            duration_per_character = segment_duration / total_characters
             start_time = segment["start"]
             for word in words:
-                end_time = start_time + duration_per_word
+                end_time = start_time + duration_per_character * len(word)
                 o.append((start_time, end_time, word))
                 start_time = end_time
 
Add a comment
List