我有一個很大的聲音文件(150 MB),我想將它分割爲一些更容易管理的大小的較小文件,例如帶有5分鐘音頻的文件。顯然,最後一部分將是< = 5分鐘,沒關係。有沒有辦法輕鬆完成這種任務?將音頻文件分割成任意大小的片段
可以使用此鏈接下載用於此問題的小示例.mp3文件:download.linnrecords.com/test/mp3/recit.aspx。
這是我到目前爲止嘗試過的。我從tuneR
使用readMP3
導入數據,並打算使用cutw
函數,但尚未找到使用它的有效方法。
library(tuneR)
sample<-readMP3("recit.mp3")
# the file is only 9.04 seconds long (44.1 Hz, 16-bit, sterio)
# so, for this example we can cut it into 0.5 second intervals)
subsamp1<-cutw(sample, from=0, to=0.5, output="Wave")
# then I would have to do this for each interval up to:
subsampn<-cutw(sample, from=9, to=9.04, output="Wave")
# where I have to explicitly state the maximum second (i.e. 9.04),
# unless there is a way I don't know of to extract this information.
這種方法是低效的,當間隔相比,在總文件長度變小。另外,sample
是立體聲,但subsamp1
是單聲道的,如果可能,我不希望更改任何有關數據的內容。
在提高效率的方式中,我嘗試了向from
和to
參數輸入矢量,但是出現錯誤(請參閱下文)。儘管它已經有效,但它不是一個特別好的解決方案。任何人都知道使用R來解決這個問題的更優雅的方式?
cutw(subsamp1,from=seq(0,9,0.5),to=c(seq(0.5,9.0,0.5),9.04)
# had to explicitly supply the max second (i.e. 9.04).
# must be a better way to extract the maximum second
Error in wave[a:b, ] : subscript out of bounds
In addition: Warning messages:
1: In if (from > to) stop("'from' cannot be superior to 'to'") :
the condition has length > 1 and only the first element will be used
2: In if (from == 0) { :
the condition has length > 1 and only the first element will be used
3: In a:b : numerical expression has 19 elements: only the first used
你可以看看到'mapply' – Dason
不,但它會b方便這類問題。 – Dason