Package: pesq
pesqPESQ (Perceptual Evaluation of Speech Quality) Wrapper for Python UsersThis code is designed for numpy array specially.RequirementsC compiler
numpy
cythonBuild and Install$gitclonehttps://github.com/ludlows/python-pesq.git
$cdpython-pesq
$pipinstall.# for python 2$pip3install.# for python 3$cd..
$rm-rfpython-pesq# remove the code folder since it exists in the python package folderInstall with pip# PyPi Repository$pipinstallpesq# The Latest Version$pipinstallhttps://github.com/ludlows/python-pesq/archive/master.zip# or$pip3installhttps://github.com/ludlows/python-pesq/archive/master.zipUsage for narrowband and wideband ModesPlease note that the sampling rate (frequency) should be 16000 or 8000 (Hz).And using 8000Hz is supported for narrowband only.The code supports error-handling behaviors now.defpesq(fs,ref,deg,mode='wb',on_error=PesqError.RAISE_EXCEPTION):"""Args:ref: numpy 1D array, reference audio signaldeg: numpy 1D array, degraded audio signalfs:  integer, sampling ratemode: 'wb' (wide-band) or 'nb' (narrow-band)on_error: error-handling behavior, it could be PesqError.RETURN_VALUES or PesqError.RAISE_EXCEPTION by defaultReturns:pesq_score: float, P.862.2 Prediction (MOS-LQO)"""Once you selectPesqError.RETURN_VALUES, thepesqfunction will return -1 when an error occurs.Once you selectPesqError.RAISE_EXCEPTION, thepesqfunction will raise an exception when an error occurs.It supports the following errors now:InvalidSampleRateError,OutOfMemoryError,BufferTooShortError,NoUtterancesError,PesqError(other unknown errors).fromscipy.ioimportwavfilefrompesqimportpesqrate,ref=wavfile.read("./audio/speech.wav")rate,deg=wavfile.read("./audio/speech_bab_0dB.wav")print(pesq(rate,ref,deg,'wb'))print(pesq(rate,ref,deg,'nb'))Usage formultiprocessingfeaturedefpesq_batch(fs,ref,deg,mode='wb',n_processor=None,on_error=PesqError.RAISE_EXCEPTION):"""Running `pesq` using multiple processorsArgs:on_error:ref: numpy 1D (n_sample,) or 2D array (n_file, n_sample), reference audio signaldeg: numpy 1D (n_sample,) or 2D array (n_file, n_sample), degraded audio signalfs:  integer, sampling ratemode: 'wb' (wide-band) or 'nb' (narrow-band)n_processor: cpu_count() (default) or number of processors (chosen by the user) or 0 (without multiprocessing)on_error: PesqError.RAISE_EXCEPTION (default) or PesqError.RETURN_VALUESReturns:pesq_score: list of pesq scores, P.862.2 Prediction (MOS-LQO)"""this function usesmultiprocessingfeatures to boost time efficiency.When therefis an 1-D numpy array anddegis a 2-D numpy array, the result ofpesq_batchis identical to the value of[pesq(fs, ref, deg[i,:],**kwargs) for i in range(deg.shape[0])].When therefis a 2-D numpy array anddegis a 2-D numpy array, the result ofpesq_batchis identical to the value of[pesq(fs, ref[i,:], deg[i,:],**kwargs) for i in range(deg.shape[0])].CorrectnessThe correctness is verified by running samples in audio folder.PESQ computed by this code in wideband mode is    1.0832337141036987PESQ computed by this code in narrowband mode is  1.6072081327438354NoteSampling rate (fs|rate) - No default. Must select either 8000Hz or 16000Hz.Note there is narrowband (nb) mode only when sampling rate is 8000Hz.The original C source code is modified.Who is usingpesqPlease clickhereto see these repositories, whose owners includeFacebook Research,SpeechBrain,NVIDIA.etc.Cite this code@software{miao_wang_2022_6549559,
   author       = {Miao Wang and
                  Christoph Boeddeker and
                  Rafael G. Dantas and
                  ananda seelan},
   title        = {{ludlows/python-pesq: supporting for 
                   multiprocessing features}},
   month        = may,
   year         = 2022,
   publisher    = {Zenodo},
   version      = {v0.0.4},
   doi          = {10.5281/zenodo.6549559},
   url          = {https://doi.org/10.5281/zenodo.6549559}}AcknowledgementThis work was funded by the Natural Sciences and Engineering Research Council of Canada.This work was also funded by the Concordia University, Montreal, Canada.