有没有办法读取R中的.WMA声音文件,或者版权限制不允许这样做?
最终目的是将其转换为另一种格式(MP3 / WAV)
答案 0 :(得分:1)
R音频包以一种或另一种方式使用ffmpeg转换器。
请查看以下选项:
system
函数调用; ffmpeg
包装程序包进行简单的音频转换。但是它是面向Linux的,可以轻松转换为与Windows兼容的版本。请参阅下面的代码2:
# install.packages("devtools")
# library(devtools)
# install_github("pmur002/ffmpeg")
library(ffmpeg)
# set path to your ffmpeg.exe file
ffmpeg_path <- "C:\\<Path to ffmpeg>\\ffmpeg-20180906-70a7087-win64-static\\bin\\ffmpeg.exe"
ffmpeg_win <- function (inputs, outputs, filters = NULL, overwrite = FALSE,
wait = TRUE, echo = FALSE) {
if (!is.null(filters)) {
stop("Filters are currently unsupported")
}
if (inherits(inputs, "FFmpeg_input")) {
inputs <- list(inputs)
}
if (inherits(outputs, "FFmpeg_output")) {
outputs <- list(outputs)
}
options <- ""
if (overwrite) {
options <- paste0(options, "-y ")
}
cmd <- paste(ffmpeg_path, options, do.call(paste, inputs), do.call(paste,
outputs))
system(cmd, wait = wait)
if (echo) {
cat(cmd, "\n")
}
}
# just copy to your working directory required file, here is for example "mellow.wma"
ffmpeg_win(fileInput("mellow.wma"), fileOutput("mellow.mp3"), echo = TRUE)