diff --git a/paddleaudio/setup.py b/paddleaudio/setup.py index 7623443a..7efa976f 100644 --- a/paddleaudio/setup.py +++ b/paddleaudio/setup.py @@ -12,18 +12,38 @@ # See the License for the specific language governing permissions and # limitations under the License. import setuptools +from setuptools.command.install import install +from setuptools.command.test import test as TestCommand # set the version here VERSION = '0.2.0' +# Inspired by the example at https://pytest.org/latest/goodpractises.html +class NoseTestCommand(TestCommand): + def finalize_options(self): + TestCommand.finalize_options(self) + self.test_args = [] + self.test_suite = True + + def run_tests(self): + # Run nose ensuring that argv simulates running nosetests directly + import nose + nose.run_exit(argv=['nosetests', '-w', 'tests']) + + +class InstallCommand(install): + def run(self): + install.run(self) + + def write_version_py(filename='paddleaudio/__init__.py'): import paddleaudio if hasattr(paddleaudio, "__version__") and paddleaudio.__version__ == VERSION: return with open(filename, "a") as f: - f.write(f"\n__version__ = '{VERSION}'\n") + f.write(f"__version__ = '{VERSION}'") def remove_version_py(filename='paddleaudio/__init__.py'): @@ -61,6 +81,11 @@ setuptools.setup( 'colorlog', 'dtaidistance >= 2.3.6', 'mcd >= 0.4', - ], ) + ], + setup_requires=['nose'], + cmdclass={ + 'install': InstallCommand, + 'test': NoseTestCommand, + }, ) remove_version_py() diff --git a/paddleaudio/tests/features/istft.py b/paddleaudio/tests/features/istft.py deleted file mode 100644 index 2d9097c7..00000000 --- a/paddleaudio/tests/features/istft.py +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import unittest - -import numpy as np -import paddle - -from .base import FeatTest -from paddleaudio.functional.window import get_window -from paddlespeech.s2t.transform.spectrogram import IStft -from paddlespeech.s2t.transform.spectrogram import Stft - - -class ISTFT(FeatTest): - def initParmas(self): - self.n_fft = 512 - self.hop_length = 128 - self.window_str = 'hann' - - def test_istft(self): - ps_stft = Stft(self.n_fft, self.hop_length) - ps_res = ps_stft( - self.waveform.T).squeeze(1).T # (n_fft//2 + 1, n_frmaes) - x = paddle.to_tensor(ps_res) - - ps_istft = IStft(self.hop_length) - ps_res = ps_istft(ps_res.T) - - window = get_window( - self.window_str, self.n_fft, dtype=self.waveform.dtype) - pd_res = paddle.signal.istft( - x, self.n_fft, self.hop_length, window=window) - - np.testing.assert_array_almost_equal(ps_res, pd_res, decimal=5) - - -if __name__ == '__main__': - unittest.main() diff --git a/paddleaudio/tests/features/log_melspectrogram.py b/paddleaudio/tests/features/log_melspectrogram.py deleted file mode 100644 index ee54f5db..00000000 --- a/paddleaudio/tests/features/log_melspectrogram.py +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import unittest - -import numpy as np -import paddle - -import paddleaudio -from .base import FeatTest -from paddlespeech.s2t.transform.spectrogram import LogMelSpectrogram - - -class LogMelSpect(FeatTest): - def initParmas(self): - self.n_fft = 512 - self.hop_length = 128 - self.n_mels = 40 - - def test_log_melspect(self): - ps_melspect = LogMelSpectrogram(self.sr, self.n_mels, self.n_fft, - self.hop_length) - ps_res = ps_melspect(self.waveform.T).squeeze(1).T - - x = paddle.to_tensor(self.waveform) - # paddlespeech.s2t的特征存在幅度谱和功率谱滥用的情况 - ps_melspect = paddleaudio.features.LogMelSpectrogram( - self.sr, - self.n_fft, - self.hop_length, - power=1.0, - n_mels=self.n_mels, - f_min=0.0) - pa_res = (ps_melspect(x) / 10.0).squeeze(0).numpy() - - np.testing.assert_array_almost_equal(ps_res, pa_res, decimal=5) - - -if __name__ == '__main__': - unittest.main() diff --git a/paddleaudio/tests/features/spectrogram.py b/paddleaudio/tests/features/spectrogram.py deleted file mode 100644 index da71d639..00000000 --- a/paddleaudio/tests/features/spectrogram.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import unittest - -import numpy as np -import paddle - -import paddleaudio -from .base import FeatTest -from paddlespeech.s2t.transform.spectrogram import Spectrogram - - -class Spect(FeatTest): - def initParmas(self): - self.n_fft = 512 - self.hop_length = 128 - - def test_spectrogram(self): - ps_spect = Spectrogram(self.n_fft, self.hop_length) - ps_res = ps_spect(self.waveform.T).squeeze(1).T # Magnitude - - x = paddle.to_tensor(self.waveform) - pa_spect = paddleaudio.features.Spectrogram( - self.n_fft, self.hop_length, power=1.0) - pa_res = pa_spect(x).squeeze(0).numpy() - - np.testing.assert_array_almost_equal(ps_res, pa_res, decimal=5) - - -if __name__ == '__main__': - unittest.main() diff --git a/paddleaudio/tests/features/stft.py b/paddleaudio/tests/features/stft.py deleted file mode 100644 index 352d6dfa..00000000 --- a/paddleaudio/tests/features/stft.py +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import unittest - -import numpy as np -import paddle - -from .base import FeatTest -from paddleaudio.functional.window import get_window -from paddlespeech.s2t.transform.spectrogram import Stft - - -class STFT(FeatTest): - def initParmas(self): - self.n_fft = 512 - self.hop_length = 128 - self.window_str = 'hann' - - def test_stft(self): - ps_stft = Stft(self.n_fft, self.hop_length) - ps_res = ps_stft( - self.waveform.T).squeeze(1).T # (n_fft//2 + 1, n_frmaes) - - x = paddle.to_tensor(self.waveform) - window = get_window(self.window_str, self.n_fft, dtype=x.dtype) - pd_res = paddle.signal.stft( - x, self.n_fft, self.hop_length, window=window).squeeze(0).numpy() - - np.testing.assert_array_almost_equal(ps_res, pd_res, decimal=5) - - -if __name__ == '__main__': - unittest.main()