mirror of
https://github.com/YuzuZensai/spleeter.git
synced 2026-01-31 04:32:53 +00:00
Updating tests to test for librosa backend
This commit is contained in:
@@ -13,6 +13,7 @@ from os.path import splitext, basename, exists, join
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
import pytest
|
||||
import numpy as np
|
||||
|
||||
from spleeter import SpleeterError
|
||||
from spleeter.audio.adapter import get_default_audio_adapter
|
||||
@@ -21,34 +22,38 @@ from spleeter.separator import Separator
|
||||
TEST_AUDIO_DESCRIPTOR = 'audio_example.mp3'
|
||||
TEST_AUDIO_BASENAME = splitext(basename(TEST_AUDIO_DESCRIPTOR))[0]
|
||||
TEST_CONFIGURATIONS = [
|
||||
('spleeter:2stems', ('vocals', 'accompaniment')),
|
||||
('spleeter:4stems', ('vocals', 'drums', 'bass', 'other')),
|
||||
('spleeter:5stems', ('vocals', 'drums', 'bass', 'piano', 'other'))
|
||||
('spleeter:2stems', ('vocals', 'accompaniment'), 'tensorflow'),
|
||||
('spleeter:4stems', ('vocals', 'drums', 'bass', 'other'), 'tensorflow'),
|
||||
('spleeter:5stems', ('vocals', 'drums', 'bass', 'piano', 'other'), 'tensorflow'),
|
||||
('spleeter:2stems', ('vocals', 'accompaniment'), 'librosa'),
|
||||
('spleeter:4stems', ('vocals', 'drums', 'bass', 'other'), 'librosa'),
|
||||
('spleeter:5stems', ('vocals', 'drums', 'bass', 'piano', 'other'), 'librosa')
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('configuration, instruments', TEST_CONFIGURATIONS)
|
||||
def test_separate(configuration, instruments):
|
||||
@pytest.mark.parametrize('configuration, instruments, backend', TEST_CONFIGURATIONS)
|
||||
def test_separate(configuration, instruments, backend):
|
||||
""" Test separation from raw data. """
|
||||
adapter = get_default_audio_adapter()
|
||||
waveform, _ = adapter.load(TEST_AUDIO_DESCRIPTOR)
|
||||
separator = Separator(configuration)
|
||||
prediction = separator.separate(waveform)
|
||||
separator = Separator(configuration, stft_backend=backend)
|
||||
prediction = separator.separate(waveform, TEST_AUDIO_DESCRIPTOR)
|
||||
assert len(prediction) == len(instruments)
|
||||
for instrument in instruments:
|
||||
assert instrument in prediction
|
||||
for instrument in instruments:
|
||||
track = prediction[instrument]
|
||||
assert not (waveform == track).all()
|
||||
assert waveform.shape == track.shape
|
||||
assert not np.allclose(waveform, track)
|
||||
for compared in instruments:
|
||||
if instrument != compared:
|
||||
assert not (track == prediction[compared]).all()
|
||||
assert not np.allclose(track, prediction[compared])
|
||||
|
||||
|
||||
@pytest.mark.parametrize('configuration, instruments', TEST_CONFIGURATIONS)
|
||||
def test_separate_to_file(configuration, instruments):
|
||||
@pytest.mark.parametrize('configuration, instruments, backend', TEST_CONFIGURATIONS)
|
||||
def test_separate_to_file(configuration, instruments, backend):
|
||||
""" Test file based separation. """
|
||||
separator = Separator(configuration)
|
||||
separator = Separator(configuration, stft_backend=backend)
|
||||
with TemporaryDirectory() as directory:
|
||||
separator.separate_to_file(
|
||||
TEST_AUDIO_DESCRIPTOR,
|
||||
@@ -59,10 +64,10 @@ def test_separate_to_file(configuration, instruments):
|
||||
'{}/{}.wav'.format(TEST_AUDIO_BASENAME, instrument)))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('configuration, instruments', TEST_CONFIGURATIONS)
|
||||
def test_filename_format(configuration, instruments):
|
||||
@pytest.mark.parametrize('configuration, instruments, backend', TEST_CONFIGURATIONS)
|
||||
def test_filename_format(configuration, instruments, backend):
|
||||
""" Test custom filename format. """
|
||||
separator = Separator(configuration)
|
||||
separator = Separator(configuration, stft_backend=backend)
|
||||
with TemporaryDirectory() as directory:
|
||||
separator.separate_to_file(
|
||||
TEST_AUDIO_DESCRIPTOR,
|
||||
@@ -74,7 +79,7 @@ def test_filename_format(configuration, instruments):
|
||||
'export/{}/{}.wav'.format(TEST_AUDIO_BASENAME, instrument)))
|
||||
|
||||
|
||||
def test_filename_confilct():
|
||||
def test_filename_conflict():
|
||||
""" Test error handling with static pattern. """
|
||||
separator = Separator(TEST_CONFIGURATIONS[0][0])
|
||||
with TemporaryDirectory() as directory:
|
||||
|
||||
Reference in New Issue
Block a user