|
|
@ -4,24 +4,18 @@ import itertools
|
|
|
|
import tarfile
|
|
|
|
import tarfile
|
|
|
|
import unittest
|
|
|
|
import unittest
|
|
|
|
from pathlib import Path
|
|
|
|
from pathlib import Path
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
from parameterized import parameterized
|
|
|
|
from parameterized import parameterized
|
|
|
|
|
|
|
|
|
|
|
|
from paddlespeech.audio import sox_effects
|
|
|
|
from paddlespeech.audio import sox_effects
|
|
|
|
from paddlespeech.audio._internal import module_utils as _mod_utils
|
|
|
|
from tests.unit.common_utils import get_sinusoid
|
|
|
|
from tests.unit.common_utils import (
|
|
|
|
from tests.unit.common_utils import get_wav_data
|
|
|
|
get_sinusoid,
|
|
|
|
from tests.unit.common_utils import load_effects_params
|
|
|
|
get_wav_data,
|
|
|
|
from tests.unit.common_utils import load_wav
|
|
|
|
load_wav,
|
|
|
|
from tests.unit.common_utils import save_wav
|
|
|
|
save_wav,
|
|
|
|
from tests.unit.common_utils import sox_utils
|
|
|
|
sox_utils,
|
|
|
|
from tests.unit.common_utils import TempDirMixin
|
|
|
|
TempDirMixin,
|
|
|
|
|
|
|
|
name_func,
|
|
|
|
|
|
|
|
load_effects_params
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _mod_utils.is_module_available("requests"):
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestSoxEffects(unittest.TestCase):
|
|
|
|
class TestSoxEffects(unittest.TestCase):
|
|
|
@ -35,20 +29,24 @@ class TestSoxEffectsTensor(TempDirMixin, unittest.TestCase):
|
|
|
|
"""Test suite for `apply_effects_tensor` function"""
|
|
|
|
"""Test suite for `apply_effects_tensor` function"""
|
|
|
|
|
|
|
|
|
|
|
|
@parameterized.expand(
|
|
|
|
@parameterized.expand(
|
|
|
|
list(itertools.product(["float32", "int32"], [8000, 16000], [1, 2, 4, 8], [True, False])),
|
|
|
|
list(
|
|
|
|
)
|
|
|
|
itertools.product(["float32", "int32"], [8000, 16000], [1, 2, 4, 8],
|
|
|
|
def test_apply_no_effect(self, dtype, sample_rate, num_channels, channels_first):
|
|
|
|
[True, False])), )
|
|
|
|
|
|
|
|
def test_apply_no_effect(self, dtype, sample_rate, num_channels,
|
|
|
|
|
|
|
|
channels_first):
|
|
|
|
"""`apply_effects_tensor` without effects should return identical data as input"""
|
|
|
|
"""`apply_effects_tensor` without effects should return identical data as input"""
|
|
|
|
original = get_wav_data(dtype, num_channels, channels_first=channels_first)
|
|
|
|
original = get_wav_data(
|
|
|
|
|
|
|
|
dtype, num_channels, channels_first=channels_first)
|
|
|
|
expected = original.clone()
|
|
|
|
expected = original.clone()
|
|
|
|
|
|
|
|
|
|
|
|
found, output_sample_rate = sox_effects.apply_effects_tensor(expected, sample_rate, [], channels_first)
|
|
|
|
found, output_sample_rate = sox_effects.apply_effects_tensor(
|
|
|
|
|
|
|
|
expected, sample_rate, [], channels_first)
|
|
|
|
|
|
|
|
|
|
|
|
assert (output_sample_rate == sample_rate)
|
|
|
|
assert (output_sample_rate == sample_rate)
|
|
|
|
# SoxEffect should not alter the input Tensor object
|
|
|
|
# SoxEffect should not alter the input Tensor object
|
|
|
|
#self.assertEqual(original, expected)
|
|
|
|
#self.assertEqual(original, expected)
|
|
|
|
np.testing.assert_array_almost_equal(original.numpy(), expected.numpy())
|
|
|
|
np.testing.assert_array_almost_equal(original.numpy(), expected.numpy())
|
|
|
|
|
|
|
|
|
|
|
|
# SoxEffect should not return the same Tensor object
|
|
|
|
# SoxEffect should not return the same Tensor object
|
|
|
|
assert expected is not found
|
|
|
|
assert expected is not found
|
|
|
|
# Returned Tensor should equal to the input Tensor
|
|
|
|
# Returned Tensor should equal to the input Tensor
|
|
|
@ -69,12 +67,18 @@ class TestSoxEffectsTensor(TempDirMixin, unittest.TestCase):
|
|
|
|
input_path = self.get_temp_path("input.wav")
|
|
|
|
input_path = self.get_temp_path("input.wav")
|
|
|
|
reference_path = self.get_temp_path("reference.wav")
|
|
|
|
reference_path = self.get_temp_path("reference.wav")
|
|
|
|
|
|
|
|
|
|
|
|
original = get_sinusoid(frequency=800, sample_rate=input_sr, n_channels=num_channels, dtype="float32")
|
|
|
|
original = get_sinusoid(
|
|
|
|
|
|
|
|
frequency=800,
|
|
|
|
|
|
|
|
sample_rate=input_sr,
|
|
|
|
|
|
|
|
n_channels=num_channels,
|
|
|
|
|
|
|
|
dtype="float32")
|
|
|
|
save_wav(input_path, original, input_sr)
|
|
|
|
save_wav(input_path, original, input_sr)
|
|
|
|
sox_utils.run_sox_effect(input_path, reference_path, effects, output_sample_rate=output_sr)
|
|
|
|
sox_utils.run_sox_effect(
|
|
|
|
|
|
|
|
input_path, reference_path, effects, output_sample_rate=output_sr)
|
|
|
|
|
|
|
|
|
|
|
|
expected, expected_sr = load_wav(reference_path)
|
|
|
|
expected, expected_sr = load_wav(reference_path)
|
|
|
|
found, sr = sox_effects.apply_effects_tensor(original, input_sr, effects)
|
|
|
|
found, sr = sox_effects.apply_effects_tensor(original, input_sr,
|
|
|
|
|
|
|
|
effects)
|
|
|
|
|
|
|
|
|
|
|
|
assert sr == expected_sr
|
|
|
|
assert sr == expected_sr
|
|
|
|
#self.assertEqual(expected, found)
|
|
|
|
#self.assertEqual(expected, found)
|
|
|
@ -90,20 +94,19 @@ class TestSoxEffectsFile(TempDirMixin, unittest.TestCase):
|
|
|
|
["float32", "int32"],
|
|
|
|
["float32", "int32"],
|
|
|
|
[8000, 16000],
|
|
|
|
[8000, 16000],
|
|
|
|
[1, 2, 4, 8],
|
|
|
|
[1, 2, 4, 8],
|
|
|
|
[False, True],
|
|
|
|
[False, True], )),
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
#name_func=name_func,
|
|
|
|
#name_func=name_func,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
def test_apply_no_effect(self, dtype, sample_rate, num_channels, channels_first):
|
|
|
|
def test_apply_no_effect(self, dtype, sample_rate, num_channels,
|
|
|
|
|
|
|
|
channels_first):
|
|
|
|
"""`apply_effects_file` without effects should return identical data as input"""
|
|
|
|
"""`apply_effects_file` without effects should return identical data as input"""
|
|
|
|
path = self.get_temp_path("input.wav")
|
|
|
|
path = self.get_temp_path("input.wav")
|
|
|
|
expected = get_wav_data(dtype, num_channels, channels_first=channels_first)
|
|
|
|
expected = get_wav_data(
|
|
|
|
|
|
|
|
dtype, num_channels, channels_first=channels_first)
|
|
|
|
save_wav(path, expected, sample_rate, channels_first=channels_first)
|
|
|
|
save_wav(path, expected, sample_rate, channels_first=channels_first)
|
|
|
|
|
|
|
|
|
|
|
|
found, output_sample_rate = sox_effects.apply_effects_file(
|
|
|
|
found, output_sample_rate = sox_effects.apply_effects_file(
|
|
|
|
path, [], normalize=False, channels_first=channels_first
|
|
|
|
path, [], normalize=False, channels_first=channels_first)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert output_sample_rate == sample_rate
|
|
|
|
assert output_sample_rate == sample_rate
|
|
|
|
#self.assertEqual(expected, found)
|
|
|
|
#self.assertEqual(expected, found)
|
|
|
@ -126,16 +129,17 @@ class TestSoxEffectsFile(TempDirMixin, unittest.TestCase):
|
|
|
|
reference_path = self.get_temp_path("reference.wav")
|
|
|
|
reference_path = self.get_temp_path("reference.wav")
|
|
|
|
data = get_wav_data(dtype, num_channels, channels_first=channels_first)
|
|
|
|
data = get_wav_data(dtype, num_channels, channels_first=channels_first)
|
|
|
|
save_wav(input_path, data, input_sr, channels_first=channels_first)
|
|
|
|
save_wav(input_path, data, input_sr, channels_first=channels_first)
|
|
|
|
sox_utils.run_sox_effect(input_path, reference_path, effects, output_sample_rate=output_sr)
|
|
|
|
sox_utils.run_sox_effect(
|
|
|
|
|
|
|
|
input_path, reference_path, effects, output_sample_rate=output_sr)
|
|
|
|
|
|
|
|
|
|
|
|
expected, expected_sr = load_wav(reference_path)
|
|
|
|
expected, expected_sr = load_wav(reference_path)
|
|
|
|
found, sr = sox_effects.apply_effects_file(input_path, effects, normalize=False, channels_first=channels_first)
|
|
|
|
found, sr = sox_effects.apply_effects_file(
|
|
|
|
|
|
|
|
input_path, effects, normalize=False, channels_first=channels_first)
|
|
|
|
|
|
|
|
|
|
|
|
assert sr == expected_sr
|
|
|
|
assert sr == expected_sr
|
|
|
|
#self.assertEqual(found, expected)
|
|
|
|
#self.assertEqual(found, expected)
|
|
|
|
np.testing.assert_array_almost_equal(expected.numpy(), found.numpy())
|
|
|
|
np.testing.assert_array_almost_equal(expected.numpy(), found.numpy())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_apply_effects_path(self):
|
|
|
|
def test_apply_effects_path(self):
|
|
|
|
"""`apply_effects_file` should return identical data as sox command when file path is given as a Path Object"""
|
|
|
|
"""`apply_effects_file` should return identical data as sox command when file path is given as a Path Object"""
|
|
|
|
dtype = "int32"
|
|
|
|
dtype = "int32"
|
|
|
@ -149,12 +153,15 @@ class TestSoxEffectsFile(TempDirMixin, unittest.TestCase):
|
|
|
|
reference_path = self.get_temp_path("reference.wav")
|
|
|
|
reference_path = self.get_temp_path("reference.wav")
|
|
|
|
data = get_wav_data(dtype, num_channels, channels_first=channels_first)
|
|
|
|
data = get_wav_data(dtype, num_channels, channels_first=channels_first)
|
|
|
|
save_wav(input_path, data, input_sr, channels_first=channels_first)
|
|
|
|
save_wav(input_path, data, input_sr, channels_first=channels_first)
|
|
|
|
sox_utils.run_sox_effect(input_path, reference_path, effects, output_sample_rate=output_sr)
|
|
|
|
sox_utils.run_sox_effect(
|
|
|
|
|
|
|
|
input_path, reference_path, effects, output_sample_rate=output_sr)
|
|
|
|
|
|
|
|
|
|
|
|
expected, expected_sr = load_wav(reference_path)
|
|
|
|
expected, expected_sr = load_wav(reference_path)
|
|
|
|
found, sr = sox_effects.apply_effects_file(
|
|
|
|
found, sr = sox_effects.apply_effects_file(
|
|
|
|
Path(input_path), effects, normalize=False, channels_first=channels_first
|
|
|
|
Path(input_path),
|
|
|
|
)
|
|
|
|
effects,
|
|
|
|
|
|
|
|
normalize=False,
|
|
|
|
|
|
|
|
channels_first=channels_first)
|
|
|
|
|
|
|
|
|
|
|
|
assert sr == expected_sr
|
|
|
|
assert sr == expected_sr
|
|
|
|
#self.assertEqual(found, expected)
|
|
|
|
#self.assertEqual(found, expected)
|
|
|
@ -165,13 +172,10 @@ class TestFileFormats(TempDirMixin, unittest.TestCase):
|
|
|
|
"""`apply_effects_file` gives the same result as sox on various file formats"""
|
|
|
|
"""`apply_effects_file` gives the same result as sox on various file formats"""
|
|
|
|
|
|
|
|
|
|
|
|
@parameterized.expand(
|
|
|
|
@parameterized.expand(
|
|
|
|
list(
|
|
|
|
list(itertools.product(
|
|
|
|
itertools.product(
|
|
|
|
["float32", "int32"],
|
|
|
|
["float32", "int32"],
|
|
|
|
[8000, 16000],
|
|
|
|
[8000, 16000],
|
|
|
|
[1, 2], )),
|
|
|
|
[1, 2],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
#name_func=lambda f, _, p: f'{f.__name__}_{"_".join(str(arg) for arg in p.args)}',
|
|
|
|
#name_func=lambda f, _, p: f'{f.__name__}_{"_".join(str(arg) for arg in p.args)}',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
def test_wav(self, dtype, sample_rate, num_channels):
|
|
|
|
def test_wav(self, dtype, sample_rate, num_channels):
|
|
|
@ -186,7 +190,8 @@ class TestFileFormats(TempDirMixin, unittest.TestCase):
|
|
|
|
sox_utils.run_sox_effect(input_path, reference_path, effects)
|
|
|
|
sox_utils.run_sox_effect(input_path, reference_path, effects)
|
|
|
|
|
|
|
|
|
|
|
|
expected, expected_sr = load_wav(reference_path)
|
|
|
|
expected, expected_sr = load_wav(reference_path)
|
|
|
|
found, sr = sox_effects.apply_effects_file(input_path, effects, normalize=False, channels_first=channels_first)
|
|
|
|
found, sr = sox_effects.apply_effects_file(
|
|
|
|
|
|
|
|
input_path, effects, normalize=False, channels_first=channels_first)
|
|
|
|
|
|
|
|
|
|
|
|
assert sr == expected_sr
|
|
|
|
assert sr == expected_sr
|
|
|
|
#self.assertEqual(found, expected)
|
|
|
|
#self.assertEqual(found, expected)
|
|
|
@ -194,68 +199,66 @@ class TestFileFormats(TempDirMixin, unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
#not support now
|
|
|
|
#not support now
|
|
|
|
#@parameterized.expand(
|
|
|
|
#@parameterized.expand(
|
|
|
|
#list(
|
|
|
|
#list(
|
|
|
|
#itertools.product(
|
|
|
|
#itertools.product(
|
|
|
|
#[8000, 16000],
|
|
|
|
#[8000, 16000],
|
|
|
|
#[1, 2],
|
|
|
|
#[1, 2],
|
|
|
|
#)
|
|
|
|
#)
|
|
|
|
#),
|
|
|
|
#),
|
|
|
|
##name_func=lambda f, _, p: f'{f.__name__}_{"_".join(str(arg) for arg in p.args)}',
|
|
|
|
##name_func=lambda f, _, p: f'{f.__name__}_{"_".join(str(arg) for arg in p.args)}',
|
|
|
|
#)
|
|
|
|
#)
|
|
|
|
#def test_flac(self, sample_rate, num_channels):
|
|
|
|
#def test_flac(self, sample_rate, num_channels):
|
|
|
|
#"""`apply_effects_file` works on various flac format"""
|
|
|
|
#"""`apply_effects_file` works on various flac format"""
|
|
|
|
#channels_first = True
|
|
|
|
#channels_first = True
|
|
|
|
#effects = [["band", "300", "10"]]
|
|
|
|
#effects = [["band", "300", "10"]]
|
|
|
|
|
|
|
|
|
|
|
|
#input_path = self.get_temp_path("input.flac")
|
|
|
|
#input_path = self.get_temp_path("input.flac")
|
|
|
|
#reference_path = self.get_temp_path("reference.wav")
|
|
|
|
#reference_path = self.get_temp_path("reference.wav")
|
|
|
|
#sox_utils.gen_audio_file(input_path, sample_rate, num_channels)
|
|
|
|
#sox_utils.gen_audio_file(input_path, sample_rate, num_channels)
|
|
|
|
#sox_utils.run_sox_effect(input_path, reference_path, effects, output_bitdepth=32)
|
|
|
|
#sox_utils.run_sox_effect(input_path, reference_path, effects, output_bitdepth=32)
|
|
|
|
|
|
|
|
|
|
|
|
#expected, expected_sr = load_wav(reference_path)
|
|
|
|
#expected, expected_sr = load_wav(reference_path)
|
|
|
|
#found, sr = sox_effects.apply_effects_file(input_path, effects, channels_first=channels_first)
|
|
|
|
#found, sr = sox_effects.apply_effects_file(input_path, effects, channels_first=channels_first)
|
|
|
|
#save_wav(self.get_temp_path("result.wav"), found, sr, channels_first=channels_first)
|
|
|
|
#save_wav(self.get_temp_path("result.wav"), found, sr, channels_first=channels_first)
|
|
|
|
|
|
|
|
|
|
|
|
#assert sr == expected_sr
|
|
|
|
#assert sr == expected_sr
|
|
|
|
##self.assertEqual(found, expected)
|
|
|
|
##self.assertEqual(found, expected)
|
|
|
|
#np.testing.assert_array_almost_equal(found.numpy(), expected.numpy())
|
|
|
|
#np.testing.assert_array_almost_equal(found.numpy(), expected.numpy())
|
|
|
|
|
|
|
|
|
|
|
|
#@parameterized.expand(
|
|
|
|
#@parameterized.expand(
|
|
|
|
#list(
|
|
|
|
#list(
|
|
|
|
#itertools.product(
|
|
|
|
#itertools.product(
|
|
|
|
#[8000, 16000],
|
|
|
|
#[8000, 16000],
|
|
|
|
#[1, 2],
|
|
|
|
#[1, 2],
|
|
|
|
#)
|
|
|
|
#)
|
|
|
|
#),
|
|
|
|
#),
|
|
|
|
##name_func=lambda f, _, p: f'{f.__name__}_{"_".join(str(arg) for arg in p.args)}',
|
|
|
|
##name_func=lambda f, _, p: f'{f.__name__}_{"_".join(str(arg) for arg in p.args)}',
|
|
|
|
#)
|
|
|
|
#)
|
|
|
|
#def test_vorbis(self, sample_rate, num_channels):
|
|
|
|
#def test_vorbis(self, sample_rate, num_channels):
|
|
|
|
#"""`apply_effects_file` works on various vorbis format"""
|
|
|
|
#"""`apply_effects_file` works on various vorbis format"""
|
|
|
|
#channels_first = True
|
|
|
|
#channels_first = True
|
|
|
|
#effects = [["band", "300", "10"]]
|
|
|
|
#effects = [["band", "300", "10"]]
|
|
|
|
|
|
|
|
|
|
|
|
#input_path = self.get_temp_path("input.vorbis")
|
|
|
|
#input_path = self.get_temp_path("input.vorbis")
|
|
|
|
#reference_path = self.get_temp_path("reference.wav")
|
|
|
|
#reference_path = self.get_temp_path("reference.wav")
|
|
|
|
#sox_utils.gen_audio_file(input_path, sample_rate, num_channels)
|
|
|
|
#sox_utils.gen_audio_file(input_path, sample_rate, num_channels)
|
|
|
|
#sox_utils.run_sox_effect(input_path, reference_path, effects, output_bitdepth=32)
|
|
|
|
#sox_utils.run_sox_effect(input_path, reference_path, effects, output_bitdepth=32)
|
|
|
|
|
|
|
|
|
|
|
|
#expected, expected_sr = load_wav(reference_path)
|
|
|
|
#expected, expected_sr = load_wav(reference_path)
|
|
|
|
#found, sr = sox_effects.apply_effects_file(input_path, effects, channels_first=channels_first)
|
|
|
|
#found, sr = sox_effects.apply_effects_file(input_path, effects, channels_first=channels_first)
|
|
|
|
#save_wav(self.get_temp_path("result.wav"), found, sr, channels_first=channels_first)
|
|
|
|
#save_wav(self.get_temp_path("result.wav"), found, sr, channels_first=channels_first)
|
|
|
|
|
|
|
|
|
|
|
|
#assert sr == expected_sr
|
|
|
|
#assert sr == expected_sr
|
|
|
|
##self.assertEqual(found, expected)
|
|
|
|
##self.assertEqual(found, expected)
|
|
|
|
#np.testing.assert_array_almost_equal(found.numpy(), expected.numpy())
|
|
|
|
#np.testing.assert_array_almost_equal(found.numpy(), expected.numpy())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#@skipIfNoExec("sox")
|
|
|
|
#@skipIfNoExec("sox")
|
|
|
|
#@skipIfNoSox
|
|
|
|
#@skipIfNoSox
|
|
|
|
class TestFileObject(TempDirMixin, unittest.TestCase):
|
|
|
|
class TestFileObject(TempDirMixin, unittest.TestCase):
|
|
|
|
@parameterized.expand(
|
|
|
|
@parameterized.expand([
|
|
|
|
[
|
|
|
|
("wav", None),
|
|
|
|
("wav", None),
|
|
|
|
])
|
|
|
|
]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_fileobj(self, ext, compression):
|
|
|
|
def test_fileobj(self, ext, compression):
|
|
|
|
"""Applying effects via file object works"""
|
|
|
|
"""Applying effects via file object works"""
|
|
|
|
sample_rate = 16000
|
|
|
|
sample_rate = 16000
|
|
|
@ -268,21 +271,25 @@ class TestFileObject(TempDirMixin, unittest.TestCase):
|
|
|
|
data = get_wav_data("int32", 2, channels_first=channels_first)
|
|
|
|
data = get_wav_data("int32", 2, channels_first=channels_first)
|
|
|
|
save_wav(input_path, data, sample_rate, channels_first=channels_first)
|
|
|
|
save_wav(input_path, data, sample_rate, channels_first=channels_first)
|
|
|
|
|
|
|
|
|
|
|
|
sox_utils.run_sox_effect(input_path, reference_path, effects, output_bitdepth=32)
|
|
|
|
sox_utils.run_sox_effect(
|
|
|
|
|
|
|
|
input_path, reference_path, effects, output_bitdepth=32)
|
|
|
|
expected, expected_sr = load_wav(reference_path)
|
|
|
|
expected, expected_sr = load_wav(reference_path)
|
|
|
|
|
|
|
|
|
|
|
|
with open(input_path, "rb") as fileobj:
|
|
|
|
with open(input_path, "rb") as fileobj:
|
|
|
|
found, sr = sox_effects.apply_effects_file(fileobj, effects, channels_first=channels_first)
|
|
|
|
found, sr = sox_effects.apply_effects_file(
|
|
|
|
save_wav(self.get_temp_path("result.wav"), found, sr, channels_first=channels_first)
|
|
|
|
fileobj, effects, channels_first=channels_first)
|
|
|
|
|
|
|
|
save_wav(
|
|
|
|
|
|
|
|
self.get_temp_path("result.wav"),
|
|
|
|
|
|
|
|
found,
|
|
|
|
|
|
|
|
sr,
|
|
|
|
|
|
|
|
channels_first=channels_first)
|
|
|
|
assert sr == expected_sr
|
|
|
|
assert sr == expected_sr
|
|
|
|
#self.assertEqual(found, expected)
|
|
|
|
#self.assertEqual(found, expected)
|
|
|
|
np.testing.assert_array_almost_equal(found.numpy(), expected.numpy())
|
|
|
|
np.testing.assert_array_almost_equal(found.numpy(), expected.numpy())
|
|
|
|
|
|
|
|
|
|
|
|
@parameterized.expand(
|
|
|
|
@parameterized.expand([
|
|
|
|
[
|
|
|
|
("wav", None),
|
|
|
|
("wav", None),
|
|
|
|
])
|
|
|
|
]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_bytesio(self, ext, compression):
|
|
|
|
def test_bytesio(self, ext, compression):
|
|
|
|
"""Applying effects via BytesIO object works"""
|
|
|
|
"""Applying effects via BytesIO object works"""
|
|
|
|
sample_rate = 16000
|
|
|
|
sample_rate = 16000
|
|
|
@ -294,13 +301,19 @@ class TestFileObject(TempDirMixin, unittest.TestCase):
|
|
|
|
#sox_utils.gen_audio_file(input_path, sample_rate, num_channels=2, compression=compression)
|
|
|
|
#sox_utils.gen_audio_file(input_path, sample_rate, num_channels=2, compression=compression)
|
|
|
|
data = get_wav_data("int32", 2, channels_first=channels_first)
|
|
|
|
data = get_wav_data("int32", 2, channels_first=channels_first)
|
|
|
|
save_wav(input_path, data, sample_rate, channels_first=channels_first)
|
|
|
|
save_wav(input_path, data, sample_rate, channels_first=channels_first)
|
|
|
|
sox_utils.run_sox_effect(input_path, reference_path, effects, output_bitdepth=32)
|
|
|
|
sox_utils.run_sox_effect(
|
|
|
|
|
|
|
|
input_path, reference_path, effects, output_bitdepth=32)
|
|
|
|
expected, expected_sr = load_wav(reference_path)
|
|
|
|
expected, expected_sr = load_wav(reference_path)
|
|
|
|
|
|
|
|
|
|
|
|
with open(input_path, "rb") as file_:
|
|
|
|
with open(input_path, "rb") as file_:
|
|
|
|
fileobj = io.BytesIO(file_.read())
|
|
|
|
fileobj = io.BytesIO(file_.read())
|
|
|
|
found, sr = sox_effects.apply_effects_file(fileobj, effects, channels_first=channels_first)
|
|
|
|
found, sr = sox_effects.apply_effects_file(
|
|
|
|
save_wav(self.get_temp_path("result.wav"), found, sr, channels_first=channels_first)
|
|
|
|
fileobj, effects, channels_first=channels_first)
|
|
|
|
|
|
|
|
save_wav(
|
|
|
|
|
|
|
|
self.get_temp_path("result.wav"),
|
|
|
|
|
|
|
|
found,
|
|
|
|
|
|
|
|
sr,
|
|
|
|
|
|
|
|
channels_first=channels_first)
|
|
|
|
assert sr == expected_sr
|
|
|
|
assert sr == expected_sr
|
|
|
|
#self.assertEqual(found, expected)
|
|
|
|
#self.assertEqual(found, expected)
|
|
|
|
print("found")
|
|
|
|
print("found")
|
|
|
@ -309,11 +322,9 @@ class TestFileObject(TempDirMixin, unittest.TestCase):
|
|
|
|
print(expected)
|
|
|
|
print(expected)
|
|
|
|
np.testing.assert_array_almost_equal(found.numpy(), expected.numpy())
|
|
|
|
np.testing.assert_array_almost_equal(found.numpy(), expected.numpy())
|
|
|
|
|
|
|
|
|
|
|
|
@parameterized.expand(
|
|
|
|
@parameterized.expand([
|
|
|
|
[
|
|
|
|
("wav", None),
|
|
|
|
("wav", None),
|
|
|
|
])
|
|
|
|
]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_tarfile(self, ext, compression):
|
|
|
|
def test_tarfile(self, ext, compression):
|
|
|
|
"""Applying effects to compressed audio via file-like file works"""
|
|
|
|
"""Applying effects to compressed audio via file-like file works"""
|
|
|
|
sample_rate = 16000
|
|
|
|
sample_rate = 16000
|
|
|
@ -326,22 +337,28 @@ class TestFileObject(TempDirMixin, unittest.TestCase):
|
|
|
|
archive_path = self.get_temp_path("archive.tar.gz")
|
|
|
|
archive_path = self.get_temp_path("archive.tar.gz")
|
|
|
|
data = get_wav_data("int32", 2, channels_first=channels_first)
|
|
|
|
data = get_wav_data("int32", 2, channels_first=channels_first)
|
|
|
|
save_wav(input_path, data, sample_rate, channels_first=channels_first)
|
|
|
|
save_wav(input_path, data, sample_rate, channels_first=channels_first)
|
|
|
|
|
|
|
|
|
|
|
|
# sox_utils.gen_audio_file(input_path, sample_rate, num_channels=2, compression=compression)
|
|
|
|
# sox_utils.gen_audio_file(input_path, sample_rate, num_channels=2, compression=compression)
|
|
|
|
sox_utils.run_sox_effect(input_path, reference_path, effects, output_bitdepth=32)
|
|
|
|
sox_utils.run_sox_effect(
|
|
|
|
|
|
|
|
input_path, reference_path, effects, output_bitdepth=32)
|
|
|
|
|
|
|
|
|
|
|
|
expected, expected_sr = load_wav(reference_path)
|
|
|
|
expected, expected_sr = load_wav(reference_path)
|
|
|
|
|
|
|
|
|
|
|
|
with tarfile.TarFile(archive_path, "w") as tarobj:
|
|
|
|
with tarfile.TarFile(archive_path, "w") as tarobj:
|
|
|
|
tarobj.add(input_path, arcname=audio_file)
|
|
|
|
tarobj.add(input_path, arcname=audio_file)
|
|
|
|
with tarfile.TarFile(archive_path, "r") as tarobj:
|
|
|
|
with tarfile.TarFile(archive_path, "r") as tarobj:
|
|
|
|
fileobj = tarobj.extractfile(audio_file)
|
|
|
|
fileobj = tarobj.extractfile(audio_file)
|
|
|
|
found, sr = sox_effects.apply_effects_file(fileobj, effects, channels_first=channels_first)
|
|
|
|
found, sr = sox_effects.apply_effects_file(
|
|
|
|
save_wav(self.get_temp_path("result.wav"), found, sr, channels_first=channels_first)
|
|
|
|
fileobj, effects, channels_first=channels_first)
|
|
|
|
|
|
|
|
save_wav(
|
|
|
|
|
|
|
|
self.get_temp_path("result.wav"),
|
|
|
|
|
|
|
|
found,
|
|
|
|
|
|
|
|
sr,
|
|
|
|
|
|
|
|
channels_first=channels_first)
|
|
|
|
assert sr == expected_sr
|
|
|
|
assert sr == expected_sr
|
|
|
|
#self.assertEqual(found, expected)
|
|
|
|
#self.assertEqual(found, expected)
|
|
|
|
np.testing.assert_array_almost_equal(found.numpy(), expected.numpy())
|
|
|
|
np.testing.assert_array_almost_equal(found.numpy(), expected.numpy())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
unittest.main()
|
|
|
|