pystoi

0.4.1 · maintenance · verified Tue Apr 14

pystoi is a Python library that computes the Short Term Objective Intelligibility (STOI) measure, a metric highly correlated with the subjective intelligibility of degraded speech signals. It is an intrusive measure, requiring both clean and degraded speech inputs. It serves as an objective alternative for evaluating the effect of non-linear processing like noise reduction or binary masking on speech intelligibility. The current version is 0.4.1, and its development appears to be in maintenance mode.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to compute the STOI score between a clean and a degraded speech signal. It uses `soundfile` to read the audio, then calls the `stoi` function with the clean signal, degraded signal, and sampling frequency. The `extended` parameter can be set to `True` for extended STOI.

import soundfile as sf
import numpy as np
from pystoi import stoi
import os

# Create dummy audio files for demonstration
fs = 10000 # Sample rate
duration = 1 # seconds

clean_signal = np.random.rand(fs * duration).astype(np.float32) * 0.5 # Clean speech
denoised_signal = clean_signal + (np.random.rand(fs * duration).astype(np.float32) - 0.5) * 0.1 # Denoised (noisy) speech

# Save dummy files
sf.write('clean.wav', clean_signal, fs)
sf.write('denoised.wav', denoised_signal, fs)

# Load the audio files (replace with your actual paths)
clean_audio, fs_clean = sf.read('clean.wav')
denoised_audio, fs_denoised = sf.read('denoised.wav')

# Ensure sample rates are consistent, pystoi will resample if needed to 10kHz internally
assert fs_clean == fs_denoised, "Sample rates must match"

# Compute STOI
score = stoi(clean_audio, denoised_audio, fs_clean, extended=False)

print(f"STOI score: {score:.4f}")

# Clean up dummy files
os.remove('clean.wav')
os.remove('denoised.wav')

view raw JSON →