mirror of
https://github.com/YuzuZensai/spleeter.git
synced 2026-01-06 04:32:43 +00:00
test: add unit test for audio adapter
fix: import issues
This commit is contained in:
@@ -16,7 +16,7 @@ import tensorflow as tf
|
||||
from tensorflow.contrib.signal import stft, hann_window
|
||||
# pylint: enable=import-error
|
||||
|
||||
from ..logging import get_logger
|
||||
from ..utils.logging import get_logger
|
||||
|
||||
__email__ = 'research@deezer.com'
|
||||
__author__ = 'Deezer Research'
|
||||
|
||||
@@ -8,7 +8,7 @@ import numpy as np
|
||||
import tensorflow as tf
|
||||
# pylint: enable=import-error
|
||||
|
||||
from ..tensor import from_float32_to_uint8, from_uint8_to_float32
|
||||
from ..utils.tensor import from_float32_to_uint8, from_uint8_to_float32
|
||||
|
||||
__email__ = 'research@deezer.com'
|
||||
__author__ = 'Deezer Research'
|
||||
|
||||
@@ -16,7 +16,7 @@ import numpy as np
|
||||
# pylint: enable=import-error
|
||||
|
||||
from .adapter import AudioAdapter
|
||||
from ..logging import get_logger
|
||||
from ..utils.logging import get_logger
|
||||
|
||||
__email__ = 'research@deezer.com'
|
||||
__author__ = 'Deezer Research'
|
||||
|
||||
4
tests/__init__.py
Normal file
4
tests/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf8
|
||||
|
||||
""" TO DOCUMENT """
|
||||
77
tests/test_ffmpeg_adapter.py
Normal file
77
tests/test_ffmpeg_adapter.py
Normal file
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf8
|
||||
|
||||
""" Unit testing for audio adapter. """
|
||||
|
||||
__email__ = 'research@deezer.com'
|
||||
__author__ = 'Deezer Research'
|
||||
__license__ = 'MIT License'
|
||||
|
||||
from os.path import join
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
# pylint: disable=import-error
|
||||
from pytest import fixture
|
||||
|
||||
import numpy as np
|
||||
import ffmpeg
|
||||
# pylint: enable=import-error
|
||||
|
||||
from spleeter.audio.adapter import AudioAdapter
|
||||
from spleeter.audio.adapter import get_default_audio_adapter
|
||||
from spleeter.audio.adapter import get_audio_adapter
|
||||
from spleeter.audio.ffmpeg import FFMPEGProcessAudioAdapter
|
||||
|
||||
TEST_AUDIO_DESCRIPTOR = 'audio_example.mp3'
|
||||
TEST_OFFSET = 0
|
||||
TEST_DURATION = 600.
|
||||
TEST_SAMPLE_RATE = 44100
|
||||
|
||||
|
||||
@fixture(scope='session')
|
||||
def adapter():
|
||||
""" Target test audio adapter fixture. """
|
||||
return get_default_audio_adapter()
|
||||
|
||||
|
||||
@fixture(scope='session')
|
||||
def audio_data(adapter):
|
||||
""" Audio data fixture based on sample loading from adapter. """
|
||||
return adapter.load(
|
||||
TEST_AUDIO_DESCRIPTOR,
|
||||
TEST_OFFSET,
|
||||
TEST_DURATION,
|
||||
TEST_SAMPLE_RATE)
|
||||
|
||||
|
||||
def test_default_adapter(adapter):
|
||||
""" Test adapter as default adapter. """
|
||||
assert isinstance(adapter, FFMPEGProcessAudioAdapter)
|
||||
assert adapter is AudioAdapter.DEFAULT
|
||||
|
||||
|
||||
def test_load(audio_data):
|
||||
""" Test audio loading. """
|
||||
waveform, sample_rate = audio_data
|
||||
assert sample_rate == TEST_SAMPLE_RATE
|
||||
assert waveform is not None
|
||||
assert waveform.dtype == np.dtype('float32')
|
||||
assert len(waveform.shape) == 2
|
||||
assert waveform.shape[0] == 479832
|
||||
assert waveform.shape[1] == 2
|
||||
|
||||
|
||||
def test_save(adapter, audio_data):
|
||||
""" Test audio saving. """
|
||||
with TemporaryDirectory() as directory:
|
||||
path = join(directory, 'ffmpeg-save.mp3')
|
||||
adapter.save(
|
||||
path,
|
||||
audio_data[0],
|
||||
audio_data[1])
|
||||
probe = ffmpeg.probe(TEST_AUDIO_DESCRIPTOR)
|
||||
assert len(probe['streams']) == 1
|
||||
stream = probe['streams'][0]
|
||||
assert stream['codec_type'] == 'audio'
|
||||
assert stream['channels'] == 2
|
||||
assert stream['duration'] == '10.919184'
|
||||
Reference in New Issue
Block a user