as_subtitle: Convert an R object to a 'subtitles' object

View source: R/read_subtitles.R

as_subtitleR Documentation

Convert an R object to a subtitles object

Description

Convert an R object to a subtitles object

Usage

as_subtitle(
  x,
  format = "auto",
  clean.tags = TRUE,
  metadata = data.frame(),
  frame.rate = NA,
  encoding = "auto",
  ...
)

## Default S3 method:
as_subtitle(
  x,
  format = "auto",
  clean.tags = TRUE,
  metadata = data.frame(),
  frame.rate = NA,
  encoding = "auto",
  ...
)

## S3 method for class 'character'
as_subtitle(
  x,
  format = "auto",
  clean.tags = TRUE,
  metadata = data.frame(),
  frame.rate = NA,
  encoding = "auto",
  ...
)

Arguments

x

an R object that can be coerced into a subtitles object

format

a character string specifying the format of the subtitles. Four formats can be read: "subrip", "substation", "microdvd", "subviewer" (v.2) and "webvtt". Default is "auto" which tries to detect automatically the format of the file from its extension.

clean.tags

logical. If "TRUE" (default), formatting tags are deleted from subtitles using clean_tags.

metadata

a one-row dataframe or tibble, or any object that can be coerced into a one-row tibble by link[tibble]{as_tibble}.

frame.rate

a numeric value giving the frame rate in frames per second. Only relevant for MicroDVD format. If NA (default), the function tries to extract the frame.rate from the file. If it fails, the frame rate is set at 24p (23.976).

encoding

the name of the encoding to be used. Default is "auto" and uses guess_encoding to detect encoding.

...

passed on to downstream methods.

Value

An object of class subtitles (see subtitles).

Examples

as_subtitle(
  c("WEBVTT",
    "X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000",
    "",
    "3",
    "00:00:21.199 --> 00:00:22.333", ">> FEMALE SPEAKER:",
    "Don't stay up too late.",
    "",
    ""
  ), format = "webvtt"
)

subtools documentation built on March 24, 2026, 5:07 p.m.