fix: improve subtitle readability
This commit is contained in:
+19
-6
@@ -1,3 +1,5 @@
|
||||
import os
|
||||
import shutil
|
||||
import textwrap
|
||||
import scipy
|
||||
import numpy as np
|
||||
@@ -11,15 +13,26 @@ def clear_screen():
|
||||
|
||||
|
||||
def print_transcript(text, translated=False, timestamps=False):
|
||||
"""Prints formatted transcript text."""
|
||||
"""Prints formatted transcript text in a subtitle-like block."""
|
||||
terminal_width = shutil.get_terminal_size((80, 20)).columns
|
||||
wrap_width = max(10, min(80, terminal_width - 8))
|
||||
|
||||
if timestamps:
|
||||
lines = []
|
||||
for t in text:
|
||||
print(f'[{t["start"]} -> {t["end"]}] {t["text"]}')
|
||||
prefix = f'[{t["start"]} -> {t["end"]}] '
|
||||
wrapper = textwrap.TextWrapper(
|
||||
width=wrap_width,
|
||||
subsequent_indent=" " * len(prefix),
|
||||
)
|
||||
lines.extend(wrapper.wrap(f'{prefix}{t["text"]}'))
|
||||
else:
|
||||
wrapper = textwrap.TextWrapper(width=60)
|
||||
text=" ".join(text) if translated else "".join(text)
|
||||
for line in wrapper.wrap(text=text):
|
||||
print(line)
|
||||
wrapper = textwrap.TextWrapper(width=wrap_width)
|
||||
transcript = " ".join(text) if translated else "".join(text)
|
||||
lines = wrapper.wrap(text=transcript)
|
||||
|
||||
for line in lines[-3:]:
|
||||
print(line.center(terminal_width))
|
||||
|
||||
|
||||
def format_time(s):
|
||||
|
||||
Reference in New Issue
Block a user