Torch-STOI is a Python library that provides a PyTorch implementation of the Short-Time Objective Intelligibility (STOI) metric, primarily designed for use as a loss function in deep learning models for tasks like speech enhancement and source separation. It wraps the functionality of the `pystoi` package to calculate both classical and extended STOI. The current version is 0.2.3, and releases are generally infrequent, focusing on functional improvements and correlation with the reference `pystoi` implementation.
pip install torch-stoiVerified import paths — ran on the pinned version, not inferred.
Initializes `NegSTOILoss` with a sample rate and demonstrates its use as a loss function with example clean and estimated speech tensors. Note that `torch-stoi` is typically integrated into a neural network training loop.
Use `pystoi` directly for accurate STOI metric evaluation: `import pystoi; pystoi.stoi(clean_audio, degraded_audio, fs)`.
Be aware of potential device transfers. For performance-critical applications, consider pre-moving data to CPU if feasible, or ensure batch sizes are optimized for transfer.
If closer adherence to the standard STOI metric is desired, ensure `use_vad` is set to `True` (default behavior).
Install the `pystoi` dependency: `pip install pystoi`.
If working with `torchtext`, update your code from `vocab.stoi` to `vocab.get_stoi()`. This error is unrelated to `torch-stoi`.
Ensure that the `est_targets` (predicted speech) and `targets` (clean reference speech) tensors have identical shapes (e.g., `[batch_size, num_samples]`).