Skip to main content

Transform subtitle line lengths, splitting into multiple subtitle fragments if necessary.

Project description

SRT Equalizer

A Python module to transform subtitle line lengths, splitting into multiple subtitle fragments if necessary. Useful to adjust automatic speech recognition outputs from e.g. Whisper to a more convenient size.

This library works for all languages where spaces separate words.

Example

If the SRT file contains lines over a certain length like this:

1
00:00:00,000 --> 00:00:04,000
Good evening. I appreciate you giving me a few minutes of your time tonight

2
00:00:04,000 --> 00:00:11,000
so I can discuss with you a complex and difficult issue, an issue that is one of the most profound of our time.

Using this code to shorten the subtitles to a maximum length of 42 chars:

from srt_equalizer import srt_equalizer

srt_equalizer.equalize_srt_file("test.srt", "shortened.srt", 42)

...they are split into multiple fragments and time code is adjusted to the approximate proportional length of each segment while staying inside the time slot for the fragment.

1
00:00:00,000 --> 00:00:02,132
Good evening. I appreciate you giving me

2
00:00:02,132 --> 00:00:04,000
a few minutes of your time tonight

3
00:00:04,000 --> 00:00:06,458
so I can discuss with you a complex and

4
00:00:06,458 --> 00:00:08,979
difficult issue, an issue that is one of

5
00:00:08,979 --> 00:00:11,000
the most profound of our time.

Is is also possible to work with the subtitle items with the following utility methods:

split_subtitle(sub: srt.Subtitle, target_chars: int=42, start_from_index: int=1) -> list[srt.Subtitle]:

whisper_result_to_srt(segments: list[dict]) -> list[srt.Subtitle]:

Contributing

This library is build with Poetry. Checkout this repo and run poetry install in the source folder. To run tests use poetry run pytest tests.

If you want to explore the library start a poetry shell.

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

srt_equalizer-0.1.2.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

srt_equalizer-0.1.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file srt_equalizer-0.1.2.tar.gz.

File metadata

  • Download URL: srt_equalizer-0.1.2.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.10.5 Darwin/22.4.0

File hashes

Hashes for srt_equalizer-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1c050a3250755ebddfd68c38bdbc84019e8799fa4c1f9d64f54dcf04b78b8826
MD5 754519c8dab3ce832c54f655bd384665
BLAKE2b-256 c9bdffa745f32d23268ea6b9b2b8e6267d05be7544572a7e81d4f7f1097bf330

See more details on using hashes here.

File details

Details for the file srt_equalizer-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: srt_equalizer-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.10.5 Darwin/22.4.0

File hashes

Hashes for srt_equalizer-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 39c5b52396da3feffd1de3b0cde97b5188942dd3f0330814e733f24d78ee8114
MD5 507330b96c2917032f155230b3d31b9e
BLAKE2b-256 ad0e431a46f0f8ac3b4176a1b8696ff1d945100fa70907e9fa051ca546a27c67

See more details on using hashes here.

Supported by

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