Subtitle.Cue (kim_subtitle v0.1.6)

View Source

Cue manipulation. It is aware of WebVTT tags in the text field.

Summary

Functions

Transforms cue into a temporarily ordered sequence of cues, preserving their duration. It adds 1ms between overapping cues.

Cuts the duration to at most max_duration.

Returns the duration of the cue.

Extend cue to last at least min_duration. May produce overlapping cues that can be fixed by calling __MODULE__.align/1.

Merges two cues given the following conditions

Splits a cue into multiple single-line cues.

Removes overlapping cues. This function is useful after merging HLS segments, as a cue might be repeated in multiple segments.

Creates a list of paragraphs obtained from the text of the cues. Merges together cues that have no silence in between. Silence is configurable through the opts.silence option, which defaults to 1ms.

Lazy version of to_paragraphs/2.

Types

merge_option()

@type merge_option() :: {:max_lines, pos_integer()} | {:max_duration, pos_integer()}

split_option()

@type split_option() :: {:max_length, pos_integer()}

t()

@type t() :: %Subtitle.Cue{
  from: non_neg_integer(),
  id: String.t(),
  text: String.t(),
  to: pos_integer()
}

to_paragraphs_option()

@type to_paragraphs_option() :: {:silence, pos_integer()}

Functions

align(cues, min_duration \\ nil)

Transforms cue into a temporarily ordered sequence of cues, preserving their duration. It adds 1ms between overapping cues.

cut(cue, max_duration)

@spec cut(t(), pos_integer()) :: t()

Cuts the duration to at most max_duration.

duration(cue)

@spec duration(t()) :: pos_integer()

Returns the duration of the cue.

extend(cue, min_duration)

@spec extend(t(), non_neg_integer()) :: t()

Extend cue to last at least min_duration. May produce overlapping cues that can be fixed by calling __MODULE__.align/1.

merge(cue1, cue2, opts \\ [])

@spec merge(t(), t(), [merge_option()]) :: {:ok, t()} | {:error, atom()}

Merges two cues given the following conditions:

  • The number of lines do not exceed opts.max_lines
  • The distance between the two cues is less than @max_distance_ms.
  • The duration of the cues does not exceed opts.max_duration

The cues must be sorted by time, should not overlap and should not contain new lines.

split(cue, opts \\ [])

@spec split(t(), [split_option()]) :: [t()]

Splits a cue into multiple single-line cues.

tidy(cues)

@spec tidy([t()]) :: [t()]

Removes overlapping cues. This function is useful after merging HLS segments, as a cue might be repeated in multiple segments.

to_paragraphs(cues, opts \\ [])

@spec to_paragraphs([t()], [to_paragraphs_option()]) :: [
  {:text | :speaker, String.t()}
]

Creates a list of paragraphs obtained from the text of the cues. Merges together cues that have no silence in between. Silence is configurable through the opts.silence option, which defaults to 1ms.

to_paragraphs_lazy(cues, opts \\ [])

@spec to_paragraphs_lazy(Enumerable.t(), Keyword.t()) :: Stream.t()

Lazy version of to_paragraphs/2.

to_records(cues)