Class SpectralFeatureExtractor<T>
Extracts spectral features from audio signals including centroid, bandwidth, rolloff, and flux.
public class SpectralFeatureExtractor<T> : AudioFeatureExtractorBase<T>, IAudioFeatureExtractor<T>
Type Parameters
TThe numeric type used for calculations.
- Inheritance
-
SpectralFeatureExtractor<T>
- Implements
- Inherited Members
Remarks
Spectral features describe the shape and characteristics of an audio signal's frequency content. They are widely used for audio classification, music analysis, and speech processing.
For Beginners: These features describe "what the sound looks like" in terms of frequency:
- Spectral Centroid: The "center of mass" of the spectrum - high for bright sounds (cymbals), low for dull sounds (bass drum). Think of it as the "brightness" of the sound.
- Spectral Bandwidth: How spread out the frequencies are. Wide for rich sounds (orchestra), narrow for pure tones (flute).
- Spectral Rolloff: The frequency below which most (e.g., 85%) of the energy is concentrated. Useful for distinguishing voiced from unvoiced speech.
- Spectral Flux: How much the spectrum changes between frames. High during transients (drum hits), low during sustained sounds.
- Spectral Flatness: How "noisy" vs "tonal" the sound is. 1.0 = pure noise, 0.0 = pure tone.
Usage:
var extractor = new SpectralFeatureExtractor<float>();
var features = extractor.Extract(audioTensor);
// features.Shape = [numFrames, numFeatures]
Constructors
SpectralFeatureExtractor(SpectralFeatureOptions?)
Initializes a new spectral feature extractor.
public SpectralFeatureExtractor(SpectralFeatureOptions? options = null)
Parameters
optionsSpectralFeatureOptionsSpectral feature extraction options.
Properties
FeatureDimension
Gets the number of features produced per frame.
public override int FeatureDimension { get; }
Property Value
Name
Gets the name of this feature extractor.
public override string Name { get; }
Property Value
Methods
Extract(Tensor<T>)
Extracts features from an audio waveform.
public override Tensor<T> Extract(Tensor<T> audio)
Parameters
audioTensor<T>The audio waveform as a 1D tensor [samples].
Returns
- Tensor<T>
Features as a 2D tensor [frames, features].
GetFeatureIndex(SpectralFeatureType)
Gets the column index for a specific feature type in the extracted feature tensor.
public int GetFeatureIndex(SpectralFeatureType featureType)
Parameters
featureTypeSpectralFeatureTypeThe feature type to find the index for.
Returns
- int
The column index of the feature in the output tensor, or -1 if the feature is not enabled.
Remarks
Feature indices depend on which features are enabled. For example, if only Flux and Flatness are enabled, Flux will be at index 0 and Flatness at index 1. With Basic features (Centroid, Bandwidth, Rolloff, Flux, Flatness), Flux will be at index 3.