有没有办法在 R 中读取 .WMA 声音文件,或者版权限制不允许这样做?
最终目标是将其转换为另一种格式(MP3/WAV)
R 音频包以一种或另一种方式使用ffmpeg转换器。
请查看以下选项:
system
函数调用将 WMA 转换为 MP3 文件格式;ffmpeg
wrapper 包进行简单的音频转换。然而,它是面向 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)