Skip to main content

No project description provided

Project description

SUBT-AI-TLES

A simple wrapper around LLMs that provides language translation interface for subtitles (.srt).

Predefined implementations

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

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

subt_ai_tles-0.0.5.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

subt_ai_tles-0.0.5-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file subt_ai_tles-0.0.5.tar.gz.

File metadata

  • Download URL: subt_ai_tles-0.0.5.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for subt_ai_tles-0.0.5.tar.gz
Algorithm Hash digest
SHA256 c3cc5e03d3a410494a28732b9e2b0cc67ed5aa5ef8e099b7e46e1de7b88ae568
MD5 b7cbbb5fe8a76fe2551ef3b09d1fb6ec
BLAKE2b-256 20e624dcd1ff730cfa481c38a3c1cd52de1253673a240f18a384ecb63c7e41ac

See more details on using hashes here.

File details

Details for the file subt_ai_tles-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for subt_ai_tles-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c3a833b384abc2452a4f8eccac9e8fdda9c527784ec41cc65d347d8b820b88e5
MD5 26f8b3c710dd45309e6c6b94ce4ef892
BLAKE2b-256 a93d8149ebf55c805a3a2b0f03628172f98502f1933b566c2aca9aef67d94c08

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