Python Wrapper for PESQ Score (narrow band and wide band)
Low maintenance activity. Last release over 4 years ago, commits in 0 of the last 26 weeks. Weaker on commit activity and recent releases.
pip install pesqpesq
PESQ (Perceptual Evaluation of Speech Quality) Wrapper for Python Users
This code is designed for numpy array specially.
Requirements
C compiler
numpy
cython
Build and Install
$ git clone https://github.com/ludlows/python-pesq.git
$ cd python-pesq
$ pip install . # for python 2
$ pip3 install . # for python 3
$ cd ..
$ rm -rf python-pesq # remove the code folder since it exists in the python package folder
Install with pip
# PyPi Repository
$ pip install pesq
# The Latest Version
$ pip install https://github.com/ludlows/python-pesq/archive/master.zip
# or
$ pip3 install https://github.com/ludlows/python-pesq/archive/master.zip
Usage for narrowband and wideband Modes
Please 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.
def pesq(fs, ref, deg, mode='wb', on_error=PesqError.RAISE_EXCEPTION):
"""
Args:
ref: numpy 1D array, reference audio signal
deg: numpy 1D array, degraded audio signal
fs: integer, sampling rate
mode: 'wb' (wide-band) or 'nb' (narrow-band)
on_error: error-handling behavior, it could be PesqError.RETURN_VALUES or PesqError.RAISE_EXCEPTION by default
Returns:
pesq_score: float, P.862.2 Prediction (MOS-LQO)
"""
Once you select PesqError.RETURN_VALUES, the pesq function will return -1 when an error occurs.
Once you select PesqError.RAISE_EXCEPTION, the pesq function will raise an exception when an error occurs.
It supports the following errors now: InvalidSampleRateError, OutOfMemoryError,BufferTooShortError,NoUtterancesError,PesqError(other unknown errors).
from scipy.io import wavfile
from pesq import pesq
rate, 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'))