【发布时间】:2013-12-20 05:08:04
【问题描述】:
我有一个较大的声音文件 (150 MB),我想将其拆分为更易于管理的较小文件,例如 5 分钟音频的文件。显然,最后一段将是
可以使用以下链接下载用于此问题的小示例 .mp3 文件:download.linnrecords.com/test/mp3/recit.aspx。
这是我到目前为止所尝试的。我使用readMP3 从tuneR 导入了数据,并打算使用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 -
否,但对这类问题会很方便。