Function to play a sound file.

playsound(sound, volume)

Arguments

sound

the sound file (given as a full path).

volume

the volume (as a percentage between 0 and 100).

Details

The function is used by the package to play sounds. This is done by invoking system commands via the system function. This may or may not work depending on your operating system and configuration.

For Linux, the function uses paplay. For macOS, the function uses afplay. Note that these commands are assumed to be on the user path.

Windows does not provide a simple way to play sound files from the command line by default. To make sounds work under Windows, download the lightweight and open-source mpg123 player from https://www.mpg123.de (click on ‘download’, go to ‘Win32 and Win64 binaries’, choose the link for the 64 bit binary, download the ‘static’ zip file, extract it to some directory on your computer, and then place this directory on your system path; if you do not know how to do this last step, see: https://stackoverflow.com/q/9546324/2615367). Note that the volume cannot be adjusted with this player, so the volume argument is ignored.

For advanced users:

If the sound is not working, but you know what the appropriate command is that will work on your system, you can write your own playsound function (see the code for playsound to use as a template). Then use assignInNamespace("playsound", playsound, ns="chesstrainer") to replace the playsound() function with your own version. Then use the example code below to test if the sound is working.

Value

The function does not return an object.

Author

Wolfgang Viechtbauer (wvb@wvbauer.com)

Examples

# test if the sound is working
if (FALSE) { # \dontrun{
playsound(system.file("sounds", "complete.ogg", package="chesstrainer"), 0.5)
} # }