Hello my R friends, 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? Thank you in advance [[alternative HTML version deleted]]
Google search "playing music with r" for example: https://stackoverflow.com/questions/31782580/how-can-i-play-birthday-music-using-r It can be a starting point Yousri On Tue, Jul 21, 2020 at 2:02 PM Vahid Borji <vahid.borji65 at gmail.com> wrote:> > Hello my R friends, > > 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? > > Thank you in advance > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Hi Vahid, The following command: system("mplayer /home/jim/songs/bimbo_soul.mp3", wait=FALSE,ignore.stdout=TRUE) works fine for me. Of course you'll have to specify a music player and music file that you have... Jim On Wed, Jul 22, 2020 at 4:02 AM Vahid Borji <vahid.borji65 at gmail.com> wrote:> > Hello my R friends, > > 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? > > Thank you in advance > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
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 at stereo srate=ywave at samp.rate play(ywave) Hoping this helps, I remain With best regards, Franklin Bretschneider Dept of Biology Utrecht University f.bretschneider at uu.nl
From the package's DESCRIPTION file found as the first hit to a search with rseek.org using strategy "play mp3 files": Package:?? ? ?tuneR? July 8, 2018 Version:?? ? 1.3.3 Date 2018-07-03 Title:?? ? Analysis of Music and Speech Author:?? ? Uwe Ligges with contributions from Sebastian Krey, Olaf Mersmann, Sarah Schnackenberg, Guillaume Guenard, Andrea Preusser, Anita Thieler, Johanna Mielke and Claus Weihs, as well as code fragments and ideas from the former package 'sound' by Matthias Heymann and functions from 'rastamat' by Daniel P. W. Ellis. The included parts of the libmad MPEG audio decoder library are authored by Underbit Technologies Description:?? ? Analyze music and speech, extract features like MFCCs, handle wave files and their representation in various ways, read mp3, read midi, perform steps of a transcription, ... Also contains functions ported from the 'rastamat' 'Matlab' package. -- David On 7/21/20 11:00 AM, Vahid Borji wrote:> Hello my R friends, > > 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? > > Thank you in advance > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Thie "system" command in R takes the first argument and passes that to the shell in which R is running. 1) I run R in the bash shell under Fedora Linux version 30 2) I have installed "mplayer" as an audio/visual player that can be called from the bash shell 3) The command I pass says "Start the mplayer program using the first argument as the file to process. One method is to find the easiest way to play an audio/visual file on your system and then call it from R using "system". Other ways using R packages have been suggested by other respondents. Jim On Thu, Jul 23, 2020 at 5:26 PM Vahid Borji <vahid.borji65 at gmail.com> wrote:> > Dear Jim, > > Thank you for your answer. > > I have a question for you. > > This is your code: system("mplayer /home/jim/songs/bimbo_soul.mp3", > wait=FALSE,ignore.stdout=TRUE) > > 1. Which part of your code is related to call a music player? > > 2. Which part is related to call a music file? > > I want to do this on my laptop, so I need to understand your code (the answer to the above questions). > > Regards, > Vahid > > > On Wed, Jul 22, 2020 at 1:45 AM Jim Lemon <drjimlemon at gmail.com> wrote: >> >> Hi Vahid, >> The following command: >> >> system("mplayer /home/jim/songs/bimbo_soul.mp3", >> wait=FALSE,ignore.stdout=TRUE) >> >> works fine for me. Of course you'll have to specify a music player and >> music file that you have... >> >> Jim >> >> On Wed, Jul 22, 2020 at 4:02 AM Vahid Borji <vahid.borji65 at gmail.com> wrote: >> > >> > Hello my R friends, >> > >> > 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? >> > >> > Thank you in advance >> > >> > [[alternative HTML version deleted]] >> > >> > ______________________________________________ >> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code.
Dear Vahid, Re:> I have a question regarding the following code: > setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play") # path depends on your R version etc. > > How can I find the corresponding path on my laptop?This line ... setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play") ... is the path on my MacBook Air running Mac OS Mojave. The structure of R on similar computers and OS versions will be the same, but I don't know if you use Windows or Linux. Maybe an R-user working with Windows or Linux can help. Success, Franklin ---- Franklin Bretschneider Dept of Biology Utrecht University f.bretschneider at uu.nl
Dear Vahid, Re:> I have a question regarding the following code: > setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play") # path depends on your R version etc. > > How can I find the corresponding path on my laptop?This line ... setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play") ... is the path on my MacBook Air running Mac OS Mojave. The structure of R on similar computers and OS versions will be the same, but I don't know if you use Windows or Linux. Maybe an R-user working with Windows or Linux can help. Success, Franklin ---- Franklin Bretschneider Dept of Biology Utrecht University f.bretschneider at uu.nl
The R command system.file() tells you where the currently running version of R is located on your machine and your operating system. On the Macintosh it shows> system.file()[1] "/Library/Frameworks/R.framework/Resources/library/base" You don't need to worry about the R version number, as R knows where it is and gives you the location of the currently running version. You can now open a system directory file (Finder on Mac, WindowsExplorer on Windows, etc) and navigate up and down to what you are looking for. Or, within R, you can navigate with .. and more directory statements, thus the example from the original email setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play") # path depends on your R version etc. would be written tmp <- system.file("../../bin/play") and the result is the correct location (if it is there). You will get an empty string if it is not ther, but this will get you started on where to look. then you write setWavPlayer(tmp) # path depends on your R version etc. On Thu, Jul 23, 2020 at 7:21 AM bretschr <bretschr at xs4all.nl> wrote:> > Dear Vahid, > > > Re: > > > I have a question regarding the following code: > > setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play") # path depends on your R version etc. > > > > How can I find the corresponding path on my laptop? > > > This line ... > > setWavPlayer("/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/play") > > ... is the path on my MacBook Air running Mac OS Mojave. > The structure of R on similar computers and OS versions will be the same, but I don't know if you use Windows or Linux. > Maybe an R-user working with Windows or Linux can help. > Success, > > Franklin > ---- > > > > Franklin Bretschneider > Dept of Biology > Utrecht University > f.bretschneider at uu.nl > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.