-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f07d035
commit 8043a55
Showing
7 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#' TextGrid to dataframe | ||
#' | ||
#' Convert Praat TextGrid to a dataframe. | ||
#' | ||
#' @author George Moroz <[email protected]> | ||
#' | ||
#' @param textgrid string with a filename or path to the TextGrid | ||
#' @return a dataframe with columns: \code{id}, \code{start}, \code{end} (if it is an interval tier -- the same as the start value), \code{annotation}, and \code{tier} | ||
#' | ||
#' @examples | ||
#' textgrid_to_df(example_textgrid) | ||
#' | ||
#' @export | ||
|
||
textgrid_to_df <- function(textgrid, tier = 1){ | ||
if(grepl("TextGrid", textgrid[2])){ | ||
tg <- textgrid | ||
} else{ | ||
tg <- readLines(textgrid) | ||
} | ||
n_tiers <- as.double(regmatches(tg[7], regexpr("\\d", tg[7]))) | ||
lapply(1:n_tiers, function(x){ | ||
df <- phonfieldwork::tier_to_df(tg, x) | ||
df$tier <- x | ||
if(!("end" %in% names(df))){ | ||
df <- data.frame(id = df$id, | ||
start = df$start, | ||
end = df$start, | ||
annotation = df$annotation, | ||
tier = df$tier) | ||
} | ||
return(df) | ||
}) -> | ||
l | ||
result <- Reduce(rbind, l) | ||
return(result[order(result$start),]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.