Skip to main content

A small CLI tool to extend subtitle durations in SRT files to make them more readable on a screen.

Project description

SubGapFix

PyPI version Python versions License: MIT

SubGapFix is a lightweight CLI tool that makes subtitles easier and more comfortable to read by intelligently extending their display duration — especially useful for auto-generated subtitles.

It works great with transcriptions from WhisperX.

✨ Features

  • Extends subtitle display time when there is a gap before the next line
  • Safely prevents overlaps and negative durations
  • Dry-run mode to preview changes without writing files
  • Creates output folders automatically if needed
  • Only processes valid .srt files
  • Option to merge subtitles when a sentence is spanning over multiple subtitles (supported languages: English, Dutch)

📦 Installation

pip install subgapfix

Requires Python 3.8+.

Dependencies:

  • typer — beautiful CLI interface
  • srt — reliable SRT parsing

🚀 Quick Start

# Basic usage — creates episode_fixed.srt in the same folder
subgapfix episode.srt

# Custom output file (creates folders if needed)
subgapfix podcast/episode.srt -o podcast/enhanced/episode_subtitles.srt

# Preview changes without modifying anything
subgapfix input.srt --dry-run

# Customize timings
subgapfix input.srt --extend-sub-start 0.8 --extend-sub-end 3.0 --min-gap 1.5 --extend-final-sub 4.5

# Merge sentences (default language: en)
subgapfix input.srt --submerge --lang nl

⚙️ All Options

Flag / Short Default Description
input_file (positional) Path to the input .srt file (must exist)
-o, --output <input>_fixed.srt Output file path (folders auto-created)
--extend-sub-start, -ess 0.5 Seconds to pull the next subtitle backward (tries to borrow from gap)
--extend-sub-end, -ese 2.0 Maximum seconds to extend current subtitle forward into the gap
--min-gap, -mg 1.0 Only apply extension if gap is at least this long (seconds)
--dry-run false Show how many pairs would change — no file written
--extend-final-sub, -efs 1.0 Number of seconds to add to the last subtitle
--submerge, -sm false Merge subtitles creating full sentences
--lang, -l en Set language in order to merge sentences correctly
--help, -help Show full help and exit

How It Works

  1. Reads and validates the .srt file
  2. For each pair of consecutive subtitles:
    • If gap < --min-gap → splits the gap evenly (closes small gaps)
    • If gap ≥ --min-gap → extends current subtitle up to --extend-sub-end, pulls next one back by --extend-sub-start
  3. Prevents any overlap by enforcing a tiny 10 ms safety gap
  4. Add --extend-final-sub to the last subtitle for a precise ending
  5. Writes the result (or just reports changes in dry-run)

Before (typical WhisperX-style tight timings):

1
00:00:01,837 --> 00:00:02,502
SubGapFix makes our lives

2
00:00:03,147 --> 00:00:03,571
much easier.

3
00:00:04,176 --> 00:00:04,518
Yes, I agree.

After (with defaults):

1
00:00:01,837 --> 00:00:02,824
SubGapFix makes our lives

2
00:00:02,834 --> 00:00:03,873
much easier.

3
00:00:03,883 --> 00:00:04,679
Yes, I agree.

After (merging sentences):

1
00:00:01,837 --> 00:00:03,873
SubGapFix makes our lives much easier.

2
00:00:03,883 --> 00:00:04,679
Yes, I agree.

💡 Why SubGapFix?

Modern speech-to-text tools often prioritize transcription accuracy over comfortable reading speed.
Subtitles flash by too quickly → viewers miss text or feel rushed.

SubGapFix does not shift timings or re-sync — it only lengthens display time using existing gaps.
This keeps perfect sync with the video while making subtitles far more readable.

Perfect for lectures, interviews, conversations, podcasts.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

subgapfix-0.0.6.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

subgapfix-0.0.6-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file subgapfix-0.0.6.tar.gz.

File metadata

  • Download URL: subgapfix-0.0.6.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for subgapfix-0.0.6.tar.gz
Algorithm Hash digest
SHA256 4f191246dbfc18a6a217f7797a9d6ffff25ead8ee0cde1281e1e396923262ca7
MD5 07157b7aeeda6d6711e9db26d2de1eda
BLAKE2b-256 8c99f4e9cb7530be432c60279b1f9be3a640650d8a2348689e81264ebce389e6

See more details on using hashes here.

File details

Details for the file subgapfix-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: subgapfix-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for subgapfix-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d37048c2f9cbdac4b0d529dd82aafbb750c0683b11d2b7568ed7f8df633b7964
MD5 9993f12dc8886644624eb8165b7d9286
BLAKE2b-256 465756d457296b1011c0204758a67ead9cd28eef9df4107a98bf24b5c0e3db1f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page