Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception For Small Inputs #23

Open
hovavalon opened this issue Dec 2, 2021 · 5 comments
Open

Exception For Small Inputs #23

hovavalon opened this issue Dec 2, 2021 · 5 comments

Comments

@hovavalon
Copy link

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
@mpariente
Copy link
Owner

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?

@hovavalon
Copy link
Author

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?

@mpariente
Copy link
Owner

I would be glad to implement it

Super cool 🎉

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

@hovavalon
Copy link
Author

hovavalon commented Dec 28, 2021

Hello!
A PR was submitted.

@mpariente
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants