How to Play Sounds with tuneR on OS X Macs
(rev. Fall 2007)

Don Byrd

 

On Windows, playing tuneR's Wave objects is no problem: just say "play(aSound)". But on LINUX and Macintoshes running OS X, you must tell R what program to use for playback, and exactly where on your system the program is. This writeup covers only OS X.

We know of three programs that can be used to play tuneR Waves on OS X. By far the best working seems to be a program whose origin is completely unclear; it was sent to us as just "play", but to avoid confusion, we've renamed it to "playRWave". To use it:

  1. Download playRWave_FOR_OSX.zip.

  2. Unzip it; remove playRWave from the resulting folder, and put it in the Audio subfolder of either (a) your top-level Library folder, e.g., MacBook HD/Library/Audio , or (b) the Library folder in your home directory, e.g., MacBook HD/Users/donbyrd/Library/Audio/playRWave. (Actually, it can go almost anywhere, but these locations seems to fits Apple's intentions the best.) The former location is simpler to tell R about, and it will work for all users of the computer. However, computers you have only limited privileges on -- like STC computers at IU -- may not let you put it there.

  3. Add a second parameter to each play statement, like this:
      
    		play(aSound, "/Library/Audio/playRWave")                  # for case (a) above
      
    		play(aSound, "/Users/donbyrd/Library/Audio/playRWave")    # for case (b) above
      
    Or, call setWavPlayer once at the start of every run of R in which you'll be playing Waves, just after the "library(tuneR)" statement, like this:
      
    		library(tuneR)
      
    		setWavPlayer("/Library/Audio/playRWave")                  # for case (a) above
      
    		setWavPlayer("/Users/donbyrd/Library/Audio/playRWave")    # for case (b) above
      
That's all there is to it.

Alternatives?

If playRWave doesn't work for you, the alternatives we know of are Apple's QuickTime Player and the open-source media player VLC. QuickTime Player is preinstalled on every Mac, and its path is nearly always "/Applications/'QuickTime Player.app'/Contents/MacOS/'QuickTime Player'". However, it usually gives a couple of scary-looking error messages every time it's used; you must hit the escape key to get R to continue after using it; and it opens (and leaves open) another QuickTime Player, always called "tuneRtemp.wav", each time it's used. This is all pretty confusing! But then, QuickTime Player wasn't designed to be run from a user-written program.

As for VLC, in our limited tests in early 2007, it seems to behave exactly the same way as QuickTime Player, which is disappointing and somewhat surprising; we'd be interested in reports about it.


Last updated: 7 Sept. 2007
Comments to: donbyrd(at)indiana.edu
Copyright 2007, Donald Byrd

Spring 2007 Music InformaticsSchool of InformaticsIndiana University