pystoi icon indicating copy to clipboard operation
pystoi copied to clipboard

Exception For Small Inputs

Open hovavalon opened this issue 3 years ago • 5 comments

Currently pystoi.stoi doesn't support small inputs, but throws a non indicative error:

In [28]:  pystoi.stoi(np.arange(100), np.arange(100), 32000, extended=False)
---------------------------------------------------------------------------
AxisError                                 Traceback (most recent call last)
<ipython-input-28-3f8d814254e5> in <module>
----> 1 pystoi.stoi(np.arange(100), np.arange(100), 32000, extended=False)

~/venv/py3/lib/python3.7/site-packages/pystoi/stoi.py in stoi(x, y, fs_sig, extended)
     56 
     57     # Remove silent frames
---> 58     x, y = utils.remove_silent_frames(x, y, DYN_RANGE, N_FRAME, int(N_FRAME/2))
     59 
     60     # Take STFT

~/venv/py3/lib/python3.7/site-packages/pystoi/utils.py in remove_silent_frames(x, y, dyn_range, framelen, hop)
    122 
    123     # Compute energies in dB
--> 124     x_energies = 20 * np.log10(np.linalg.norm(x_frames, axis=1) + EPS)
    125 
    126     # Find boolean mask of energies lower than dynamic_range dB

<__array_function__ internals> in norm(*args, **kwargs)

~/venv/py3/lib/python3.7/site-packages/numpy-1.19.2-py3.7-linux-x86_64.egg/numpy/linalg/linalg.py in norm(x, ord, axis, keepdims)
   2559             # special case for speedup
   2560             s = (x.conj() * x).real
-> 2561             return sqrt(add.reduce(s, axis=axis, keepdims=keepdims))
   2562         # None of the str-type keywords for ord ('fro', 'nuc')
   2563         # are valid for vectors

AxisError: axis 1 is out of bounds for array of dimension 1

hovavalon avatar Dec 02 '21 11:12 hovavalon

It doesn't make sense to compute STOI for such short inputs, that's why. But it's true, the error can be improved, would you like to do it?

mpariente avatar Dec 02 '21 12:12 mpariente

I know it doesn't make sense, I did it by accident... I would be glad to implement it, what should be the minimal length in milliseconds of an audio section in order for the stoi to be computed?

hovavalon avatar Dec 02 '21 12:12 hovavalon

I would be glad to implement it

Super cool :tada:

Yes, it's related to the window size used for the computation. Maybe it's mentioned in the paper.

mpariente avatar Dec 02 '21 13:12 mpariente

Hello! A PR was submitted.

hovavalon avatar Dec 28 '21 08:12 hovavalon

Thank you, @hovavalon ! :pray: I'm linking the PR for reference: #24

mpariente avatar Dec 28 '21 09:12 mpariente