Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Permission denied" when playing WAV file

Tags:

macos

r

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.

like image 430
Yellow Avatar asked Apr 26 '14 11:04

Yellow


2 Answers

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')
like image 99
Pisca46 Avatar answered Nov 06 '22 23:11

Pisca46


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.

like image 1
Dason Avatar answered Nov 06 '22 23:11

Dason