From 956e99b2501c39efbcc4b57ee3b418c1b91194bd Mon Sep 17 00:00:00 2001 From: ludlows Date: Sun, 8 May 2022 00:29:42 +0800 Subject: [PATCH] enable multiple processors performance test --- pesq/__init__.py | 5 +++-- tests/test_pesq.py | 32 +++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/pesq/__init__.py b/pesq/__init__.py index 91a5e4c..ee8cc38 100644 --- a/pesq/__init__.py +++ b/pesq/__init__.py @@ -5,8 +5,9 @@ import numpy as np from multiprocessing import Pool, Queue, Process from functools import partial -from .cypesq import cypesq, cypesq_retvals -from .cypesq import PesqError +from .cypesq import cypesq, cypesq_retvals, cypesq_error_message as pesq_error_message +from .cypesq import PesqError, InvalidSampleRateError, OutOfMemoryError +from .cypesq import BufferTooShortError, NoUtterancesError USAGE = """ Run model on reference(ref) and degraded(deg) diff --git a/tests/test_pesq.py b/tests/test_pesq.py index 737ce6d..5e01562 100755 --- a/tests/test_pesq.py +++ b/tests/test_pesq.py @@ -92,8 +92,30 @@ def test_pesq_batch(): assert np.allclose(np.array(scores), ideally), scores -if __name__ == "__main__": - test() - test_no_utterances_nb_mode() - test_no_utterances_wb_mode() - test_pesq_batch() +# def test_time_efficiency(): +# data_dir = Path(__file__).parent.parent / 'audio' +# ref_path = data_dir / 'speech.wav' +# deg_path = data_dir / 'speech_bab_0dB.wav' +# +# sample_rate, ref = scipy.io.wavfile.read(ref_path) +# sample_rate, deg = scipy.io.wavfile.read(deg_path) +# import time +# nums = [100, 1000, 10000] +# durations = [] +# n_processors = 8 +# degs = [np.repeat(deg[np.newaxis, :], n, axis=0) for n in nums] +# for d, n in zip(degs, nums): +# start = time.time() +# pesq_batch(ref=ref, deg=d, fs=sample_rate, mode='wb', n_processor=n_processors) +# end = time.time() +# durations.append(end - start) +# print(durations) +# # [5.192636251449585, 30.032038688659668, 294.47159910202026] + + +# if __name__ == "__main__": + # test() + # test_no_utterances_nb_mode() + # test_no_utterances_wb_mode() + # test_pesq_batch() +