Skip to content

Commit

Permalink
[DONE] Transcription : Adjusting subtitle display timing (#1072)
Browse files Browse the repository at this point in the history
* Proposal for the "improveCaptionsAccessibility" method

* Fixup. Format code with Black

---------

Co-authored-by: github-actions <[email protected]>
  • Loading branch information
david42 and github-actions authored Mar 12, 2024
1 parent 5322227 commit 55173ba
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pod/video_encode_transcript/transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,23 @@ def improveCaptionsAccessibility(webvtt):
new_captions = []
for caption in webvtt.captions:
sent = split_string(caption.text, 40, sep=" ")
# nb mots total
nbTotWords = len(caption.text.split())
if len(sent) > 2:
num_captions = int(len(sent) / 2)
if len(sent) % 2:
num_captions += 1
dur = caption.end_in_seconds - caption.start_in_seconds
# On se positionne sur le point de départ en sec
startTime = caption.start_in_seconds
for x in range(num_captions):
new_cap = Caption()
new_cap.start = sec_to_timestamp(
caption.start_in_seconds + x * dur / num_captions
)
new_cap.end = sec_to_timestamp(
caption.start_in_seconds + (x + 1) * dur / num_captions
)
new_cap.text = get_cap_text(sent, x)
# Durée d'affichage au prorata du nombre de mots
timeCalc = dur * (len(new_cap.text.split()) / nbTotWords)
new_cap.start = sec_to_timestamp(startTime)
new_cap.end = sec_to_timestamp(startTime + timeCalc)
startTime = startTime + timeCalc
new_captions.append(new_cap)
else:
new_cap = Caption()
Expand Down

0 comments on commit 55173ba

Please sign in to comment.