.wav file length/duration without reading in the f

2019-07-06 22:36发布

Is there a way to extract the information about .wav file length/duration without having to read in the file in R? I have thousands of those files and it would take a long time if I had to read in every single one to find its duration. Windows File Explorer gives you and option to turn on the Length field and you can see the file duration, but is there a way to extract that information to be able to use in in R?

This is what I tried and would like to avoid doing since reading in tens of thousands of audio files in R will take a long time:

library(tuneR)
audio<-readWave("AudioFile.wav")
round(length(audio@left) / audio@samp.rate, 2)

1条回答
成全新的幸福
2楼-- · 2019-07-06 23:05

You can use the readWave function from the tuneR package with header=TRUE. This will only head the metadata of the file and not the entire file.

library(tuneR)
audio<-readWave("AudioFile.wav", header=TRUE)
round(audio$samples / audio$sample.rate, 2)
查看更多
登录 后发表回答