Audio playback in R

Like other R packages that work with audio, soundgen relies on "tuneR" library for audio playback. As the developer of soundgen, I have no direct control over the backend and can only offer general tips. Audio playback may fail initially, depending on your platform and installed software. This is normal and generally fixable, but you may need to experiment and possibly install system dependencies. On Linux or Mac OS, it should be possible to play audio invisibly - without opening a new window. On Windows machines, it seems like only external players like VLC or Audacity do the job, but then a new window pops up every time a sound is played. See the seewave vignette on sound input/output for an in-depth discussion of audio playback in R. Some tips are also available here. Also check ?playme. A quick step-by-step guide is below.

Suggested sequence of actions to try in case audio playback fails (I'm using soundgen::playme() in the examples below, but the same logic applies to the backend function tuneR::play()):

  1. Create a simple sound that you want to play, eg sound = runif(16000) (a second of white noise)
  2. Try to play it with soundgen::playme(sound)
  3. No sound? Try different players with soundgen::playme(sound, player = 'my_favorite_player'), for example:
    • Linux: player = 'play' You may need to install the "vox" library (in the terminal, not R).
    • Mac OS: if the default "afplay" is not working, try VLC or Audacity, eg player = 'vlc'.
    • Windows: again, VLC or Audacity seem to be the safest options. In system settings, choose VTL as the default application that opens audio files, then restart R. Not working? You can try to provide the full path to the executable. Try Sys.which('vlc') to get the path. Still not working? Reinstalling / updating VLC has been known to work.
  4. Still no sound? A tough one. OK, in the long run you will probably want to find a player that works. As a quick fix, though, you can save each generated sound as a .wav file on your hard drive, and then play this audio file from outside R - just navigate to it in your file explorer and open it with whatever you normally use to play / edit audio.
    • When working with the soundgen() function to create sounds, save them directly with soundgen(saveAudio = 'temp.wav')
    • If you already have your sound object, save it with seewave::savewav(sound, f = 16000, filename = 'temp.wav') (saved in the current working directory - check what it is with getwd(), reset with setwd(), set to where the current R script is saved with setwd(dirname(rstudioapi::getActiveDocumentContext()$path)), or provide the full path to where you want to save your audio file).

Demos

Documentation