The code as follows can split wav.file but there is a limitation which you need to set up the duration to cut audio files. May I ask if there are any solutions in R that are able to split audio files wherever there is silence?
library(seewave)
#your audio file (using example file from seewave package)
data(tico)
audio <- tico
#the frequency of your audio file
freq <- 22050
# the length and duration of your audio file
totlen <- length(audio)
totsec <- totlen/freq
# the duration that you want to chop the file into
seglen <- 0.5
# defining the break points
breaks <- unique(c(seq(0, totsec, seglen), totsec))
index <- 1:(length(breaks)-1)
# a list of all the segments
lapply(index, function(i) audio[(breaks[i]*freq):(breaks[i+1]*freq)])
# the above final line is the only difference between this code and the
# code provided by @Jean V. Adams
The
seewavepackage contains the functiontimerwhich detects where silence and signal are. Some care is needed to get the threshold, smoothing and minimum duration correct but here's an example.