Beispiel #1
0
def test_get_audio_paths():
    dataset_path = './tests/data'
    dataset = Dataset(dataset_path)
    audio_paths = dataset.get_audio_paths()
    assert audio_paths[0] == './tests/data/audio'
    assert audio_paths[1] == ['./tests/data/audio/original']

    audio_paths = dataset.get_audio_paths(22050)
    assert audio_paths[0] == './tests/data/audio22050'
    assert audio_paths[1] == ['./tests/data/audio22050/original']
Beispiel #2
0
def test_get_audio_paths():
    dataset_path = "./tests/data"
    dataset = Dataset(dataset_path)
    audio_paths = dataset.get_audio_paths()
    assert audio_paths[0] == "./tests/data/audio"
    assert audio_paths[1] == ["./tests/data/audio/original"]

    audio_paths = dataset.get_audio_paths(22050)
    assert audio_paths[0] == "./tests/data/audio22050"
    assert audio_paths[1] == ["./tests/data/audio22050/original"]
Beispiel #3
0
def test_check_sampling_rate():
    dataset_path = './tests/data'
    dataset = Dataset(dataset_path)
    sr = 22050
    audio_path_sr = dataset.get_audio_paths(sr)[1][0]
    _clean(audio_path_sr)
    dataset.change_sampling_rate(sr)
    assert dataset.check_sampling_rate(sr)
Beispiel #4
0
def test_change_sampling_rate(sr):
    dataset_path = './tests/data'
    dataset = Dataset(dataset_path)
    audio_path = dataset.get_audio_paths()[0]
    audio_path_sr = dataset.get_audio_paths(sr)[1][0]
    _clean(audio_path_sr)
    dataset.change_sampling_rate(sr)
    for file_audio in audio_files:
        file_path = os.path.join(audio_path_sr, file_audio)
        file_data, file_sr = sf.read(file_path)
        length_seconds = len(file_data) / float(file_sr)

        file_path_original = os.path.join(audio_path, file_audio)
        file_data_original, file_sr_original = sf.read(file_path_original)
        length_seconds_original = len(file_data_original) / \
            float(file_sr_original)

        assert np.allclose(length_seconds,
                           length_seconds_original,
                           rtol=0.0001,
                           atol=0.0001)

    assert dataset.check_sampling_rate(sr)
Beispiel #5
0
def test_convert_to_wav():
    dataset_path = './tests/data_aiff'
    dataset = Dataset(dataset_path)
    audio_path = dataset.get_audio_paths()[0]
    aiff_files = ['40722-8-0-7.aiff', '147764-4-7-0.aiff', '176787-5-0-0.aiff']
    for wavfile in audio_files:
        wavpath = os.path.join(audio_path, wavfile)
        _clean(wavpath)

    dataset.convert_to_wav()
    for wavfile, aifffile in zip(audio_files, aiff_files):
        wavpath = os.path.join(audio_path, wavfile)
        data, sr = sf.read(wavpath)
        wavpath_orig = os.path.join('./tests/data/audio', wavfile)
        data_orig, sr_orig = sf.read(wavpath_orig)
        assert sr_orig == sr
        assert np.allclose(data_orig, data, rtol=0.0001, atol=0.0001)

        _clean(wavpath)