Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix timing overlap issue (#816) #1

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions whisperx/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,19 @@ def iterate_subtitles():
yield subtitle, times

if "words" in result["segments"][0]:
for subtitle, _ in iterate_subtitles():
sstart, ssend, speaker = _[0]
for subtitle, times in iterate_subtitles():
# TODO: handle multiple segments with different start/end times and speakers
sstart, send, speaker = times[0]
has_timing = any(["start" in timing for timing in subtitle])
if has_timing:
sstart = next(timing["start"] for timing in subtitle if "start" in timing)
send = next(timing["end"] for timing in reversed(subtitle) if "end" in timing)
subtitle_start = self.format_timestamp(sstart)
subtitle_end = self.format_timestamp(ssend)
subtitle_end = self.format_timestamp(send)
if result["language"] in LANGUAGES_WITHOUT_SPACES:
subtitle_text = "".join([word["word"] for word in subtitle])
else:
subtitle_text = " ".join([word["word"] for word in subtitle])
has_timing = any(["start" in word for word in subtitle])

# add [$SPEAKER_ID]: to each subtitle if speaker is available
prefix = ""
Expand Down