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()
):
sound = runif(16000)
(a second of white noise)soundgen::playme(sound)
soundgen::playme(sound, player = 'my_favorite_player')
, for example:
player = 'play'
You may need to install the "vox" library (in the terminal, not R). player = 'vlc'
.Sys.which('vlc')
to get the path. Still not working? Reinstalling / updating VLC has been known to work.soundgen()
function to create sounds, save them directly with soundgen(saveAudio = 'temp.wav')
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).