From 531418ad07431fec99ec88b3efb73a7d476bfe9e Mon Sep 17 00:00:00 2001 From: Tijs Zwinkels Date: Thu, 8 Feb 2024 23:33:52 +0100 Subject: [PATCH] Interpolate word timestamps based on word character length --- whisper_online.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/whisper_online.py b/whisper_online.py index d60cc84..477297a 100644 --- a/whisper_online.py +++ b/whisper_online.py @@ -190,12 +190,14 @@ class OpenaiApiASR(ASRBase): # 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