View Source Subtitle.Cue (kim_subtitle v0.1.0)

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

@type merge_option() :: {:max_lines, pos_integer()} | {:max_duration, pos_integer()}
@type split_option() :: {:min_length, pos_integer()} | {:max_length, pos_integer()}
@type t() :: %Subtitle.Cue{
  from: non_neg_integer(),
  id: String.t(),
  text: String.t(),
  to: pos_integer()
}
Link to this type

to_paragraphs_option()

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

Functions

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

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

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

Cuts the duration to at most max_duration.

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

Returns the duration of the cue.

Link to this function

extend(cue, min_duration)

View Source
@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.

Link to this function

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

View Source
@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.

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

Splits a cue into multiple single-line 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.

Link to this function

to_paragraphs(cues, opts \\ [])

View Source
@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.

Link to this function

to_paragraphs_lazy(cues, opts \\ [])

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

Lazy version of to_paragraphs/2.