iver56 / audiomentations

A Python library for audio data augmentation. Inspired by albumentations. Useful for machine learning.
https://iver56.github.io/audiomentations/
MIT License
1.76k stars 183 forks source link

limiter (with defaults): AssertionError: threshold has to be a float greater than zero. #252

Closed drscotthawley closed 1 year ago

drscotthawley commented 1 year ago

Hi Iver (et al)! I'm really enjoying audiomentations.

One problem I'm having is that the limiter will die with the following message:

  File "/admin/home-shawley/envs/aa/lib/python3.8/site-packages/audiomentations/core/transforms_interface.py", line 84, in __call__
    return self.apply(samples, sample_rate)
  File "/admin/home-shawley/envs/aa/lib/python3.8/site-packages/audiomentations/augmentations/limiter.py", line 122, in apply
    limiter = CyLimiter(
  File "cylimiter.pyx", line 16, in extensions.cylimiter.Limiter.__init__
AssertionError: threshold has to be a float greater than zero.

My usage is that I'm just invoking it with almost all the defaults in place, as

aug  = Limiter(p=1.0)

, and then calling it with

new_audio = aug(audio, sample_rate=48000). 

I'm not sure exactly if there's a problem with the audio that I'm passing in. I'll try to do some more checking on that. In the meantime, any suggestions on how to best prevent this?

drscotthawley commented 1 year ago

after checking on the audio: yea so far it throws that error no matter what sort of numpy array (bounded between -1 and 1) I throw in.

I am using stereo arrays, e.g. audio.shape = 2, 65536]. But according to the docs, Limiter supports stereo, yes?

right now my only solution is to remove Limiter from the list. :-(

iver56 commented 1 year ago

Does it occur for all audios you give it, or just a few specific ones? If possible, please share an audio where it fails

Does the problem go away if you pass threshold_mode="absolute" to the limiter?

iver56 commented 1 year ago

Looking at the code, I am imagine that it will fail on digital silence 🤔 I guess I forgot to test it on that

drscotthawley commented 1 year ago

I hope I'm not feeding it silence but i can check: My code I have before that is automatically set to keep "re-drawing" a new sample of audio until it gets something that's not silence. So if there's silence going into to the limiter that means my other code is failing too. :-/

iver56 commented 1 year ago

I could reproduce the error message you saw by feeding it digital silence. I proposed a patch for that here: https://github.com/iver56/audiomentations/pull/254

Have a look if you want. If digital silence was not the problem, I would be grateful for more information on how to reproduce the bug

drscotthawley commented 1 year ago

Thanks for adding that patch! I will work on this today. ...

iver56 commented 1 year ago

Thanks for adding that patch! I will work on this today. ...

Great! Any interesting findings?

iver56 commented 1 year ago

If the patch didn't fix it, please reopen the issue