.wav file length/duration without reading in the file

↘锁芯ラ 提交于 2019-12-12 12:30:55

问题


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:


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)


来源:https://stackoverflow.com/questions/48814730/wav-file-length-duration-without-reading-in-the-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!