Yellow
Yellow

Reputation: 3966

"Permission denied" when playing WAV file

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.

Upvotes: 9

Views: 3203

Answers (2)

Pisca46
Pisca46

Reputation: 914

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')

Upvotes: 13

Dason
Dason

Reputation: 61973

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.

Upvotes: 1

Related Questions