简体   繁体   中英

How to load sound files and data in R for bioacoustic analysis (MonitoR)?

I am trying to follow this bioacoustics in R guide to help me run analysis on some frog chirps. I am also looking at this MonitoR guide as they're trying to accomplish the same thing (using templates to run against sound files).

As I have over 30,000 frog sound files of about 5 MB each, I've created a "dummy" folder with 20 random frog sound files in it and 5 template files. I figured this would make things quicker and once I had my code fully working I would tweak the folder names.

I am working in R Studio and the sound files are WAV ones.

I have loaded MonitoR and WarbleR using library(monitoR, warbleR) and I think that has successfully loaded them.

Then I have set my working directory to that "dummy" folder with the 20 frog files and 5 chirp template files. I know that one has worked as when I call up list.files() they all appear.

> list.files()
 [1] "frog1.WAV"          "frog10.WAV"         "frog11.WAV"        
 [4] "frog12.WAV"         "frog13.WAV"         "frog14.WAV"        
 [7] "frog15.WAV"         "frog16.WAV"         "frog17.WAV"        
[10] "frog18.WAV"         "frog19.WAV"         "frog2.WAV"         
[13] "frog20.WAV"         "frog3.WAV"          "frog4.WAV"         
[16] "frog5.WAV"          "frog6.WAV"          "frog7.WAV"         
[19] "frog8.WAV"          "frog9.WAV"          "template_test1.WAV"
[22] "template_test2.WAV" "template_test3.WAV" "template_test4.WAV"
[25] "template_test5.WAV"

It is the second step of the first guide that I keep getting error messages on no matter how I try and tweak it.

Step 1 has this:

x<-c("warbleR", "monitoR")

That bit I understand as loading the packages, though I don't know what x and c are doing there...

 if(.y %in% installed,packages()[."Package"]) install,packages(y) require(y. character.only = T) })

I have no idea what that bit does... but including it or excluding it makes no difference to the error messages in the next step.

Step 2 is creating templates and where I am getting stuck:

The guide says: # load sound files and data

data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4", "selec.table"))

I am unsure what the selec.table bit of the code does, but again, including or excluding it makes no difference to the error messages.

My attempted code is:

data(list = c("template_test1", "template_test2", "template_test3", "template_test4", "template_test5", "selec.table"))

and it throws up the following errors:

Warning messages: 1: In data(list = c("template_test1", "template_test2", "template_test3", : data set 'template_test1' not found 2: In data(list = c("template_test1", "template_test2", "template_test3", : data set 'template_test2' not found 3: In data(list = c("template_test1", "template_test2", "template_test3", : data set 'template_test3' not found 4: In data(list = c("template_test1", "template_test2", "template_test3", : data set 'template_test4' not found 5: In data(list = c("template_test1", "template_test2", "template_test3", : data set 'template_test5' not found

I've tried steps suggested in both guides (with no success) and looking online for where I am going wrong, but I'm afraid I'm stumped. I've got a long road in R ahead of me for analysing this data set so any help anyone reading this has to give is greatly appreciated. Thank-you.

I think that's the idea, though it takes forever to run on my laptop:

library(monitoR)
library(tuneR)

file1 <- "Phae.long1.wav"
file2 <- "Phae.long2.wav"
file3 <- "Phae.long3.wav"
file4 <- "Phae.long4.wav"

viewSpec(file1)

wct1 <- makeCorTemplate(file1, 
                        t.lim=c(0, 1.0),
                        wl = 300,ovlp=90,
                        frq.lim=c(0.1, 11), dens=1, name="file1")
wct2 <- makeCorTemplate(file2, 
                        t.lim=c(0, 1.0),
                        wl = 300,ovlp=90,
                        frq.lim=c(0.1, 11), dens=1, name="file2")
wct3 <- makeCorTemplate(file3, 
                        t.lim=c(0, 1.0),
                        wl = 300,ovlp=90,
                        frq.lim=c(0.1, 11), dens=1, name="file3")
wct4 <- makeCorTemplate(file4, 
                        t.lim=c(0, 1.0),
                        wl = 300,ovlp=90,
                        frq.lim=c(0.1, 11), dens=1, name="file4")

ctemps <- combineCorTemplates(wct1, wct2, wct3, wct4)

audio <- readWave("mybigfile.wav")
audio <- changeSampRate(wchange = audio, sr.new = 22500)

cscores <- corMatch(survey = audio, templates = ctemps, write.wav = T)
cdetects <- findPeaks(cscores)
getDetections(cdetects)
plot(cdetects)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM