INITIAL POST: One of my first times here. I am trying to use a function called split_acoustic_data() in ohun, an R package for processing bioacoustic data. The process involves use of a class of object called a selection table, so I used a subset of a CSV file to build one below. Split_acoustic_data() splits an audio file and its corresponding selection table into smaller pieces, which I am trying to do below with a segment duration of 30 seconds (sgmt.dur = 30). I have read about the function but haven't been able to solve the problem by doing so.
install.packages("devtools")
devtools::install_github("maRce10/warbleR")
#load package
library(warbleR)
# loading some data from dput to make into a selection table
example <-structure(list(sound.files = c("Floodplain_220814_1205.wav",
"Floodplain_220814_1205.wav", "Floodplain_220814_1205.wav"),
selec = 1:3, start = c(4877.33, 4880.5, 4881.5), end = c(4878,
4881.5, 4882)), row.names = c(NA, 3L), class = "data.frame")
# building the selection table itself
exampleselectiontable <- selection_table(example, max.dur = 2, path = NULL, whole.recs = FALSE,
extended = FALSE, confirm.extended = TRUE, mar = 0.1, by.song = NULL,
pb = TRUE, parallel = 1, verbose = TRUE)
# double and triple checking to make sure it's a selection table:
is_selection_table(exampleselectiontable)
class(exampleselectiontable)
# install package
remotes::install_github("maRce10/ohun")
#load package
library(ohun)
# trying to split into 30-second segments:
split_acoustic_data(sgmt.dur = 30, X = exampleselectiontable)
The error I'm getting says "Error: both objects must be of class 'selection_table'". What I have there is a selection table, as near as I can tell, and reading the details of split_acoustic_data I haven't found a candidate for what the "other" selection table might need to be.
Would appreciate any thoughts.
EDIT1 Notes added 9/22/2022 in response to comments: Thanks for your thoughts. I believe 30 seconds should work because I think it is splitting the sound file (and might in doing so split the events, but only as a byproduct). However I moved down to 1 second and got the same error.
I also tried running this with materials from the ohun package including lbh1, lbh2, and lbh_reference (the selection table from the ohun package) and got the same error. I could build my own selection table for it next, but I'm starting to think it is something about the way I'm using the split_acoustic_data function, like it is missing another selection table or something.
Someone helped me find this from warbleR: The error comes from warbler::selection_table line 710, (and is the only ref containing both objects and selection_table in warbleR)that is an if test, if (!is_selection_table(X) | !is_selection_table(Y)). I am going to try to learn how to look through the materials better and see if I can figure out what selection table Y might be referring to.
EDIT2: I read about the function online, therefore I missed the example code. The example code is as follows once you've installed the package ohun:
data("lbh1", "lbh2")
writeWave(lbh1, file.path(tempdir(), "lbh1.wav"))
writeWave(lbh2, file.path(tempdir(), "lbh2.wav"))
#split files in 1 s files
split_acoustic_data(sgmt.dur = 1, path = tempdir())
# Check this folder
tempdir()
I still was unable to use X to create a new data frame (same error message as described below), but I used the above to accomplish the splitting. Wanted to post this in case I confused anyone by missing the example code.
split_acoustic_data
do? Have you checked the help file for the expected input for the function? Have you tried contacting the package author about the error? $\endgroup$