Deep-Learning-and-Scientific-Computing-with-R-torch icon indicating copy to clipboard operation
Deep-Learning-and-Scientific-Computing-with-R-torch copied to clipboard

Error in tuneR_loader("resources/chaffinch.wav"): could not find function "tuneR_loader"

Open nwstephens opened this issue 2 years ago • 5 comments

For some reason, tuneR_loader on this line in the wavelet code resulted in a could not find function error.

This line failed:

wav <- tuneR_loader("resources/chaffinch.wav")

The solution was to call the tuneR_loader function with ::::

wav <- torchaudio:::tuneR_loader("resources/chaffinch.wav")

nwstephens avatar May 03 '23 00:05 nwstephens

Hi Nathan, thanks for pointing this out!

After the book release, there has been a major refactoring in torchaudio: https://github.com/mlverse/torchaudio/blob/main/NEWS.md#breaking-changes

The only user-visible function is now torchaudio_load().

skeydan avatar May 03 '23 07:05 skeydan

Thanks, but now I'm getting errors with mono. This was run on windows:

image

nwstephens avatar May 03 '23 15:05 nwstephens

I see. That's because mono is from tuneR, and the default (as well as recommended) backend now is av.

You could either switch backends (using the un-exported set_audio_backend()), like so

wav_2chan <- "/tmp/chaffinch.wav"
torchaudio:::set_audio_backend("tuneR")
wav <-torchaudio_load(wav_2chan)
tuneR::mono(wav)

or do the conversion to mono using av, like this:

wav_1chan <- "/tmp/chaffinch_1.wav"
av::av_audio_convert(wav_2chan, channels = 1, output = wav_1chan)
wav <-torchaudio_load(wav_1chan)
attr(wav, "channels")

In both cases, you can then continue with transform_to_tensor().

skeydan avatar May 03 '23 16:05 skeydan

Thank you. That worked on Linux. (Note, I had to install libavfilter-dev to get the second solution to work on Ubuntu). Unfortunately, I get different results for Windows. The code runs as expected, but I get this plot:

image

Instead of this one:

image

nwstephens avatar May 03 '23 23:05 nwstephens

Hm, that is weird. Maybe it is just a matter of scaling. Can you find out at which point the difference in the values is introduced? Is it already present after conversion to single-channel, or after torchaudio_load(), or after transform_to_tensor()? Then, can you provide a sample, so we can see if really it is a scaling effect?

skeydan avatar May 04 '23 08:05 skeydan