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.11
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.11.tar.gz | 12.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| subt_ai_tles-0.0.11-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.1 kB
Release files / subt_ai_tles-0.0.11.tar.gz
| Download URL | subt_ai_tles-0.0.11.tar.gz |
|---|---|
| Size | 12.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1dbc49f65e00485dbc33a85dcd6844fff7bc0f709c043e96cdd1575e2ba73318
|
|
BLAKE2b-256 checksum How to use checksums |
159b7001a2dda775cf1afee9240665af8980bb95dd4d55a9e982c116fd59f057
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","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.11-py3-none-any.whl
| Download URL | subt_ai_tles-0.0.11-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
da2ad4020c1ca5e2e8b8f9388e9aa9e7d2b8dd8335fbbefb2c4e25d4f6254d9d
|
|
BLAKE2b-256 checksum How to use checksums |
d64a6a2c2e556de1a5d799fd76a2d5abde004b62ccf3c328fec06549ed5b79e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","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}
|