knitr::opts_chunk$set( collapse = TRUE, warning = FALSE, message = FALSE, error = FALSE, comment = "#>", fig.path = "man/figures/README-", fig.height = 4, fig.width = 9, out.width = "100%", dpi = 300 ) if (!interactive()) { options(width = 95) }
The goal of srt is to read SubRip text files as tabular data for easy analysis and manipulation.
You can install the development version of srt from GitHub with:
# install.packages("remotes") remotes::install_github("k5cents/srt")
The .srt
standard is used to identify the subtitle components for the columns
of a data frame:
-->
and the time it
should disappearlibrary(srt) library(tidyverse) library(tidytext) srt <- srt_example()
cat(readLines(srt, n = 11), sep = "\n")
These subtitle files are parsed as data frames with separate columns.
(wonderful_life <- read_srt(path = srt, collapse = " "))
This makes it easy to perform various text analysis on the subtitles.
wonderful_life %>% unnest_tokens(word, subtitle) %>% count(word, sort = TRUE) %>% anti_join(stop_words)
Or uniformly manipulate the numeric time stamps:
wonderful_life <- srt_shift(wonderful_life, seconds = 9.99)
The subtitle data frames can be easily re-written as valid SubRip files.
tmp <- tempfile(fileext = ".srt") write_srt(wonderful_life, tmp, wrap = FALSE)
cat(readLines(tmp, n = 11), sep = "\n")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.