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.srtalready exists in the directory and translation fromen -> deis to be performed on it, the filesub-1.srtwill 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.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| subt_ai_tles-0.0.10.tar.gz | 10.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| subt_ai_tles-0.0.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.0 kB
Release files / subt_ai_tles-0.0.10.tar.gz
| Download URL | subt_ai_tles-0.0.10.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
db0968577bfc15d4c0d9fed1e834cb37c2114a80177851a4a4690b1ce708e46f
|
|
BLAKE2b-256 checksum How to use checksums |
7e632b3e4e4e802d67506d7944bc476f64bf16898e5c1486e9aaeb8db2f97fbe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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.10-py3-none-any.whl
| Download URL | subt_ai_tles-0.0.10-py3-none-any.whl |
|---|---|
| Size | 15.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8090ff29275e71621bebfea7e60b3d253e6e043a8d4e3465a1a516092e89e8a0
|
|
BLAKE2b-256 checksum How to use checksums |
3489d6225980ce8c6fa1c8987aed9e0070b9773f6f5859bdbade429529f21445
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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}
|