From 161ebe94c1e2e5e26f945de998294cf1ee58134f Mon Sep 17 00:00:00 2001 From: Alon Hovav Date: Tue, 28 Dec 2021 10:35:55 +0200 Subject: [PATCH] Fixed audio size boundary checks --- pystoi/stoi.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pystoi/stoi.py b/pystoi/stoi.py index e955afb..2a60784 100644 --- a/pystoi/stoi.py +++ b/pystoi/stoi.py @@ -46,7 +46,7 @@ def stoi(x, y, fs_sig, extended=False): IEEE Transactions on Audio, Speech and Language Processing, 2016. """ if x.shape != y.shape: - raise Exception('x and y should have the same length,' + + raise Exception('x and y should have the same length,' 'found {} and {}'.format(x.shape, y.shape)) # Resample is fs_sig is different than fs @@ -54,6 +54,10 @@ def stoi(x, y, fs_sig, extended=False): x = utils.resample_oct(x, FS, fs_sig) y = utils.resample_oct(y, FS, fs_sig) + if min(x.shape[0], y.shape[0]) < N_FRAME: + raise Exception('x and y should at least {} miliseconds long' + .format(int(1000 * float(N_FRAME) / float(FS)))) + # Remove silent frames x, y = utils.remove_silent_frames(x, y, DYN_RANGE, N_FRAME, int(N_FRAME/2)) @@ -65,7 +69,10 @@ def stoi(x, y, fs_sig, extended=False): if x_spec.shape[-1] < N: warnings.warn('Not enough STFT frames to compute intermediate ' 'intelligibility measure after removing silent ' - 'frames. Returning 1e-5. Please check you wav files', + 'frames. At least {} seconds are required, ' + 'but only {} were found. ' + 'Returning 1e-5. Please check you wav files' + .format(((N - 1) * N_FRAME + NFFT) / FS, x.shape[0] / FS), RuntimeWarning) return 1e-5