Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find duration of wav file in r

Tags:

r

wav

I know the equation to find the duration of a wav file is:

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

But I've failed to retrieve all the necessary information to fill this equation in R. Here is an example of what I've come up with:

sound <- readWave(sound.wav) 
sampleRate <- [email protected] #44100
bit <- sound@bit #16

So from the information above I have:

fileLength/(44100*channel*16/8)

The channel will either be 1 or 2, so that I'm not bothered about, but what about the file length? How do I retrieve that in R? Or is there some getDurationWavFile method in some package that I've missed?

Update: I'm using the tuneR library and when I use the str(sound) as suggested it gives me:

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
like image 401
user3593948 Avatar asked May 01 '14 19:05

user3593948


1 Answers

A small adjustment to @gary's answer worked for me:

sound_length <- round(length(sound@left) / [email protected], 2)
like image 79
bill-felix Avatar answered Sep 19 '22 05:09

bill-felix