[R] Playing a music file in R
bretschr
bret@chr @end|ng |rom x@4@||@n|
Tue Jul 21 23:39:40 CEST 2020
Hello vahid.borji,
Re:
> How can we call a music file from our laptop (for example from desktop) and
> play it in R? Could you please give me an explicit example by writing
> commands in R. Is it necessary for our music file to be in a specific
> format? If yes, which format it has to be?
Wave files, and probably a few other formata, can be loaded, saved and manupulated with (a.o.) these packages:
library(signal)
library(seewave)
library(tuneR)
In addition, to play a wave file, a small Unix file is necessary, called "play".
It must be attached by the following line:
setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play") # path depends on your R version etc.
Then, a simple script like the following will do:
inname = file.choose()
ywave=readWave(inname)
ster=ywave using stereo
srate=ywave using samp.rate
play(ywave)
Hoping this helps, I remain
With best regards,
Franklin Bretschneider
Dept of Biology
Utrecht University
f.bretschneider using uu.nl
More information about the R-help
mailing list