[R] [External] Re: Playing a music file in R

Henrik Bengtsson henr|k@bengt@@on @end|ng |rom gm@||@com
Fri Jul 24 01:25:31 CEST 2020


FWIW, see also the 'midi' R package
(https://github.com/moodymudskipper/midi).  It's not on CRAN.  /Henrik

On Thu, Jul 23, 2020 at 12:19 PM Rasmus Liland <jral using posteo.no> wrote:
>
> On 2020-07-23 14:19 -0400, Richard M. Heiberger wrote:
> > On Thu, Jul 23, 2020 at 7:21 AM bretschr <bretschr using 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.
> >
> > 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.
>
>
> Hello, I found you can use mpv (and
> mplayer) as well, instead of sox[1].
> There are many ways to install it[1]
> including various ways on mac.
>
>         > system("whereis mpv")
>         mpv: /usr/bin/mpv /etc/mpv /usr/include/mpv /usr/share/mpv /usr/share/man/man1/mpv.1.gz
>         > tuneR::setWavPlayer("/usr/bin/mpv")
>         > w <- tuneR::readWave(filename="rf_07.wav", from=0, to=1e6)
>         > w
>
>         Wave Object
>                 Number of Samples:      1000001
>                 Duration (seconds):     22.68
>                 Samplingrate (Hertz):   44100
>                 Channels (Mono/Stereo): Stereo
>                 PCM (integer format):   TRUE
>                 Bit (8/16/24/32/64):    16
>
>         > tuneR::play(w)
>          (+) Audio --aid=1 (pcm_s16le 2ch 44100Hz)
>         AO: [pulse] 44100Hz stereo 2ch s16
>         A: 00:00:22 / 00:00:22 (98%)
>
>
>         Exiting... (End of file)
>         >
>         > tuneR::setWavPlayer("/usr/bin/play")
>         > tuneR::play(w)
>
>         /tmp/RtmpadTOu6/tuneRtemp.wav:
>
>          File Size: 4.00M     Bit Rate: 1.41M
>           Encoding: Signed PCM
>           Channels: 2 @ 16-bit
>         Samplerate: 44100Hz
>         Replaygain: off
>           Duration: 00:00:22.68
>
>         In:100%  00:00:22.68 [00:00:00.00] Out:1.00M [ -====|====- ] Hd:4.2 Clip:0
>         Done.
>         >
>
>
> Best,
> Rasmus
>
> [1] http://sox.sourceforge.net/
> [1] https://mpv.io/installation/
> ______________________________________________
> R-help using 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.



More information about the R-help mailing list