Hi Hans-Jörg,

This is getting close.

Here is what I did:

You offered two solutions.

(1) Using Quicktime:
 > require(sound)
Loading required package: sound
Warning messages:
1: In findWavPlayer() : No standard wav player known for your system.

2: In setWavPlayer() :
   To play sounds you need to select a wav file player first.
For more information type '?setWavPlayer'.

 > setWavPlayer('open -a \"QuickTime Player.app\"')
[1] "WAV file player 'open -a \"QuickTime Player.app\"' linked  
successfully."
 > myplay <- function(s, ...) {
+ f <- paste(tempdir(), "/Temp_Sound.wav", sep='')
+ if (file.exists(f)) {file.remove(f)}
+ saveSample(s, f)
+ play(f, ...)
+ }
 > (s <- Sine(440,1,channels=2)  # stereo sine wave)
type      : stereo
rate      : 44100 samples / second
quality   : 16 bits / sample
length    : 44100 samples
R memory  : 352800 bytes
HD memory : 176444 bytes
duration  : 1 second
 > myplay(s, stay=TRUE)

This opened QuickTime Player and loaded Temp_Sound.wav. However, I had  
to click on the play button to hear it.

(2) Using the terminal-callable 'play' program.
I downloaded it from http://www.hieper.nl/html/play.html and installed  
it and then checked its availability:
% which play
/usr/local/bin/play

 > setWavPlayer('play')
[1] "WAV file player 'play' linked successfully."
 > myplay(s, stay=TRUE)

Success!!

But

 > play(s)

works as well!
_____________________________
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS:     P.O.Box 400400    Charlottesville, VA 22904-4400
Parcels:    Room 102        Gilmer Hall
         McCormick Road    Charlottesville, VA 22903
Office:    B011    +1-434-982-4729
Lab:        B019    +1-434-982-4751
Fax:        +1-434-982-4766
WWW:    http://www.people.virginia.edu/~mk9y/




On Aug 27, 2008, at 3:30 AM, Hans-Jörg Bibiko wrote:

>
> On 27.08.2008, at 09:13, Hans-Jörg Bibiko wrote:
>> first setWavPlayer() expects an UNIX shell command. To open it with 
>> e.g. QuickTime one should use this:
>>
>> setWavPlayer('open -a \"QuickTime Player.app\"')
>>
>> [Ignore the error message]
>>
>> Then the tricky point is that QuickTime cannot open temp files  
>> written by the play() function (?maybe access rights; or the sound  
>> lib is written with Windows-like paths?)
>>
>> Thus I wrote my own play() function
>>
>> myplay <- function(s, ...) {
>> f <- paste(tempdir(), "/Temp_Sound.wav", sep='')
>> if (file.exists(f)) {file.remove(f)}
>> saveSample(s, f)
>> play(f, ...)
>> }
>
> Stop. I've just read the source code. On Mac you should write:
>
> setWavPlayer('open -a \"QuickTime Player.app\"')
> play(s, stay=TRUE)
>
> If stay = FALSE the temp file will be deleted immediately after  
> creation (?)
>
> BTW the error message after setWavPlayer results by the issue that  
> the test wav file is in some sense corrupt.
> Furthermore findWavPlayer() is not up-to-date, thus it couldn't find 
> an adequate player for Leopard ;)
>
> I will contact the maintainer.
>
>
> --Hans


        [[alternative HTML version deleted]]

_______________________________________________
R-SIG-Mac mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-mac

Reply via email to