subaligner.predictor module

class subaligner.predictor.Predictor(*args, **kwargs)[source]

Bases: object

Predictor for working out the time to shift subtitles

get_log_loss(voice_probabilities: numpy.ndarray, subs: List[pysrt.SubRipItem]) → float[source]

Returns a single loss value on voice prediction

Parameters
  • {list} -- A list of probabilities of audio chunks being speech. (voice_probabilities) –

  • {list} -- A list of subtitle segments. (subs) –

  • Returns – float – The loss value.

get_min_log_loss_and_index(voice_probabilities: numpy.ndarray, subs: pysrt.SubRipFile) → Tuple[float, int][source]

Returns the minimum loss value and its shift position after going through all possible shifts. :param voice_probabilities {list} – A list of probabilities of audio chunks being speech.: :param subs {list} – A list of subtitle segments.:

Returns

tuple – The minimum loss value and its position.

predict_dual_pass(video_file_path: str, subtitle_file_path: str, weights_dir: str = '/home/docs/checkouts/readthedocs.org/user_builds/subaligner/checkouts/latest/subaligner/models/training/weights', stretch: bool = False, stretch_in_lang: str = 'eng', exit_segfail: bool = False) → Tuple[List[pysrt.SubRipItem], List[pysrt.SubRipItem], Union[numpy.ndarray, List[float]], Optional[float]][source]

Predict time to shift with single pass

Arguments: video_file_path {string} – The input video file path. subtitle_file_path {string} – The path to the subtitle file. weights_dir {string} – The the model weights directory. stretch {bool} – True to stretch the subtitle segments (default: {False}) stretch_in_lang {str} – The language used for stretching subtitles (default: {“eng”}). exit_segfail {bool} – True to exit on any segment alignment failures (default: {False})

Returns: tuple – The shifted subtitles, the globally shifted subtitles and the voice probabilities of the original audio.

predict_plain_text(video_file_path: str, subtitle_file_path: str, stretch_in_lang: str = 'eng') → Tuple[source]

Predict time to shift with plain texts

Arguments: video_file_path {string} – The input video file path. subtitle_file_path {string} – The path to the subtitle file. stretch_in_lang {str} – The language used for stretching subtitles (default: {“eng”}).

Returns: tuple – The shifted subtitles, the audio file path (None) and the voice probabilities of the original audio (None).

predict_single_pass(video_file_path: str, subtitle_file_path: str, weights_dir: str = '/home/docs/checkouts/readthedocs.org/user_builds/subaligner/checkouts/latest/subaligner/models/training/weights') → Tuple[List[pysrt.SubRipItem], str, Union[numpy.ndarray, List[float]], Optional[float]][source]

Predict time to shift with single pass

Parameters
  • {string} -- The input video file path. (video_file_path) –

  • {string} -- The path to the subtitle file. (subtitle_file_path) –

  • {string} -- The the model weights directory. (weights_dir) –

Returns

tuple – The shifted subtitles, the audio file path and the voice probabilities of the original audio.