library(warbleR) library(tuneR) # Set the inputs directory dir = "/home/ortion/records/" indir = paste0(dir, 'raw') outdir = paste0(dir, 'exp') # Set name prefix car = "721035" year = 2021 pass = 0 point = "Z2" prefix = paste0("Car", car, "-", year, "-", "Pass", pass, "-", point, "-") # Create the output directory dir.create(outdir) # Create a list of ".WAV" files wav_list=list.files(indir,"*.WAV") # To handle quite frequent crashes in mp32wav function wav_list=list.files(indir, pattern=".wav$") mp3_list=list.files(indir, pattern=".mp3$") while(length(wav_list) 50000) { wav_tmp = readWave(wav_list[j]) dur = duration(wav_tmp) if (dur > 0) { for(k in 1:ceiling(dur/5)) { left_channel_tmp = cutw(channel(wav_tmp,which="left"),from=(k-1)*5,to=min(dur,k*5),output="Wave") left_channel_tmp = normalize(left_channel_tmp,level=0.3) suf = formatC(x = k, width = 3, flag = "0") #create a suffix as 001, 000 savewav(left_channel_tmp,filename=paste0(SplitDir,substr(wav_list[j],1,nchar(wav_list[j])-4),"_",suf,".wav")) if (length(wav_tmp@right) > 0){ right_channel_tmp = cutw(channel(wav_tmp,which="right"),from=(k-1)*5,to=min(dur,k*5),output="Wave",normalize= "16") right_channel_tmp = normalize(right_channel_tmp,level=0.3) savewav(right_channel_tmp,filename = paste0(SplitDir,substr(wav_list[j],1,nchar(wav_list[j])-4),"_",suf,".wav")) } } } } print(paste(j,wav_list[j],dur)) }