Exemplo n.º 1
0
def test_spectral_extractors():
    audio = AudioStim(join(AUDIO_DIR, 'barber.wav'))
    ext = SpectralCentroidExtractor()
    df = ext.transform(audio).to_df()
    assert df.shape == (1221, 5)
    assert np.isclose(df['onset'][1], 0.04644)
    assert np.isclose(df['duration'][0], 0.04644)
    assert np.isclose(df['spectral_centroid'][0], 1144.98145)

    ext2 = SpectralCentroidExtractor(n_fft=1024, hop_length=256)
    df = ext2.transform(audio).to_df()
    assert df.shape == (2441, 5)
    assert np.isclose(df['onset'][1], 0.02322)
    assert np.isclose(df['duration'][0], 0.02322)
    assert np.isclose(df['spectral_centroid'][0], 866.20176)

    ext = SpectralBandwidthExtractor()
    df = ext.transform(audio).to_df()
    assert df.shape == (1221, 5)
    assert np.isclose(df['spectral_bandwidth'][0], 1172.96090)

    ext = SpectralContrastExtractor(fmin=100.0)
    df = ext.transform(audio).to_df()
    assert df.shape == (1221, 11)
    assert np.isclose(df['spectral_contrast_band_4'][0], 25.637166)

    ext = SpectralRolloffExtractor()
    df = ext.transform(audio).to_df()
    assert df.shape == (1221, 5)
    assert np.isclose(df['spectral_rolloff'][0], 2492.46826)
Exemplo n.º 2
0
def test_spectral_extractors():
    audio = AudioStim(join(AUDIO_DIR, "barber.wav"))
    ext = SpectralCentroidExtractor()
    df = ext.transform(audio).to_df()
    assert df.shape == (4882, 3)
    assert np.isclose(df['onset'][1], 0.01161)
    assert np.isclose(df['duration'][0], 0.01161)
    assert np.isclose(df['spectral_centroid'][0], 817.53095)

    ext2 = SpectralCentroidExtractor(n_fft=1024, hop_length=256)
    df = ext2.transform(audio).to_df()
    assert df.shape == (9763, 3)
    assert np.isclose(df['onset'][1], 0.005805)
    assert np.isclose(df['duration'][0], 0.005805)
    assert np.isclose(df['spectral_centroid'][0], 1492.00515)

    ext = SpectralBandwidthExtractor()
    df = ext.transform(audio).to_df()
    assert df.shape == (4882, 3)
    assert np.isclose(df['spectral_bandwidth'][0], 1056.66227)

    ext = SpectralContrastExtractor()
    df = ext.transform(audio).to_df()
    assert df.shape == (4882, 9)
    assert np.isclose(df['spectral_contrast_band_4'][0], 25.09001)

    ext = SpectralRolloffExtractor()
    df = ext.transform(audio).to_df()
    assert df.shape == (4882, 3)
    assert np.isclose(df['spectral_rolloff'][0], 1550.39063)