From df725b4a64fe42db19c3f57b01f19cc247a29878 Mon Sep 17 00:00:00 2001 From: SuperKogito Date: Fri, 22 Mar 2024 14:57:20 +0100 Subject: [PATCH 1/3] fix cqcc size bug --- spafe/features/cqcc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spafe/features/cqcc.py b/spafe/features/cqcc.py index 6d5f1c8..c902b80 100644 --- a/spafe/features/cqcc.py +++ b/spafe/features/cqcc.py @@ -166,7 +166,7 @@ def cqcc( normalize: Optional[NormalizationType] = None, number_of_octaves: int = 7, number_of_bins_per_octave: int = 24, - resampling_ratio: float = 0.95, + resampling_ratio: float = 1.0, spectral_threshold: float = 0.005, f0: float = 120, q_rate: float = 1.0, @@ -283,7 +283,7 @@ def cqcc( # -> log(.) # handle zeros: if feat is zero, we get problems with log features_no_zero = zero_handling(x=power_spectrum) - log_features = np.log(features_no_zero) + log_features = np.log(features_no_zero.T) # uniform resampling resampled_features = resample( From cfa4503adad1d9312a996ae14b8b3d94f2737693 Mon Sep 17 00:00:00 2001 From: SuperKogito Date: Wed, 29 May 2024 04:08:22 +0200 Subject: [PATCH 2/3] update cqcc tests --- tests/test_features_cqcc.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_features_cqcc.py b/tests/test_features_cqcc.py index 9cdad0d..b2416c1 100644 --- a/tests/test_features_cqcc.py +++ b/tests/test_features_cqcc.py @@ -3,6 +3,7 @@ import scipy.io.wavfile from spafe.utils import vis from spafe.features.cqcc import cqcc +from spafe.utils.preprocessing import framing from spafe.utils.exceptions import ParameterError from spafe.utils.cepstral import normalize_ceps, lifter_ceps @@ -18,6 +19,7 @@ @pytest.mark.parametrize("dct_type", [1, 2, 4]) @pytest.mark.parametrize("lifter", [None, 0.7, -7]) @pytest.mark.parametrize("normalize", [None, "mvn", "ms"]) +@pytest.mark.parametrize("resampling_ratio", [1.0, 0.9, 0.3]) def test_cqcc( sig, fs, @@ -29,6 +31,7 @@ def test_cqcc( dct_type, lifter, normalize, + resampling_ratio, ): """ test cqcc features module for the following: @@ -40,6 +43,9 @@ def test_cqcc( - check normalization. - check liftering. """ + # get number of frames + frames, frame_length = framing(sig=sig, fs=fs, win_len=0.025, win_hop=0.01) + num_frames = len(frames) # check error for number of filters is smaller than number of cepstrums with pytest.raises(ParameterError): @@ -50,6 +56,7 @@ def test_cqcc( nfft=nfft, low_freq=low_freq, high_freq=fs, + resampling_ratio=resampling_ratio, ) # compute features @@ -64,12 +71,17 @@ def test_cqcc( dct_type=dct_type, lifter=lifter, normalize=normalize, + resampling_ratio=resampling_ratio, ) # assert number of returned cepstrum coefficients if not cqccs.shape[1] == num_ceps: raise AssertionError + # assert number of returned cepstrum coefficients + if not cqccs.shape[0] == int(num_frames * resampling_ratio): + raise AssertionError + # check normalize if normalize: np.testing.assert_array_almost_equal( @@ -86,6 +98,7 @@ def test_cqcc( dct_type=dct_type, lifter=lifter, normalize=None, + resampling_ratio=resampling_ratio, ), normalize, ), @@ -108,6 +121,7 @@ def test_cqcc( dct_type=dct_type, lifter=None, normalize=normalize, + resampling_ratio=resampling_ratio, ), lifter, ), From 954e94d974c30f8d8206b37d365ba470614224bc Mon Sep 17 00:00:00 2001 From: SuperKogito Date: Wed, 29 May 2024 04:08:38 +0200 Subject: [PATCH 3/3] update formatting --- build.sh | 0 spafe/fbanks/bark_fbanks.py | 1 + spafe/fbanks/gammatone_fbanks.py | 1 + spafe/fbanks/linear_fbanks.py | 1 + spafe/fbanks/mel_fbanks.py | 1 + spafe/features/bfcc.py | 1 + spafe/features/cqcc.py | 6 ++++-- spafe/features/gfcc.py | 1 + spafe/features/lfcc.py | 1 + spafe/features/lpc.py | 1 + spafe/features/mfcc.py | 1 + spafe/features/msrcc.py | 1 + spafe/features/ngcc.py | 1 + spafe/features/pncc.py | 1 + spafe/features/psrcc.py | 1 + spafe/features/rplp.py | 5 ++--- spafe/utils/cepstral.py | 1 + spafe/utils/converters.py | 1 + spafe/utils/filters.py | 1 + spafe/utils/preprocessing.py | 1 + spafe/utils/spectral.py | 1 + spafe/utils/vis.py | 1 + spafe/version.py | 1 + 23 files changed, 26 insertions(+), 5 deletions(-) mode change 100644 => 100755 build.sh diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 diff --git a/spafe/fbanks/bark_fbanks.py b/spafe/fbanks/bark_fbanks.py index 2154ba5..202dc27 100644 --- a/spafe/fbanks/bark_fbanks.py +++ b/spafe/fbanks/bark_fbanks.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Optional import numpy as np diff --git a/spafe/fbanks/gammatone_fbanks.py b/spafe/fbanks/gammatone_fbanks.py index 0bc2455..cefa2e7 100644 --- a/spafe/fbanks/gammatone_fbanks.py +++ b/spafe/fbanks/gammatone_fbanks.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Optional, Tuple import numpy as np diff --git a/spafe/fbanks/linear_fbanks.py b/spafe/fbanks/linear_fbanks.py index 3057b25..39aa0a5 100644 --- a/spafe/fbanks/linear_fbanks.py +++ b/spafe/fbanks/linear_fbanks.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Optional import numpy as np diff --git a/spafe/fbanks/mel_fbanks.py b/spafe/fbanks/mel_fbanks.py index 22fd376..bb69a78 100644 --- a/spafe/fbanks/mel_fbanks.py +++ b/spafe/fbanks/mel_fbanks.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Optional import numpy as np diff --git a/spafe/features/bfcc.py b/spafe/features/bfcc.py index 8b46364..a40496b 100644 --- a/spafe/features/bfcc.py +++ b/spafe/features/bfcc.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Optional import numpy as np diff --git a/spafe/features/cqcc.py b/spafe/features/cqcc.py index c902b80..ecaef50 100644 --- a/spafe/features/cqcc.py +++ b/spafe/features/cqcc.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Optional import numpy as np @@ -208,7 +209,7 @@ def cqcc( number_of_bins_per_octave (int) : numbers of bins oer occtave. (Default is 24). resampling_ratio (float) : ratio to use for the uniform resampling. - (Default is 0.95). + (Default is 1.00). spectral_threshold (float) : spectral threshold. (Default is 0.005). f0 (float) : fundamental frequency. @@ -217,7 +218,7 @@ def cqcc( (Default is 1.0). Returns: - (numpy.ndarray) : 2d array of BFCC features (num_frames x num_ceps). + (numpy.ndarray) : 2d array of BFCC features (num_frames*resampling_ratio x num_ceps). Tip: - :code:`dct` : can take the following options [1, 2, 3, 4]. @@ -300,4 +301,5 @@ def cqcc( # normalization if normalize: cqccs = normalize_ceps(cqccs, normalize) + return cqccs diff --git a/spafe/features/gfcc.py b/spafe/features/gfcc.py index f19792b..457bc7b 100644 --- a/spafe/features/gfcc.py +++ b/spafe/features/gfcc.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Optional, Tuple import numpy as np diff --git a/spafe/features/lfcc.py b/spafe/features/lfcc.py index 42883cc..2eee763 100644 --- a/spafe/features/lfcc.py +++ b/spafe/features/lfcc.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Optional import numpy as np diff --git a/spafe/features/lpc.py b/spafe/features/lpc.py index da369d7..746d18d 100644 --- a/spafe/features/lpc.py +++ b/spafe/features/lpc.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Optional import numpy as np diff --git a/spafe/features/mfcc.py b/spafe/features/mfcc.py index 6bd1e2d..eea53be 100644 --- a/spafe/features/mfcc.py +++ b/spafe/features/mfcc.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Optional import numpy as np diff --git a/spafe/features/msrcc.py b/spafe/features/msrcc.py index b387fa6..2fa8780 100644 --- a/spafe/features/msrcc.py +++ b/spafe/features/msrcc.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Optional import numpy as np diff --git a/spafe/features/ngcc.py b/spafe/features/ngcc.py index 2d8d086..5f34091 100644 --- a/spafe/features/ngcc.py +++ b/spafe/features/ngcc.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Optional import numpy as np diff --git a/spafe/features/pncc.py b/spafe/features/pncc.py index 49dd305..a283d6b 100644 --- a/spafe/features/pncc.py +++ b/spafe/features/pncc.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Optional import numpy as np diff --git a/spafe/features/psrcc.py b/spafe/features/psrcc.py index 519de5c..1ff9114 100644 --- a/spafe/features/psrcc.py +++ b/spafe/features/psrcc.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Optional import numpy as np diff --git a/spafe/features/rplp.py b/spafe/features/rplp.py index 2f5ca8e..65c9cfd 100644 --- a/spafe/features/rplp.py +++ b/spafe/features/rplp.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Optional import numpy as np @@ -148,9 +149,7 @@ def __rastaplp( # equal loudness pre_emphasis E = lambda w: ((w**2 + 56.8 * 10**6) * w**4) / ( - (w**2 + 6.3 * 10**6) - * (w**2 + 0.38 * 10**9) - * (w**6 + 9.58 * 10**26) + (w**2 + 6.3 * 10**6) * (w**2 + 0.38 * 10**9) * (w**6 + 9.58 * 10**26) ) Y = [E(w) for w in auditory_spectrum] diff --git a/spafe/utils/cepstral.py b/spafe/utils/cepstral.py index 621b84b..e4eedac 100644 --- a/spafe/utils/cepstral.py +++ b/spafe/utils/cepstral.py @@ -6,6 +6,7 @@ For a copy, see . """ + import numpy as np from scipy.signal import lfilter from typing_extensions import Literal diff --git a/spafe/utils/converters.py b/spafe/utils/converters.py index 73381c0..61eb5c5 100644 --- a/spafe/utils/converters.py +++ b/spafe/utils/converters.py @@ -6,6 +6,7 @@ For a copy, see . """ + import numpy as np from typing_extensions import Literal diff --git a/spafe/utils/filters.py b/spafe/utils/filters.py index 4390a71..65ddd94 100644 --- a/spafe/utils/filters.py +++ b/spafe/utils/filters.py @@ -6,6 +6,7 @@ For a copy, see . """ + import numpy as np from scipy import signal from typing_extensions import Literal diff --git a/spafe/utils/preprocessing.py b/spafe/utils/preprocessing.py index b5bd231..9989c73 100644 --- a/spafe/utils/preprocessing.py +++ b/spafe/utils/preprocessing.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import Tuple import numpy as np diff --git a/spafe/utils/spectral.py b/spafe/utils/spectral.py index a68a51a..e14e19b 100644 --- a/spafe/utils/spectral.py +++ b/spafe/utils/spectral.py @@ -6,6 +6,7 @@ For a copy, see . """ + from typing import List import numpy as np diff --git a/spafe/utils/vis.py b/spafe/utils/vis.py index c2bbf73..6debcdf 100644 --- a/spafe/utils/vis.py +++ b/spafe/utils/vis.py @@ -6,6 +6,7 @@ For a copy, see . """ + import numpy as np from spafe.utils.converters import hz2mel, hz2bark, hz2erb diff --git a/spafe/version.py b/spafe/version.py index fa18d2a..53c9a1a 100644 --- a/spafe/version.py +++ b/spafe/version.py @@ -6,4 +6,5 @@ For a copy, see . """ + __version__ = "0.3.2"