I am trying to play a wav file in R using the tuneR package. I don't know the background of the function, but it seems that it tries to save the wav file to a temporary file that it doesn't have access to. I am doing the following:
> # install package if you don't have it
> install.packages("tuneR")
> library(tuneR)
> # load some WAV file
> mySound = readWave("Beethoven.wav");
> # plot it to see if things are working:
> plot(mySound)
> # play the sound
> play(mySound)
sh: /var/folders/qv/sw8_92hn4qg0rb5w40gz9mf40000gn/T//RtmpKU9kVN/tuneRtemp.wav: Permission denied
So clearly it doesn't have access to this folder. How can I either change this folder or give R access to this folder?
I'm working on MacOSX 10.7.5, with RStudio Version 0.98.501.
When using OSX a simple solution is to use the a built-in command line audio player afplay in /usr/bin. (see: http://hints.macworld.com/article.php?story=20081002080543392 )
So use:
setWavPlayer('/usr/bin/afplay')
I made an R package that lets you make your own music a while back. I had this issue trying to get tuneR to work with a mac as well. As you can see here: https://github.com/Dasonk/musicmakeR/blob/master/R/playsong.R my solution (which probably isn't the best) was to do this
if(Sys.info()["sysname"] == "Darwin"){
filename <- tempfile("tuneRtemp", fileext = ".wav")
#on.exit(unlink(filename))
writeWave(song, filename)
system(paste("open -a iTunes", filename))
return(invisible())
}
where song
is the wave data. So my workaround was essentially to write it out to a file that you know you have access to and then directly call the music player using system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With