MelSpectrogramExtractor#
Defined in: voxatlas.features.acoustic.spectrogram.mel
- class voxatlas.features.acoustic.spectrogram.mel.MelSpectrogramExtractor[source]#
Bases:
BaseExtractorExtract the
acoustic.spectrogram.melfeature within the VoxAtlas pipeline.This public extractor defines the reusable API for computing
acoustic.spectrogram.melfrom VoxAtlas structured inputs. It consumesNoneunits and produces values aligned toframeunits, making the extractor a stable pipeline node that can be cited independently of the surrounding execution machinery.Algorithm#
The extractor projects an STFT magnitude spectrum onto a mel-spaced filterbank.
Spectrum dependency The upstream STFT provides \(S_{t,k}\) values and frequency bins.
Filterbank projection Each mel channel is computed as
\[M_{t,m} = \sum_k H_{m,k} S_{t,k},\]where \(H\) is the triangular mel filterbank.
Matrix packaging The mel spectrogram is returned as a matrix-valued feature aligned to the original frame grid.
Notes
This extractor declares the upstream dependencies [‘acoustic.spectrogram.stft’] and is executed only after those features are available in the pipeline feature store.
Examples
>>> import numpy as np >>> from voxatlas.audio.audio import Audio >>> from voxatlas.features.acoustic.spectrogram.mel import MelSpectrogramExtractor >>> from voxatlas.features.feature_input import FeatureInput >>> from voxatlas.features.feature_output import MatrixFeatureOutput >>> from voxatlas.pipeline.feature_store import FeatureStore >>> audio = Audio(waveform=np.zeros(800, dtype=np.float32), sample_rate=8000) >>> store = FeatureStore() >>> stft_out = MatrixFeatureOutput( ... feature="acoustic.spectrogram.stft", ... unit="frame", ... time=np.array([0.0, 0.01], dtype=np.float32), ... frequency=np.array([0.0, 2000.0, 4000.0], dtype=np.float32), ... values=np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]], dtype=np.float32), ... ) >>> store.add("acoustic.spectrogram.stft", stft_out) >>> feature_input = FeatureInput(audio=audio, units=None, context={"feature_store": store}) >>> params = MelSpectrogramExtractor.default_config.copy() >>> params["n_mels"] = 2 >>> out = MelSpectrogramExtractor().compute(feature_input, params) >>> out.values.shape (2, 2)
- name: str = 'acoustic.spectrogram.mel'#
- input_units: str | None = None#
- output_units: str | None = 'frame'#
- dependencies: list[str] = ['acoustic.spectrogram.stft']#
- default_config: dict = {'fmax': None, 'fmin': 0.0, 'frame_length': 0.025, 'frame_step': 0.01, 'n_mels': 40}#
- compute(feature_input, params)[source]#
Compute the extractor output for a single pipeline invocation.
This method is the reusable execution entry point for the extractor. It receives the standard
FeatureInputbundle, applies the configured algorithm, and returns feature values aligned to the extractor output units for storage in the pipeline feature store.- Parameters:
feature_input (object) – Structured extractor input bundling audio, hierarchical units, and execution context for this feature computation.
params (object) – Resolved feature configuration for this invocation. Keys are feature-specific and merged from defaults and pipeline settings.
- Returns:
Structured output aligned to the
frameunit level when applicable.- Return type:
FeatureOutput
Examples
>>> import numpy as np >>> from voxatlas.audio.audio import Audio >>> from voxatlas.features.acoustic.spectrogram.mel import MelSpectrogramExtractor >>> from voxatlas.features.feature_input import FeatureInput >>> from voxatlas.features.feature_output import MatrixFeatureOutput >>> from voxatlas.pipeline.feature_store import FeatureStore >>> audio = Audio(waveform=np.zeros(800, dtype=np.float32), sample_rate=8000) >>> store = FeatureStore() >>> stft_out = MatrixFeatureOutput( ... feature="acoustic.spectrogram.stft", ... unit="frame", ... time=np.array([0.0], dtype=np.float32), ... frequency=np.array([0.0, 2000.0, 4000.0], dtype=np.float32), ... values=np.array([[1.0, 0.0, 0.0]], dtype=np.float32), ... ) >>> store.add("acoustic.spectrogram.stft", stft_out) >>> feature_input = FeatureInput(audio=audio, units=None, context={"feature_store": store}) >>> params = MelSpectrogramExtractor.default_config.copy() >>> params["n_mels"] = 2 >>> result = MelSpectrogramExtractor().compute(feature_input, params) >>> result.unit 'frame'