Exemplo n.º 1
0
    def test_sine_mfcc_time_major(self):

        sine = utils.make_test_sine(2048, 440, 44100)
        audio = AudioBuffer(sine, 44100)
        mfcc = MFCC(hop_size=512, frame_size=1024, time_major=True)
        features = mfcc(audio)

        assert features.shape == (5, 20)
Exemplo n.º 2
0
    def test_sine_wave_fft_power(self):

        bin_freq = 44100. / 1024.
        sine = utils.make_test_sine(1024, bin_freq * 10, 44100)
        audio = AudioBuffer(sine, 44100)
        fft = FFT(output='power')
        features = fft(audio)
        expected = np.zeros(513)
        expected[10] = 512. * 512.

        assert features.shape == (513, )
        assert isinstance(features[0], np.float32)
        np.testing.assert_array_almost_equal(features, expected)
Exemplo n.º 3
0
    def test_sine_wave_fft_magnitude_longer(self):

        bin_freq = 44100. / 4096.
        sine = utils.make_test_sine(4096, bin_freq * 10, 44100)
        audio = AudioBuffer(sine, 44100)
        fft = FFT(output='magnitude')
        features = fft(audio)
        expected = np.zeros(2049)
        expected[10] = 2048.

        assert features.shape == (2049, )
        assert isinstance(features[0], np.float32)
        np.testing.assert_array_almost_equal(features, expected)
Exemplo n.º 4
0
    def test_sine_mfcc_scale(self):

        batch_size = 10
        mfcc = MFCC(hop_size=512, frame_size=1024, scale_axis=(0, 2))
        features = np.zeros((batch_size, 20, 5))

        for i in range(batch_size):
            sine = utils.make_test_sine(2048, 100 + (50 * i), 44100)
            audio = AudioBuffer(sine, 44100)
            features[i] = mfcc(audio)

        assert features.shape == (10, 20, 5)
        scaled = mfcc.fit_scaler(features)
        assert scaled.mean() == pytest.approx(0.)
        assert scaled.std() == pytest.approx(1.)
        np.testing.assert_array_almost_equal(scaled.mean((0, 2)), np.zeros(20))
        np.testing.assert_array_almost_equal(scaled.std((0, 2)), np.ones(20))