files.py 589 B

1234567891011121314151617
  1. import os
  2. from typing import Iterator, TextIO
  3. from .convert import format_timestamp
  4. def write_srt(transcript: Iterator[dict], file: TextIO):
  5. for i, segment in enumerate(transcript, start=1):
  6. print(
  7. f"{i}\n"
  8. f"{format_timestamp(segment.start, always_include_hours=True)} --> "
  9. f"{format_timestamp(segment.end, always_include_hours=True)}\n"
  10. f"{segment.text.strip().replace('-->', '->')}\n",
  11. file=file,
  12. flush=True,
  13. )
  14. def filename(path: str):
  15. return os.path.splitext(os.path.basename(path))[0]