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

TranslateFn

A translator maps (texts, target_language, source_language) -> texts.

Functions

parse_srt(srt_text)

Parse SRT text into a list of Cue objects.

dump_srt(cues)

Serialize cues back to SRT text, renumbering from 1.

srt_time_to_seconds(timestamp)

Parse an HH:MM:SS,mmm (or .mmm) SRT timestamp to seconds.

translate_srt(srt, target_language, *[, ...])

Translate the cue text of an SRT to target_language, keeping timings.

default_translate_fn(texts, target_language)

LLM-backed translator (segment-count preserving) using aix.chat.

Classes

Cue(index, start, end, text)

One SRT subtitle cue.

class mixing.dubbing.srt.Cue(index, start, end, text)[source]

Bases: object

One SRT subtitle cue.

index

1-based cue number.

Type:

int

start

Start time in seconds.

Type:

float

end

End time in seconds.

Type:

float

text

Cue text (may contain embedded newlines).

Type:

str

property duration: float

Cue duration in seconds (never negative).

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 aix is not importable — pass your own translate_fn then.

Return type:

list[str]

mixing.dubbing.srt.dump_srt(cues)[source]

Serialize cues back to SRT text, renumbering from 1.

Return type:

str

mixing.dubbing.srt.parse_srt(srt_text)[source]

Parse SRT text into a list of Cue objects.

Tolerant of blank-line spacing variations and of either , or . as the millisecond separator. Cues without a valid time line are skipped.

Return type:

list[Cue]

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:

float

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:
Return type:

str

Returns:

Translated SRT text with the original cue timings.

Raises:

ValueError – The translator returned a different number of segments than it was given.