我有一个很大的声音文件(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