Title: | Read in a 'Praat' 'TextGrid' File |
---|---|
Description: | 'Praat' <https://www.fon.hum.uva.nl/praat/> is a widely used tool for manipulating, annotating and analyzing speech and acoustic data. It stores annotation data in a format called a 'TextGrid'. This package provides a way to read these files into R. |
Authors: | Tristan Mahr [aut, cre] |
Maintainer: | Tristan Mahr <[email protected]> |
License: | GPL-3 |
Version: | 0.1.2.9000 |
Built: | 2024-11-22 04:06:30 UTC |
Source: | https://github.com/tjmahr/readtextgrid |
Locate the path of an example textgrid file
example_textgrid(which = 1)
example_textgrid(which = 1)
which |
index of the textgrid to load |
This function is a wrapper over system.file()
to locate the
paths to bundled textgrids. These files are used to test or demonstrate
functionality of the package.
Two files are included:
"Mary_John_bell.TextGrid"
- the default TextGrid created by Praat's
Create TextGrid command. This file is saved as UTF-8 encoding.
"utf_16_be.TextGrid"
- a TextGrid with some IPA characters entered using
Praat's IPA character selector. This file is saved with UTF-16 encoding.
"nested-intervals.TextGrid"
- A textgrid containing an "utterance"
tier, a "words"
tier, and a "phones"
tier. This file is typical of
forced alignment textgrids where utterances contain words which contain
speech segments. In this case, alignment was made by hand so that word
and phone boundaries do not correspond exactly.
Path of "Mary_John_bell.TextGrid"
bundled with the readtextgrid
package.
Pivot a textgrid into wide format, respecting nested tiers
pivot_textgrid_tiers(data, tiers, join_cols = "file")
pivot_textgrid_tiers(data, tiers, join_cols = "file")
data |
a textgrid dataframe created with |
tiers |
character vector of tiers to pivot into wide format. When
|
join_cols |
character vector of the columns that will uniquely identify
a textgrid file. Defaults to |
For the joining nested intervals, two intervals a and b are combined into
the same row if they match on the values in the join_cols
columns and if
the a$xmin <= b$xmid
and b$xmid <= a$xmax
. That is, if the midpoint of
b is contained inside the interval a.
a dataframe with just the intervals from tiers named in tiers
converted into a wide format. Columns are renamed so that the text
column
is pivot into columns named after the tier names. For example, the text
column in a words
tier is renamed to words
. The xmax
, xmin
,
annotation_num
, tier_num
, tier_type
are also prefixed with the tier
name. For example, the xmax
column in a words
tier is renamed to
words_xmax
. An additional helper column xmid
is added and prefixed
appropriately. See examples below.
data <- example_textgrid(3) |> read_textgrid() data # With a single tier, we get just that tier with the columns prefixed with # the tier_name pivot_textgrid_tiers(data, "utterance") pivot_textgrid_tiers(data, "words") # With multiple tiers, intervals in one tier that contain intervals in # another tier are combined into the same row. a <- pivot_textgrid_tiers(data, c("utterance", "words")) cols <- c( "utterance", "utterance_xmin", "utterance_xmax", "words", "words_xmin", "words_xmax" ) a[cols] a <- pivot_textgrid_tiers(data, c("utterance", "words", "phones")) cols <- c(cols, "phones", "phones_xmin", "phones_xmax") a[cols]
data <- example_textgrid(3) |> read_textgrid() data # With a single tier, we get just that tier with the columns prefixed with # the tier_name pivot_textgrid_tiers(data, "utterance") pivot_textgrid_tiers(data, "words") # With multiple tiers, intervals in one tier that contain intervals in # another tier are combined into the same row. a <- pivot_textgrid_tiers(data, c("utterance", "words")) cols <- c( "utterance", "utterance_xmin", "utterance_xmax", "words", "words_xmin", "words_xmax" ) a[cols] a <- pivot_textgrid_tiers(data, c("utterance", "words", "phones")) cols <- c(cols, "phones", "phones_xmin", "phones_xmax") a[cols]
Read a textgrid file into a tibble
read_textgrid(path, file = NULL, encoding = NULL) read_textgrid_lines(lines, file = NULL)
read_textgrid(path, file = NULL, encoding = NULL) read_textgrid_lines(lines, file = NULL)
path |
a path to a textgrid |
file |
an optional value to use for the |
encoding |
the encoding of the textgrid. The default value |
lines |
alternatively, the lines of a textgrid file |
a tibble with one row per textgrid annotation
tg <- system.file("Mary_John_bell.TextGrid", package = "readtextgrid") read_textgrid(tg)
tg <- system.file("Mary_John_bell.TextGrid", package = "readtextgrid") read_textgrid(tg)