Closed noamross closed 5 years ago
It may be possible to hack it (you need to pass in something "video" related):
library(av)
library(tuneR)
library(gapminder)
library(ggplot2)
wav = noise()
input = tempfile(fileext = ".wav")
writeWave(wav, input)
makeplot <- function(){
datalist <- split(gapminder, gapminder$year)
lapply(datalist, function(data){
p <- ggplot(data, aes(gdpPercap, lifeExp, size = pop, color = continent)) +
scale_size("population", limits = range(gapminder$pop)) + geom_point() + ylim(20, 90) +
scale_x_log10(limits = range(gapminder$gdpPercap)) + ggtitle(data$year) + theme_classic()
print(p)
})
}
res = av_capture_graphics(makeplot(), output = tempfile(fileext = ".mp3"),
audio = input)
tuneR::readMP3(res)
#>
#> Wave Object
#> Number of Samples: 46080
#> Duration (seconds): 1.04
#> Samplingrate (Hertz): 44100
#> Channels (Mono/Stereo): Mono
#> PCM (integer format): TRUE
#> Bit (8/16/24/32/64): 16
Created on 2019-08-11 by the reprex package (v0.3.0)
The dev version now has av_encode_audio()
which allows you to convert audio from a video/audio file into another audio format.
FYI, the command is now av_audio_convert
.
R has
wav
files readers in the audio and tuneR packages, (simple as wav files are just raw audio samples), and the tuneR package can readmp3
files. However, there is now way to writemp3
or other compressed formats.ffmpeg
allows conversion between audio formats. It would be great if one could convertwav
tomp3
using av. Asffmpeg
allows conversion of raw audio, one could in theory use it to write audio directly to mp3 from a numeric vector and vice versa.