.wav文件长度/持续时间,无需读取文件 [英] .wav file length/duration without reading in the file

查看:339
本文介绍了.wav文件长度/持续时间,无需读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以提取有关.wav文件长度/持续时间的信息,而不必在R中读取文件?我有成千上万个这样的文件,如果我必须仔细阅读每个文件来查找其持续时间,则将花费很长时间. Windows File Explorer为您提供了打开Length(长度)字段的选项,您可以看到文件的持续时间,但是有没有办法提取该信息以便在R中使用?

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?

这是我尝试并要避免做的事情,因为在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)

推荐答案

您可以使用tuneR包中带有header=TRUE的rel ="noreferrer"> readWave 函数.这只会显示文件的元数据,而不是整个文件.

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)

这篇关于.wav文件长度/持续时间,无需读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆