This guide helps you translate Praat scripts into R code using pladdrr. The package provides a direct object-oriented interface to Praat’s functionality.
Praat Script:
sound = Read from file: "audio.wav"
pladdrr:
Praat commands become method calls following a consistent naming pattern:
| Praat Command | pladdrr Method | Pattern |
|---|---|---|
To Pitch... |
to_pitch() |
To X → to_x() |
To Formant (burg)... |
to_formant_burg() |
To X (y) → to_x_y() |
Get mean... |
get_mean() |
Get x → get_x() |
Set value... |
set_value() |
Set x → set_x() |
Praat Script:
sound = Read from file: "audio.wav"
pitch = To Pitch: 0.01, 75, 600
mean_f0 = Get mean: 0, 0, "Hertz"
std_f0 = Get standard deviation: 0, 0, "Hertz"
pladdrr:
sound <- Sound$new(system.file("extdata", "test.wav", package = "pladdrr"))
pitch <- sound$to_pitch(time_step = 0.01, pitch_floor = 75, pitch_ceiling = 600)
mean_f0 <- pitch$get_mean(from_time = 0, to_time = 0, unit = "hertz")
std_f0 <- pitch$get_standard_deviation(from_time = 0, to_time = 0,
unit = "hertz")Praat Script:
sound = Read from file: "vowel.wav"
formant = To Formant (burg): 0.01, 5, 5500, 0.025, 50
f1 = Get value at time: 1, 0.5, "Hertz", "Linear"
f2 = Get value at time: 2, 0.5, "Hertz", "Linear"
pladdrr:
sound <- Sound$new(system.file("extdata", "test.wav", package = "pladdrr"))
formant <- sound$to_formant_burg(
time_step = 0.01,
max_number_of_formants = 5,
maximum_formant = 5500,
window_length = 0.025,
pre_emphasis_from = 50
)
f1 <- formant$get_value_at_time(formant_number = 1, time = 0.5, unit = "hertz")
f2 <- formant$get_value_at_time(formant_number = 2, time = 0.5, unit = "hertz")Praat Script:
sound = Read from file: "audio.wav"
intensity = To Intensity: 100, 0.01, "yes"
mean_intensity = Get mean: 0, 0, "energy"
max_intensity = Get maximum: 0, 0, "Parabolic"
pladdrr:
sound <- Sound$new(system.file("extdata", "test.wav", package = "pladdrr"))
intensity <- sound$to_intensity(minimum_pitch = 100, time_step = 0.01,
subtract_mean = TRUE)
mean_intensity <- intensity$get_mean(from_time = 0, to_time = 0,
averaging_method = "energy")
max_intensity <- intensity$get_maximum(from_time = 0, to_time = 0,
interpolation = "parabolic")Praat Script:
sound = Read from file: "audio.wav"
spectrum = To Spectrum: "yes"
cog = Get centre of gravity: 2.0
pladdrr:
Praat Script:
textgrid = Create TextGrid: 0, 1, "words phones", "phones"
Insert boundary: 1, 0.5
Set interval text: 1, 1, "hello"
pladdrr:
Create Strings as file list: "fileList", "*.wav"
numberOfFiles = Get number of strings
for ifile to numberOfFiles
selectObject: "Strings fileList"
fileName$ = Get string: ifile
sound = Read from file: fileName$
pitch = To Pitch: 0.01, 75, 600
mean_f0 = Get mean: 0, 0, "Hertz"
appendFileLine: "results.txt", fileName$, tab$, mean_f0
removeObject: sound, pitch
endfor
library(pladdrr)
# Get list of WAV files
files <- list.files(pattern = "\\.wav$", full.names = TRUE)
# Process each file
results <- lapply(files, function(filepath) {
sound <- Sound$new(filepath)
pitch <- sound$to_pitch(time_step = 0.01, pitch_floor = 75,
pitch_ceiling = 600)
mean_f0 <- pitch$get_mean(from_time = 0, to_time = 0, unit = "hertz")
data.frame(
file = basename(filepath),
mean_f0 = mean_f0
)
})
# Combine results
results_df <- do.call(rbind, results)
write.csv(results_df, file.path(tempdir(), "results.csv"), row.names = FALSE)library(pladdrr)
library(dplyr)
library(purrr)
results <- tibble(file = list.files(pattern = "\\.wav$")) %>%
mutate(
sound = map(file, Sound$new),
pitch = map(sound,
~.$to_pitch(time_step = 0.01, pitch_floor = 75, pitch_ceiling = 600)),
mean_f0 = map_dbl(pitch,
~.$get_mean(from_time = 0, to_time = 0, unit = "hertz")),
sd_f0 = map_dbl(pitch,
~.$get_standard_deviation(from_time = 0, to_time = 0, unit = "hertz"))
) %>%
select(file, mean_f0, sd_f0)library(ggplot2)
# Extract pitch contour
sound <- Sound$new(system.file("extdata", "test.wav", package = "pladdrr"))
pitch <- sound$to_pitch(time_step = 0.01, pitch_floor = 75, pitch_ceiling = 600)
pitch_data <- pitch$as_data_frame()
# Plot
ggplot(pitch_data, aes(x = time, y = frequency)) +
geom_line() +
labs(title = "Pitch Contour", x = "Time (s)", y = "Frequency (Hz)") +
theme_minimal()Praat uses explicit object selection and removal:
selectObject: sound
removeObject: sound
pladdrr uses R’s garbage collection (automatic):
Praat uses 0, 0 to mean “entire
range”:
mean_f0 = Get mean: 0, 0, "Hertz"
pladdrr follows the same convention:
help(package = "pladdrr")?Sound, ?Pitch,
?Formant, etc.vignette(package = "pladdrr")Most translations follow a simple pattern: convert Praat commands to lowercase method names with underscores, and use named parameters.
For complex workflows, pladdrr can be combined with R’s data manipulation and visualization packages (e.g. dplyr, purrr, ggplot2).