From 02a5fc15fcd43e9917da0c729433a240d0a8ef66 Mon Sep 17 00:00:00 2001 From: Caparrini Date: Sun, 31 Mar 2024 19:18:41 +0200 Subject: [PATCH] Fix: Issue #396, when chroma features can not be computed --- pyAudioAnalysis/ShortTermFeatures.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyAudioAnalysis/ShortTermFeatures.py b/pyAudioAnalysis/ShortTermFeatures.py index 3a3bd4250..2d0760e27 100644 --- a/pyAudioAnalysis/ShortTermFeatures.py +++ b/pyAudioAnalysis/ShortTermFeatures.py @@ -290,8 +290,10 @@ def chroma_features(signal, sampling_rate, num_fft): else: I = np.nonzero(num_chroma > num_chroma.shape[0])[0][0] C = np.zeros((num_chroma.shape[0],)) - C[num_chroma[0:I - 1]] = spec - C /= num_freqs_per_chroma + if I > 1: + # If I <= 1 there are no chroma features that can be extracted + C[num_chroma[0:I - 1]] = spec[num_chroma[0:I - 1]] + C /= num_freqs_per_chroma final_matrix = np.zeros((12, 1)) newD = int(np.ceil(C.shape[0] / 12.0) * 12) C2 = np.zeros((newD,))