PESQ Score Calculator

0.0.4 · active · verified Fri Apr 17

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.

Common errors

Warnings

Install

Imports

Quickstart

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')

view raw JSON →