-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fixing words that have missing timestamps #349
Comments
I have encountered same issue and the solution can be as simple as this if you just want to post-process the broken json file. Simply feed in the output json and it will fill in the gap by being start where previous ended and end where next starts, assuming same speaker (if exists in json) and giving whatever score such as 0.5.
Might have edge cases and need adjustments to your use case but if parsing json later depends on having start and end times it will at least not crash :) |
Updated code to account for consecutive cases of missing 'start' and 'end' def estimate_time(words_from_segments):
for i, word in enumerate(words_from_segments):
try:
if "start" not in word or "end" not in word: # enter loop if current word is missing "start" or "end"
pointer = 1 # let the pointer to the next word start at 1
prev_word_end = words_from_segments[i - 1]["end"] # grab the end from the last one (should always work)
try:
next_word_start = words_from_segments[i + pointer]["start"] # try to grab the start from the next one
except KeyError: # if trying to grab results in the error
pointer += 1 # we'll increment pointer to next
next_word_start = "" # and add placeholder string
while (next_word_start == ""): # while next_word_start is a place holder
try:
next_word_start = words_from_segments[i + pointer]["start"] # grab the start time from the next word
#if successful: find difference, and then divide to find increment. Add increment to prev_word_end and assign.
next_word_start = ((next_word_start - prev_word_end) / pointer) + prev_word_end
except KeyError:
pointer += 1 # if another error, increment the pointer
word["start"] = prev_word_end #set prevEnd to currStr
word["end"] = next_word_start #set prevStr to currEnd
word["score"] = 0.5
word["speaker"] = words_from_segments[i - 1]["speaker"] if "speaker" in words_from_segments[i - 1] else None
except Exception as e: # Catch-all for any other exceptions
print(f"Unexpected error while estimating time for word: {word}. Error details: {e}")
return words_from_segments |
Should be fixed with #986 |
I noticed that sometimes the word within the "words" list don't have a start or end time if they are made of only numbers.
This function I have been using for fixing missing "start" or "end" timestamps in segments.
Hope this can help people who are having the same issue!
`
def fix_whisperX_timestamp(segments):
"""
Fixes missing "start" or "end" timestamps in the segments before assigning speakers.
`
The text was updated successfully, but these errors were encountered: