readtextgrid
readtextgrid parses Praat textgrids into tidy R dataframes.
Features
- Simple: Minimal package with two core functions (
read_textgrid()andread_textgrid_lines()). - Tidy: Returns rectangular tibbles ready for downstream processing with dplyr and tidyr.
- Flexible: Supports both long and short textgrid file formats.
- Fast: Uses a compiled C++ tokenizer for high-throughput parsing.
Installation
Install readtextgrid from CRAN:
install.packages("readtextgrid")Development version. Install precompiled version of readtextgrid from R-universe:
install.packages(
"readtextgrid",
repos = c("https://tjmahr.r-universe.dev", "https://cloud.r-project.org")
)Basic usage
Here is the example textgrid created by Praat. It was created using
New > Create TextGrid... with default settings in Praat.
This textgrid is bundled with this R package. We can locate the file
with example_textgrid(). We read in the textgrid with
read_textgrid().
library(readtextgrid)
# Locates path to an example textgrid bundled with this package
tg <- example_textgrid()
read_textgrid(path = tg)
#> # A tibble: 3 × 10
#> file tier_num tier_name tier_type tier_xmin tier_xmax
#> <chr> <int> <chr> <chr> <dbl> <dbl>
#> 1 Mary_John_bell.TextGrid 1 Mary IntervalTier 0 1
#> 2 Mary_John_bell.TextGrid 2 John IntervalTier 0 1
#> 3 Mary_John_bell.TextGrid 3 bell TextTier 0 1
#> xmin xmax text annotation_num
#> <dbl> <dbl> <chr> <int>
#> 1 0 1 "" 1
#> 2 0 1 "" 1
#> 3 NA NA <NA> NAThe dataframe contains one row per annotation: one row for each interval
on an interval tier and one row for each point on a point tier. If a
point tier has no points, it is represented with single row with NA
values.
The columns encode the following information:
filefilename of the textgrid. By default this column uses the filename inpath. A user can override this value by setting thefileargument inread_textgrid(path, file), which can be useful if textgrids are stored in speaker-specific folders.tier_numthe number of the tier (as in the left margin of Praat’s textgrid editor)tier_namethe name of the tier (as in the right margin of Praat’s textgrid editor)tier_typethe type of the tier."IntervalTier"for interval tiers and"TextTier"for point tiers (this is the terminology used inside of the textgrid file format).tier_xmin,tier_xmaxstart and end times of the tier in secondsxmin,xmaxstart and end times of the textgrid interval or point tier annotation in secondstextthe text in the annotationannotation_numthe number of the annotation in that tier (1 for the first annotation, etc.)
Reading in directories of textgrids
Suppose we have data on multiple speakers with one folder of textgrids
per speaker. As an example, this package has a folder called
speaker_data bundled with it representing 5 five textgrids from 2
speakers.