Registry / ai-ml / pesq
library0.0.4pypypiunverified

pesq is a Python wrapper for the Perceptual Evaluation of Speech Quality (PESQ) metric, implementing the ITU-T P.862 standard. It supports both narrow-band ('nb') and wide-band ('wb') calculations, providing an objective measure of speech quality. The current version is 0.0.4, with releases occurring infrequently but introducing new features like multiprocessing support.

pip install pesq
INSTALL
IMPORT
SIG · PESQ
P
pesq
ai-mlpythonv0.0.4
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
build_error
glibc
py 3.103.910 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pesq
from pesq import pesq
import pesq

This quickstart demonstrates how to calculate a PESQ score using NumPy arrays for reference and degraded audio signals. It highlights the use of the `pesq` function with a specified sampling rate and mode ('wb' for wide-band). The library internally handles the necessary conversions, but input characteristics are crucial.

import numpy as np from pesq import pesq # Define sampling rate and generate dummy audio signals (16 kHz, 3 seconds) fs = 16000 duration = 3 # seconds t = np.linspace(0, duration, int(fs * duration), endpoint=False) # Reference signal (e.g., clean speech) ref_signal = (0.5 * np.sin(2 * np.pi * 440 * t)).astype(np.float32) # Degraded signal (e.g., speech with noise or distortion) deg_signal = (0.5 * np.sin(2 * np.pi * 440 * t + 0.1) + 0.1 * np.random.randn(len(t))).astype(np.float32) # Ensure signals are 16-bit PCM (by scaling to int16 range) if not already # The library expects float32, but underlying PESQ is 16-bit. # For this example, float32 is fine as it will be handled internally. # Calculate Wide-Band PESQ score score_wb = pesq(fs, ref_signal, deg_signal, 'wb') print(f"PESQ Wide-Band (wb) score: {score_wb:.2f}") # Calculate Narrow-Band PESQ score (requires adjusting signals if necessary) # score_nb = pesq(fs, ref_signal, deg_signal, 'nb') # print(f"PESQ Narrow-Band (nb) score: {score_nb:.2f}") # The `pesq` function also accepts file paths directly: # import soundfile as sf # import os # sf.write('ref.wav', ref_signal, fs, subtype='PCM_16') # sf.write('deg.wav', deg_signal, fs, subtype='PCM_16') # score_files = pesq(fs, 'ref.wav', 'deg.wav', 'wb') # print(f"PESQ from files: {score_files:.2f}") # os.remove('ref.wav'); os.remove('deg.wav')
Debug
Known issues
gotchaDue to its reliance on Cython for performance, installing `pesq` often requires a C compiler (e.g., GCC on Linux, Apple Clang on macOS, MSVC on Windows). Users may encounter `Failed building wheel` errors during `pip install` without one.
fix
Ensure a C compiler and associated build tools are installed on your system before attempting `pip install pesq`.
affects: All versions
gotchaThe underlying PESQ algorithm is highly sensitive to input audio characteristics. Signals provided to `pesq` must effectively represent 16-bit PCM, have the same sampling rate, and typically be of equal length to avoid `ValueError` or incorrect scores.
fix
Pre-process your audio signals to ensure they are consistent: resample to a common rate (e.g., 16 kHz), convert to 16-bit PCM representation (if not already), and trim/pad to equal lengths.
affects: All versions
gotchaIncorrectly specifying the PESQ mode ('nb' for narrow-band or 'wb' for wide-band) can lead to unexpected scores or errors. The chosen mode must match the characteristics and intended evaluation context of your audio.
fix
Always verify that the `mode` argument ('nb' or 'wb') passed to `pesq` or `pesq_batch` is appropriate for your audio data and the desired evaluation.
affects: All versions
deprecatedPrior to v0.0.3, error handling behaviors were less robust. While not a breaking API change, errors might have been less descriptive or harder to catch.
fix
Upgrade to v0.0.3 or higher to benefit from improved error messages and more graceful error handling.
affects: <0.0.3
Upgrade
Version history
0.0.4latest on PyPI · released May 17, 2022
Audit
Dependencies
numpyrequiredNumerical operations for audio data.
scipyrequiredScientific computing library, potentially for signal processing.
soundfilerequiredReading and writing audio files (e.g., WAV).
cythonrequiredUsed for compiling the C extensions that implement the core PESQ algorithm.
Agent activity
10 hits · last 30 days
node
10
Resources