Search code examples
rwavslots

How do you assign slots to .wav files in r


Hoping this will be a palm to the forehead for missing something. Using R Consol and I'm trying to analyze .wav files. I've loaded seewave, tuneR, soundecology, warbleR, and many supporting packages. And this is the message I get;

bioacoustics::read_wav("A1.wav", time_exp=1, from=NULL, to=NULL)

Wave Object Number of Samples: 1584000 Duration (seconds): 33 Samplingrate (Hertz): 48000 Channels (Mono/Stereo): Mono PCM (integer format): TRUE Bit (8/16/24/32/64): 24

fspec("A1.wav",channel=left,FFT_size=256,FFT_overlap=0.875, FFT_win="hann",LPF,HPF=0,tlim=NULL,flim=NULL, rotate=FALSE,to_dB=TRUE) Error in slot(wave, "samp.rate") : cannot get a slot ("samp.rate") from an object of type "character" How/where do I assign the slots with this .wav information. Thanks for helping, Laurel


Solution

  • If I read the code in your question correctly, you should probably do:

    myWave <- bioacoustics::read_wav("A1.wav", time_exp=1, from=NULL, to=NULL)
    
    bioacoustics::fspec(myWave, channel=left, FFT_size=256, FFT_overlap=0.875,
                        FFT_win="hann", LPF, HPF=0, tlim=NULL, flim=NULL,
                        rotate=FALSE, to_dB=TRUE)
    

    The error message indicates that you have passed an object of type character (i.e. "A1.wav") to the fspec function, which instead expects a Wave object, as created by bioacoustics::read_wav. The Wave object contains a slot called "samp.rate", so then everything should be fine.