Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Extract pitch values, intensity, time, and confidence from Praat pitch files
#!/usr/bin/env r
## load pitch files extracted from Praat and pull key information
# take input from the command line
f <- argv
# load packages and hide messages
# load the file
pitch_path <- f
p <-
# extract the filename - will be used to save the output
pitch_filename <- basename(pitch_path)
# extract pitch
pitch <- p$frame
# run through all frame examples and extract max strength freq
# extract strength
strength_list <- lapply(pitch, `[[`, "strength")
max_strength <- lapply(strength_list, max) %>% unlist()
max_strength_index <- lapply(strength_list, which.max) %>% unlist()
# extract frequency
frequency_list <- lapply(pitch, `[[`, "frequency")
max_strength_frequency <- c()
for (i in 1:length(frequency_list)) {
## extract pitch where strength has the max value
## that's the best candidate in Praat (i.e. pink circle in the Pitch Track)
max_strength_frequency[i] <- frequency_list[[i]][[max_strength_index[i]]]
# time
time <- p$t
# extract intensity
intensity <- lapply(pitch, `[[`, "intensity") %>% unlist()
# make a df with the key values
key_values <- data.frame(Time = time,
Intensity = intensity,
Frequency = max_strength_frequency,
MaxStrength = max_strength,
File = pitch_filename,
stringsAsFactors = FALSE)
paste0(tools::file_path_sans_ext(pitch_filename), ".csv"),
row.names = FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.