combiner <- function(path, segments_per_file) {
## Get a list of the wav files
files <- list.files(path = path, pattern = ".wav", full.names = TRUE)
## Split the list of wav files according to the number of files you want to combine at a time
groups <- cumsum(seq_along(files) %% segments_per_file == 1)
file_list <- split(files, groups)
## Loop through the list and use the concat protocol for ffmpeg to combine the files
lapply(seq_along(file_list), function(x) {
a <- tempfile(fileext = ".txt")
writeLines(sprintf("file '%s'", file_list[[x]]), a)
system(sprintf('ffmpeg -f concat -safe 0 -i %s -c copy Group_%s.wav', a, x))
})
}
下面是我将如何使用R和
ffmpeg
来实现这一点。我相信您可以使用bash执行相同类型的循环,但这似乎非常简单:如果您更喜欢使用
sox
,那么循环更简单一些:在R中,如果您希望一次合并60个文件,则可以运行
combiner(path_to_your_wav_files, 60)
请注意,组合文件将位于运行脚本的工作目录中(使用
getwd()
验证其位置)相关问题 更多 >
编程相关推荐