r - Fastest read WAV -


i trying find length (in seconds) of files (only wav) in directory.

require(tuner) fnam=file.path("dir") filist=list.files(fnam, recursive=true, pattern="wav" ) filist1=paste(fnam, "/", filist, sep="") nfiles=length(filist1)  x=1:nfiles file_len=function(n){   inname=data_phone$filist1[n]   if(file.info(inname)$size!=0){     ywave=readwave(inname)     lengthsec=length(ywave@left)/ywave@samp.rate   } else {     lengthsec=0    } } len_file=unlist(lapply(x,fun=file_len)) 

but works 86k files. maybe there way faster?

you need header this. this:

library("tuner") filist <- list.files("dir", recursive=true, pattern="\\.wav$", full.names = true)  file_len <- function(fil) {   if (file.info(fil)$size != 0) {     wavheader <- readwave(fil, header = true)     wavheader$samples / wavheader$sample.rate   } else {     0   } } len_file <- sapply(filist, file_len) 

i've simplified , tidied code, key change using header = true argument readwave , using $samples , $sample.rate members of list returned.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -