### R summer Club 18 -- May 2018: Introduction to TuneR package ## Install and load packages install.packages("tuneR") # If you don't have the latest version of warbleR: # remove.packages("warbleR") # to be able to install the latest version. # install.packages("warbleR") # do this after you restarted R library(tuneR) library(warbleR) setwd(tempdir()) # create a temporary folder and set the working directory. This folder will be automatically deleted after closing RStudio. This is not necessary, but now you won't save a lot of files on your computer while doing practices. ## Load and save data data(list = c("Phae.long1", "Phae.long2")) # these sound files come with the package warbleR writeWave(Phae.long1, "Phae.long1.wav") # save sound files as .wav writeWave(Phae.long2, "Phae.long2.wav") w1 <- readWave("Phae.long1.wav") # import wave objects in R writeWave(w1, "w1.wav", extensible = FALSE) # Save a Wave object as .wave file. Specify extensible = FALSE to be able to load it in Raven. Non-extensible is more broadly used. Extensible used from multiple channels and generates a larger file. readMP3() # no .mp3 files in R, this function converts .mp3 files to Wave objects ## Wave objects plot(w1) class(w1) # objects are of class "Wave" (S4 class), which require specific functions. w1@samp.rate # use '@' to extract from the Wave object w1.2 <- extractWave(w1, from = 0, to = 2, xunit = "time") # this function is used select a specific part of the .wav file (in time (s) or in samples). The default for xunit is 'samples'. w3 <- bind(w1, w1.2) # to combine different sound files play(w3, player = "cvlc") # use this function to play a sound ## To get acoustics parameters wSpecObject <- periodogram(w1, normalize = TRUE, width = 1024, overlap = 512) # First you need to convert from a Wave object to a "Wspec" object plot(wSpecObject) FF(wSpecObject) # to calculate fundamental frequency