简体   繁体   中英

R Language: How to use Specan function on my own wav file?

I am trying to use specan function from warbleR package. I want to pass my own wav file as an argument to the function. I have seen only one example in docs which is not much self explanatory.

wave_file <- readWave("C:/Users/ABC/Downloads/file_example_WAV_1MG.wav", from = 1, to = Inf, units = c("seconds"), header = FALSE, toWaveMC = NULL)
head(wave_file)
mono_file <- mono(wave_file, which = c("both"))
head(mono_file)
auto_file <- autodetec(X = "C:/Users/ABC/Downloads/file_example_WAV_1MG.wav")
head(auto_file)
dataframe <- data.frame(list = c("sound.files", "selec", "start", "end"))
dataframe <- data.frame(wave_file, "abc", 1, Inf)
dataframe

# Existing Example found in R docs
#setwd('C:/Users/ABC/Downloads')
#data1 <- data(list = c("Phae.long1", "Phae.long2", "Phae.long3", "Phae.long4", "selec.table"))
#writeWave(Phae.long1,"Phae.long1.wav")
#writeWave(Phae.long2,"Phae.long2.wav")
#writeWave(Phae.long3,"Phae.long3.wav")
#writeWave(Phae.long4,"Phae.long4.wav")
#writeWave(Phae.long1,"file_example_WAV_1MG.wav")
#writeWave(Phae.long2," ")
#writeWave(Phae.long3,"1")
#writeWave(Phae.long4,"Inf")

getwd()


#file <- specan(X = selec.table, bp = c(0, 22))
#head(file)

file <- specan(X = dataframe, bp = c(0,22))

How to give my own .wav file as argument to the specan function?

Instead of passing the actual wav file to the dataframe, pass the name of that file. So your code should look like this;

dataframe <- data.frame(list = c("sound.files", "selec", "start", "end"))

dataframe <- data.frame("file_example_WAV_1MG.wav", 2, 1, 20)

names(dataframe) <- c("sound.files", "selec", "start", "end")

a <- specan(X=dataframe, bp=c(0,22))

You can then view a . The extracted features will be stored in the dataframe. Make sure your file is stored in the working directory.

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