mixing.dubbing.srt¶
SRT translation for dubbing — built on the canonical mixing.srt.
SRT parsing/serialization and the Cue model live in
mixing.srt; this module re-exports them and adds the dubbing-specific
piece: translating cue text into another language while preserving timings.
Translation is pluggable: pass any translate_fn that maps a list of strings
to a list of the same length. The default uses an LLM via the aix package
(provider-agnostic) when it is importable.
Module Attributes
A translator maps (texts, target_language, source_language) -> texts. |
Functions
|
Parse SRT text into a list of |
|
Serialize cues back to SRT text, renumbering from 1. |
|
Parse an |
|
Translate the cue text of an SRT to |
|
LLM-backed translator (segment-count preserving) using |
Classes
|
One SRT subtitle cue. |
- mixing.dubbing.srt.TranslateFn¶
A translator maps (texts, target_language, source_language) -> texts.
alias of
Callable[[Sequence[str],str,str | None],list[str]]
- mixing.dubbing.srt.default_translate_fn(texts, target_language, source_language=None, *, model=None)[source]¶
LLM-backed translator (segment-count preserving) using
aix.chat.Translates all segments in a single call, returning a JSON array so the one-to-one mapping with the input cues is preserved. Falls back to a clear error if
aixis not importable — pass your owntranslate_fnthen.
- mixing.dubbing.srt.dump_srt(cues)[source]¶
Serialize cues back to SRT text, renumbering from 1.
- Return type:
- mixing.dubbing.srt.parse_srt(srt_text)[source]¶
Parse SRT text into a list of
Cueobjects.Tolerant of blank-line spacing variations and of either
,or.as the millisecond separator. Cues without a valid time line are skipped.
- mixing.dubbing.srt.srt_time_to_seconds(timestamp)[source]¶
Parse an
HH:MM:SS,mmm(or.mmm) SRT timestamp to seconds.>>> srt_time_to_seconds('00:43:12,187') 2592.187 >>> srt_time_to_seconds('00:00:01.500') 1.5- Return type:
- mixing.dubbing.srt.translate_srt(srt, target_language, *, source_language=None, translate_fn=None)[source]¶
Translate the cue text of an SRT to
target_language, keeping timings.- Parameters:
srt (
Union[str,Sequence[Cue]]) – SRT text or a list ofCueobjects.target_language (
str) – Human-readable target language (e.g."French").source_language (
str|None) – Optional source language hint.translate_fn (
Optional[Callable[[Sequence[str],str,str|None],list[str]]]) – A callable(texts, target_language, source_language) -> list[str]returning one translation per input text, in order. Defaults todefault_translate_fn()(LLM-backed).
- Return type:
- Returns:
Translated SRT text with the original cue timings.
- Raises:
ValueError – The translator returned a different number of segments than it was given.