Registry / ai-ml / python-speech-features

python-speech-features

JSON →
library0.6pypypi✓ verified 26d ago

python-speech-features is a Python library designed for extracting common speech features used in Automatic Speech Recognition (ASR). It provides functionalities to compute Mel-Frequency Cepstral Coefficients (MFCCs), filterbank energies, log filterbank energies, and spectral subband centroids. The current stable version on PyPI is 0.6, last released in 2017, with a slightly newer v0.6.1 tag on its GitHub repository from 2020. The project maintains a slow release cadence, but its core functionalities remain widely used for fundamental speech feature extraction.

pip install python-speech-features
INSTALL
IMPORT
SIG · PYTHON-SPEECH-FEAT
P
python-speech-features
ai-mlpythonv0.6
Install
2.4s avg
Import
—
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.6 · pip install
no network on importno background threads
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.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 2.4s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

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

mfcc
✓ from python_speech_features import mfcc
✗ from python_speech_features import mfcc
fbank
✓ from python_speech_features import fbank
logfbank
✓ from python_speech_features import logfbank

This quickstart demonstrates how to generate a simple audio signal, save it as a WAV file, and then use `python-speech-features` to extract both Mel-Frequency Cepstral Coefficients (MFCCs) and log Mel-filterbank energies. It uses `scipy.io.wavfile` to handle audio file I/O.

import numpy as np from scipy.io import wavfile from python_speech_features import mfcc, logfbank import os # Create a dummy WAV file for demonstration samplerate = 16000 # Hz duration = 1 # seconds f_hz = 440 # A4 note t = np.linspace(0., duration, int(samplerate * duration)) signal = 0.5 * np.sin(2 * np.pi * f_hz * t) # Scale to 16-bit integer for WAV file wav_signal = (signal * 32767).astype(np.int16) dummy_wav_filename = 'dummy_audio.wav' wavfile.write(dummy_wav_filename, samplerate, wav_signal) # Read the audio file (rate, sig) = wavfile.read(dummy_wav_filename) # Compute MFCC features mfcc_feat = mfcc(sig, rate) print(f"MFCC features shape: {mfcc_feat.shape}") # Compute Log Filterbank energies fbank_feat = logfbank(sig, rate) print(f"Log Filterbank features shape: {fbank_feat.shape}") # Clean up the dummy file os.remove(dummy_wav_filename)
Debug
Known issues
gotchaThe PyPI version (0.6, last updated Aug 2017) is older than the latest tag on GitHub (v0.6.1, Jan 2020). Users installing via `pip install python-speech-features` might not get the absolute latest code, which could have minor fixes or changes not yet reflected on PyPI.
fix
For the very latest version, consider installing directly from the GitHub repository: `pip install git+https://github.com/jameslyons/python_speech_features.git`.
affects: <=0.6 on PyPI
gotchaWhen integrating with other audio processing libraries like `librosa`, be aware of data type expectations. `scipy.io.wavfile.read` typically returns `int16` samples, while some libraries might expect `float32`. Additionally, MFCC computation methodologies can differ between libraries (e.g., `python-speech-features` uses Discrete Fourier Transform, `librosa` uses Short-Time Fourier Transform), leading to different output shapes or values for seemingly identical parameters.
fix
Explicitly convert signal data types (e.g., `signal.astype(np.float32)`) if required by other libraries. Consult the documentation of both `python-speech-features` and any other library being used for parameter details and expected outputs. Be mindful that `numcep` is effectively capped by `nfilt` in `python-speech-features`.
affects: All versions
gotchaA common warning, `WARNING:root:frame length (X) is greater than FFT size`, can occur if the product of `winlen` (window length in seconds) and `samplerate` (frame length in samples) exceeds `nfft` (FFT size).
fix
Ensure that `nfft` is greater than or equal to `winlen * samplerate`. For example, if `winlen=0.025` and `samplerate=16000`, the frame length is 400 samples. `nfft` should be set to 512, 1024, or a higher power of 2 that accommodates this length.
affects: All versions
Upgrade
Version history
0.6latest on PyPI · released Aug 16, 2017
Audit
Dependencies
numpyrequiredRequired for numerical operations and array manipulation of audio signals and features.
scipyrequiredRequired for scientific computing, particularly for I/O operations like reading WAV files (scipy.io.wavfile).
Agent activity
20 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
python-speech-features — pip install python-speech-features · libregistry