Avoid adding empty words list to segments when word_timestamps is False#2780
Open
LeSingh1 wants to merge 1 commit into
Open
Avoid adding empty words list to segments when word_timestamps is False#2780LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
When word_timestamps is False, segments do not have a 'words' key. However, the cleanup loop for instantaneous/empty segments was unconditionally assigning segment['words'] = [], introducing the key only for empty segments. This produces an inconsistent schema where some segments have a 'words' key and others do not. The SubtitlesWriter (used by WriteVTT and WriteSRT) checks whether the first segment has a 'words' key to decide which iteration path to take. If the first segment happened to be empty/instantaneous, the spurious key triggered the word-based path, which then raised KeyError on subsequent non-empty segments that lacked the key. Only reset 'words' when it already exists so the schema stays consistent with how add_word_timestamps populates it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When word_timestamps is False, segments do not have a
wordskey. The cleanup pass for instantaneous or empty segments was unconditionally assigningsegment['words'] = [], introducing the key only on those empty segments. This makes the segment schema inconsistent: some segments get awordskey, others do not.SubtitlesWriter(used by both WriteVTT and WriteSRT) decides which iteration path to take by checking'words' in result['segments'][0]. If the first segment happens to be empty or instantaneous, that spurious key flips the writer into the word-level path, which then raisesKeyError: 'words'on the next non-empty segment that lacks the key.Minimal reproducer:
Fix: only reset
wordswhen the key is already present, matching howadd_word_timestampspopulates it. Behavior whenword_timestamps=Trueis unchanged (the key is present, gets cleared to[]as before).