20 분 길이의 파일을 만들기 위해 결합해야하는 20 초 .wav 파일이 있습니다. 나는 그것들을 날짜 수정 순서로 가지고 있지만 특정한 방식으로 이름을 지정하지 않았습니다 (파일은 AudioMoth 녹음에서 직접 왔으며 필요한 경우 이름을 바꿀 수 있습니다). 나는 그것들을 결합하는 방법을 살펴 보았고 sox 또는 ffmpeg를 사용할 수 있지만 약 15000 개의 파일이 있으므로 수동으로 너무 오래 걸립니다. 루프로 가능할 수 있기를 바랍니다. bash를 통해 가능합니까 아니면 python 또는 R로 가능합니까?
R 및 ffmpeg
. bash로 동일한 유형의 루핑을 수행 할 수 있다고 확신하지만 이것은 매우 간단 해 보였습니다.
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))
})
}
을 사용하고 싶다면 sox
루프가 좀 더 간단합니다.
combiner <- function(path, segments_per_file) {
files <- list.files(path = path, pattern = ".wav", full.names = TRUE)
groups <- cumsum(seq_along(files) %% segments_per_file == 1)
file_list <- split(files, groups)
lapply(seq_along(file_list), function(x) {
system(sprintf("sox %s Group_%s.wav", paste(file_list[[x]], collapse = " "), x))
})
}
R combiner(path_to_your_wav_files, 60)
에서 한 번에 60 개의 파일을 결합하려면 실행 합니다.
결합 된 파일은 스크립트를 실행하는 작업 디렉토리에 있습니다 ( getwd()
위치 확인에 사용 ).
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다