r - 在r中查找wav文件的持续时间

标签 r wav

我知道找到 wav 文件持续时间的等式是:

fileLength/(sampleRate*channel*bits per sample/8)

但是我未能检索到所有必要的信息来填充 R 中的这个等式。
这是我想出的一个例子:
sound <- readWave(sound.wav) 
sampleRate <- sound@samp.rate #44100
bit <- sound@bit #16

所以从上面的信息我有:
fileLength/(44100*channel*16/8)

channel 将是 1 或 2,这样我就不用担心了,但是文件长度呢?我如何在 R 中检索它?或者在我错过的某个包中是否有一些 getDurationWavFile 方法?

更新:
我正在使用 tuneR 库,当我按照建议使用 str(sound) 时,它给了我:
Formal class 'Wave' [package "tuneR"] with 6 slots
  ..@ left     : int [1:132301] 0 3290 6514 9605 12502 15145 17482 19464 21052 22213 ...
  ..@ right    : num(0) 
  ..@ stereo   : logi FALSE
  ..@ samp.rate: int 44100
  ..@ bit      : int 16
  ..@ pcm      : logi TRUE

最佳答案

对@gary 的回答的小调整对我有用:

sound_length <- round(length(sound@left) / sound@samp.rate, 2)

关于r - 在r中查找wav文件的持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23415036/

相关文章:

r - 在 data.table 中动态创建新列

r - 以编程方式构建公式而无需字符串操作

audio - ffmpeg - 制作干净的 WAV 文件

javascript - 如何在 jPlayer 中使用 .wav 音频文件

java - 通过 AudioTrack 多次播放 WAV 文件

r - 提取R中字符串中的最后一个单词

html - 如何使用 rmarkdown 在 pdf 中呈现 DT::datatables?

r - 按顺序从字符串中提取匹配的单词

python - 从字节创建 .wav 文件

python - 如何在显示文本的同时在 Python 2.6.6 中播放音频?