Phonetics Tools in R - Supplementary code

Data processing

library(tidyverse)
## ── Attaching packages ────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2     ✓ purrr   0.3.4
## ✓ tibble  3.0.3     ✓ dplyr   1.0.2
## ✓ tidyr   1.1.2     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## ── Conflicts ───────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(PraatR)
library(rPraat)
library(phonR)
library(dygraphs)
library(phonTools)
## 
## Attaching package: 'phonTools'
## The following object is masked from 'package:dplyr':
## 
##     slice
library(audio)
## 
## Attaching package: 'audio'
## The following object is masked from 'package:phonTools':
## 
##     play
library(tuneR)
## 
## Attaching package: 'tuneR'
## The following object is masked from 'package:audio':
## 
##     play
## The following objects are masked from 'package:phonTools':
## 
##     normalize, play
library(gss)
absdir = "/Users/marissabarlaz/Desktop/FemaleBP/"
mydir = list.files(absdir, "*.WAV")
mydir
##  [1] "BP17-L-babado.WAV"  "BP17-L-cabido.WAV"  "BP17-L-tributo.WAV"
##  [4] "BP18-L-babado.WAV"  "BP18-L-cabido.WAV"  "BP18-L-tributo.WAV"
##  [7] "BP19-L-babado.WAV"  "BP19-L-cabido.WAV"  "BP19-L-tributo.WAV"
## [10] "BP20-L-babado.WAV"  "BP20-L-cabido.WAV"  "BP20-L-tributo.WAV"
## [13] "BP21-L-babado.WAV"  "BP21-L-cabido.WAV"  "BP21-L-tributo.WAV"
testwav = paste0(absdir, mydir[1])
testwav
## [1] "/Users/marissabarlaz/Desktop/FemaleBP/BP17-L-babado.WAV"
testtext = str_replace(testwav, ".WAV", ".TextGrid")
testformant = str_replace(testwav, ".WAV", ".Formant")
testpitch = str_replace(testwav, ".WAV", ".Pitch")
testpitchtier = str_replace(testwav, ".WAV", ".PitchTier")
testint = str_replace(testwav, ".WAV", ".Intensity")
testinttier = str_replace(testwav, ".WAV", ".IntensityTier")
testtable = str_replace(testwav, ".WAV", ".Table")

PraatR

praat( "To Pitch...", arguments=list( 0.001, 75,350), input=testwav, output=testpitch, overwrite=TRUE )
praat( "Down to PitchTier", input=testpitch, output=testpitchtier, overwrite=TRUE, filetype="headerless spreadsheet" )

praat( "To Intensity...", arguments = list(100, 0), input=testwav, output=testint, overwrite=TRUE )
praat( "Down to IntensityTier", input=testint, output=testinttier, overwrite=TRUE, filetype="text" )

praat( "To Formant (burg)...", arguments = list(0.01, 4, 5000, 0.05, 50), input=testwav, output=testformant, overwrite=TRUE )

Dygraphs

Create shorter examples from long audio

#form.test = formant.read(testformant)
tg.test = tg.read(testtext)
pt.test = pt.read(testpitchtier)
it.test = it.read(testinttier)

tg.testmini = tg.cut0(tg.test, tStart = 0, tEnd = 5)
pt.testmini = pt.cut0(pt.test, tStart = 0, tEnd = 5)
it.testmini = it.cut0(it.test, tStart = 0, tEnd = 5)
#mylength = length(form.test$t[form.test$t<=5])
# form.testmini = form.test
# form.testmini$t = form.testmini$t[1:mylength]
# form.testmini$xmax = form.testmini$t[mylength]
# form.testmini$frame = form.test$frame[1:mylength] 
# form.testmini$nx = mylength

# formlist = data.frame(form.test$t, do.call("rbind", form.test$frame)) %>% mutate(frequency = str_replace_all(frequency, "(^[^[:digit:]]+|\\)$)", ""), bandwidth = str_replace_all(bandwidth, "(^[^[:digit:]]+|\\)$)", "")) %>% separate(frequency, into =c("f1", "f2", "f3", "f4", "f5"), sep = ",") %>% separate(bandwidth, into =c("f1_bw", "f2_bw", "f3_bw", "f4_bw", "f5_bw"), sep = ",") %>% mutate_at(.vars = c(4:13), .funs  = "as.numeric")

Create dygraphs

#tg.plot(tg.test, group = "testplot")
#pt.plot(pt.test, group = "testplot")
#it.plot(it.test, group = "testplot")
# formant.plot(form.test, group = "testplot", scaleIntensity = TRUE, drawBandwidth = TRUE)
# tg.plot(tg.testmini, formant = form.testmini)
# tg.plot(tg.testmini, pt = pt.testmini, it = it.testmini)

tg.plot(tg.testmini, group = "testplot2")
pt.plot(pt.testmini, group = "testplot2")
it.plot(it.testmini, group = "testplot2")
# formant.plot(form.testmini, group = "testplot2", scaleIntensity = TRUE, drawBandwidth = TRUE)
#tg.plot(tg.testmini, formant = form.testmini)
tg.plot(tg.testmini, pt = pt.testmini, it = it.testmini)
#plot sound
sndWav <- readWave(testwav)
fs <- sndWav@samp.rate
snd <- sndWav@left / (2^(sndWav@bit-1))
t <- seqM(0, (length(snd)-1)/fs, by = 1/fs)

snddf = data.frame(t, snd) %>% filter(t <=5)
dygraph(snddf, xlab = "Time (sec)", group = "testplot")%>% dyRangeSelector(height = 20)