Skip to content

Commit 4edb59c

Browse files
Fix VTT formatting issues (#29)
1 parent bb2ff08 commit 4edb59c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ def asr_alignments_to_vtt(alignment_view, viz_id):
4646
start, end, text = start_end_text
4747
start_kwarg, end_kwarg = {timeunit: float(start)}, {timeunit: float(end)}
4848
start, end = timedelta(**start_kwarg), timedelta(**end_kwarg)
49+
s_mins, s_secs = divmod(start.seconds, 60)
50+
e_mins, e_secs = divmod(end.seconds, 60)
4951
if not vtt_start:
50-
vtt_start = f'{start.seconds // 3600 :02d}:{start.seconds:02d}.{start.microseconds // 1000 :03d}'
52+
vtt_start = f'{s_mins:02d}:{s_secs:02d}.{((s_secs - int(s_secs)) * 1000):03d}'
5153
texts.append(text)
5254
if len(texts) > 8:
53-
vtt_end = f'{end.seconds // 3600 :02d}:{end.seconds:02d}.{end.microseconds // 1000 :03d}'
55+
vtt_end = f'{e_mins:02d}:{e_secs:02d}.{((e_secs - int(e_secs)) * 1000):03d}'
5456
vtt_file.write(f'{vtt_start} --> {vtt_end}\n{" ".join(texts)}\n\n')
5557
vtt_start = None
5658
texts = []

0 commit comments

Comments
 (0)