3
3
import scipy .io .wavfile
4
4
from spafe .utils import vis
5
5
from spafe .features .cqcc import cqcc
6
+ from spafe .utils .preprocessing import framing
6
7
from spafe .utils .exceptions import ParameterError
7
8
from spafe .utils .cepstral import normalize_ceps , lifter_ceps
8
9
18
19
@pytest .mark .parametrize ("dct_type" , [1 , 2 , 4 ])
19
20
@pytest .mark .parametrize ("lifter" , [None , 0.7 , - 7 ])
20
21
@pytest .mark .parametrize ("normalize" , [None , "mvn" , "ms" ])
22
+ @pytest .mark .parametrize ("resampling_ratio" , [1.0 , 0.9 , 0.3 ])
21
23
def test_cqcc (
22
24
sig ,
23
25
fs ,
@@ -29,6 +31,7 @@ def test_cqcc(
29
31
dct_type ,
30
32
lifter ,
31
33
normalize ,
34
+ resampling_ratio ,
32
35
):
33
36
"""
34
37
test cqcc features module for the following:
@@ -40,6 +43,9 @@ def test_cqcc(
40
43
- check normalization.
41
44
- check liftering.
42
45
"""
46
+ # get number of frames
47
+ frames , frame_length = framing (sig = sig , fs = fs , win_len = 0.025 , win_hop = 0.01 )
48
+ num_frames = len (frames )
43
49
44
50
# check error for number of filters is smaller than number of cepstrums
45
51
with pytest .raises (ParameterError ):
@@ -50,6 +56,7 @@ def test_cqcc(
50
56
nfft = nfft ,
51
57
low_freq = low_freq ,
52
58
high_freq = fs ,
59
+ resampling_ratio = resampling_ratio ,
53
60
)
54
61
55
62
# compute features
@@ -64,12 +71,17 @@ def test_cqcc(
64
71
dct_type = dct_type ,
65
72
lifter = lifter ,
66
73
normalize = normalize ,
74
+ resampling_ratio = resampling_ratio ,
67
75
)
68
76
69
77
# assert number of returned cepstrum coefficients
70
78
if not cqccs .shape [1 ] == num_ceps :
71
79
raise AssertionError
72
80
81
+ # assert number of returned cepstrum coefficients
82
+ if not cqccs .shape [0 ] == int (num_frames * resampling_ratio ):
83
+ raise AssertionError
84
+
73
85
# check normalize
74
86
if normalize :
75
87
np .testing .assert_array_almost_equal (
@@ -86,6 +98,7 @@ def test_cqcc(
86
98
dct_type = dct_type ,
87
99
lifter = lifter ,
88
100
normalize = None ,
101
+ resampling_ratio = resampling_ratio ,
89
102
),
90
103
normalize ,
91
104
),
@@ -108,6 +121,7 @@ def test_cqcc(
108
121
dct_type = dct_type ,
109
122
lifter = None ,
110
123
normalize = normalize ,
124
+ resampling_ratio = resampling_ratio ,
111
125
),
112
126
lifter ,
113
127
),
0 commit comments