batch-pystoi
This is a fork of pystoi, the original python implementation of classical and extended Short Term Objective Intelligibility (STOI) metrics [1-3]. This fork adds support for batched inputs and substantially improves processing time. The original author expressed that batched processing will not be implemented in the original repository, despite the interest and an open pull request. So it was implemented here. Thanks to @giamic for providing the groundwork for this fork in that pull request.
Notable changes
- As pointed out in this pull request, the original implementation for the extended STOI uses expensive
np.random.standard_normalcalls to add noise to the signal before normalizing. However since the noise is then scaled very small, this does not change the results unless the inputs are all-zeros, in which case the STOI output is non-zero (which does not seem to make much sense anyway?). Thenp.random.standard_normalcalls were removed here and for all-zero inputs the STOI output is zero. Note that any non-zero sample makes the VAD discard zeros, so the user should not worry about the different behavior in this very special case. stoinow accepts an extralengthsoptional argument containing the original length of the waveforms before batching. This is useful if padding is performed to match the length of the waveforms in the batch, since the padding should not affect the STOI results. Note that simply padding with zeros hoping that the VAD will discard them without providinglengthsis not enough, since the zeros can still leak onto the final frames of the original signal due to overlap-and-add.
Tests
- New tests under
tests/extensively compare the outputs from the originalpystoiimplementation with the implementation here. Results show the two implementations are equivalent (except for all-zeros inputs as described above, which can be neglected). - The original tests were moved to
tests.old/. These tests usematlab.engineand require Python 2.7. I was unable to run the tests despite my efforts. So the reference now is the originalpystoiimplementation.
Benchmark
The times below where obtained on an HP Elitebook 840 G6 with an Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz. The extended argument was set to True.
Install
pip install batch-pystoi
Usage
Same usage as in pystoi
import soundfile as sf
from batch_pystoi import stoi
clean, fs = sf.read('path/to/clean/audio')
denoised, fs = sf.read('path/to/denoised/audio')
# clean and denoised must have same shape
# they can be 1D (single-channel) or 2D (multi-channel) since stoi now supports batched inputs
# swap axis from (samples, channels) to (channels, samples) if 2D
clean, denoised = clean.T, denoised.T
# compute stoi
d = stoi(clean, denoised, fs, extended=False)
Using the lengths argument
import soundfile as sf
import numpy as np
from batch_pystoi import stoi
clean_1, fs = sf.read('path/to/clean/audio/1')
clean_2, fs = sf.read('path/to/clean/audio/2')
denoised_1, fs = sf.read('path/to/denoised/audio/1')
denoised_2, fs = sf.read('path/to/denoised/audio/2')
# clean_1 and denoised_1 are 1D and have same length
# clean_2 and denoised_2 are 1D and have same length
# however clean_1 and clean_2 might have different lengths
# we pad to match the lengths and allow batched processing
max_length = max(clean_1.shape[-1], clean_2.shape[-1])
clean_1 = np.pad(clean_1, (0, max_length - clean_1.shape[-1]))
clean_2 = np.pad(clean_2, (0, max_length - clean_2.shape[-1]))
denoised_1 = np.pad(denoised_1, (0, max_length - denoised_1.shape[-1]))
denoised_2 = np.pad(denoised_2, (0, max_length - denoised_2.shape[-1]))
# make the batch
clean = np.stack([clean_1, clean_2])
denoised = np.stack([denoised_1, denoised_2])
# store original lengths
lengths = [clean_1.shape[-1], clean_2.shape[-1]]
# compute stoi
d = stoi(clean, denoised, fs, extended=False, lengths=lengths)
References
- [1] C. H. Taal, R. C. Hendriks, R. Heusdens and J. Jensen, "A short-time objective intelligibility measure for time-frequency weighted noisy speech", Proc. ICASSP, 2010.
- [2] C. H. Taal, R. C. Hendriks, R. Heusdens and J. Jensen, "An Algorithm for Intelligibility Prediction of Time–Frequency Weighted Noisy Speech", IEEE Trans. Audio, Speech, and Language Process., 2011.
- [3] J. Jensen and C. H. Taal, "An Algorithm for Predicting the Intelligibility of Speech Masked by Modulated Noise Maskers", IEEE/ACM Trans Audio, Speech, and Language Process., 2016.
Metadata
Release files for batch-pystoi 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| batch_pystoi-0.0.3.tar.gz | 11.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| batch_pystoi-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.3 kB
Release files / batch_pystoi-0.0.3.tar.gz
| Download URL | batch_pystoi-0.0.3.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
99f72805a397faff117e78e1e8835a33b29a70fa9074069bdb26355176677e26
|
|
BLAKE2b-256 checksum How to use checksums |
153d3d67b57b1aa023dfa52a9f58eeb862c2b94133939ef93e213ee6448c2a47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.18
|
Release files / batch_pystoi-0.0.3-py3-none-any.whl
| Download URL | batch_pystoi-0.0.3-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
66cbbb99b9bebdab922bec99c6c11775eedb379e188fd383947b19697b461035
|
|
BLAKE2b-256 checksum How to use checksums |
a7d3f8d3ed2a81133cde21ba14276a186fff0f279f44cede20b0294dc167f821
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.18
|
Security for batch-pystoi 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.