Skip to main content

SUBT-AI-TLES

A simple wrapper around your LLM for movie subtitles translation that makes

What does it do?

  • Parses the .srt
  • Requests individual lines to be translated by the LLM
  • Puts it all back together, making sure the sentences match the srt structure/timings
  • Caches results - which makes rerunning failed runs a possibility

Provided adapters

So far OpenAI API is the only supported/pre-implemented 'backend'

Setup required environment variables and then simply import and invoke the function.

import asyncio
from subtaitles import translate_srt_file, Engine, Lang

# use predefined translators from the Engine enum
asyncio.run(
    translate_srt_file(
        path="/tmp/subtitles.en.srt",
        new_path="/tmp/subtitles.de.srt",
        translator=Engine.OPEN_AI,
        source=Lang.EN,
        target=Lang.DE,
    )
)
# behavior and configuration is controlled via environment variables
# all the used variables are defined int the environment module
from subtaitles import env

Directory mode

A directory mode is included as well that tries to translate ALL the .srt files it can find in the supplied directory path. Locale extension are used to avoid re-running the translation over and over, e.g.:

If sub-1.de.srt already exists in the directory and translation from en -> de is to be performed on it, the file sub-1.srt will be skipped altogether.

import asyncio
from subtaitles import Lang, Engine
from subtaitles.filesystem import translate_directory

asyncio.run(
    translate_directory(
        path="/tmp/data/shows/foo/season-01",
        translator=Engine.OPEN_AI,
        source=Lang.EN,
        target=Lang.DE,
    )
)

Custom implementations

An arbitrary class that implements the TranslateProtocol can be passed to both the translate_srt_file() and translate_srt()

import asyncio
from subtaitles import Lang, translate_srt_file


class MyCustomTranslator:
    async def translate(
        self,
        text: list[str],
        language_from: Lang,
        language_to: Lang,
    ) -> list[str]:
        # <implement whatever floats your boat>
        ...


asyncio.run(
    translate_srt_file(
        path="/tmp/subtitles.en.srt",
        new_path="/tmp/subtitles.de.srt",
        translator=MyCustomTranslator(),
        source=Lang.EN,
        target=Lang.DE,
    )
)

CLI

translate_srt_file is exposed as a utility command for command line usage:

translate_subtitles --help
translate_subtitles --engine openai /tmp/subtitles.en.srt /tmp/subtitles.de.srt en de

Metadata

Release files for subt-ai-tles 0.0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for subt-ai-tles 0.0.12
File Size Uploaded Provenance
subt_ai_tles-0.0.12.tar.gz 11.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for subt-ai-tles 0.0.12
File Interpreter ABI Platform
subt_ai_tles-0.0.12-py3-none-any.whl Python 3 none any Details

Total release size: 27.8 kB

Release files / subt_ai_tles-0.0.12.tar.gz

Download URL subt_ai_tles-0.0.12.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3f157d22d2fc4839f381a0ef7366da205b86a38936d0ad824cb6c48f982824fa
BLAKE2b-256 checksum
How to use checksums
6f35679b479ed769ae0b16f2adb9a4d1ced3d537a60c29ceed73e3336b634c4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"44","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / subt_ai_tles-0.0.12-py3-none-any.whl

Download URL subt_ai_tles-0.0.12-py3-none-any.whl
Size 16.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c061c0f732ca5626ffe27faf8b5ace13de97993847d1143a612c3ed33207473
BLAKE2b-256 checksum
How to use checksums
5aa9fe50c6ca71070fb86c4d61c94c1a4ddc821fb0e9dc3269883a4e0bad4c01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"44","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for subt-ai-tles 0.0.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page