MCPcopy Create free account
hub / github.com/ml-explore/mlx-data / mfsc

Function mfsc

python/mlx/data/features/audio.py:162–267  ·  view source on GitHub ↗

Returns a function that computes spectrogram features from audio in particular mel-frequency spectral coefficients (MFSCs). .. note:: This feature extractor operates on mono audio provided as a 1D array. Meaning the input should have shape ``(N,)`` and not ``(N, 1)``. You may

(
    n_filterbank,
    sampling_freq,
    frame_size_ms=25,
    frame_stride_ms=10,
    pre_emphasis_coeff=0.97,
    window_type=WindowType.Hamming,
    low_freq=0,
    high_freq=-1,
    mel_floor=1.0,
    freq_scale=FrequencyScale.MEL,
    post_process=None,
)

Source from the content-addressed store, hash-verified

160
161
162def mfsc(
163 n_filterbank,
164 sampling_freq,
165 frame_size_ms=25,
166 frame_stride_ms=10,
167 pre_emphasis_coeff=0.97,
168 window_type=WindowType.Hamming,
169 low_freq=0,
170 high_freq=-1,
171 mel_floor=1.0,
172 freq_scale=FrequencyScale.MEL,
173 post_process=None,
174):
175 """Returns a function that computes spectrogram features from audio in
176 particular mel-frequency spectral coefficients (MFSCs).
177
178 .. note::
179 This feature extractor operates on mono audio provided as a 1D array.
180 Meaning the input should have shape ``(N,)`` and not ``(N, 1)``. You may
181 want to look into :meth:`~mlx.data.Buffer.squeeze` to transform arrays of shape
182 ``(N, 1)`` to ``(N,)``.
183
184 The featurization function
185
186 1. computes a sliding window of the input audio
187 2. applies a pre-emphasis filter
188 3. applies a windowing function
189 4. computes the power spectrum
190 5. computes triangular filterbank features
191 6. compute the log of the features
192 7. apply any post processing function that may be provided
193
194 The following example loads the librispeech dataset and computes MFSC
195 features:
196
197 .. code-block:: python
198
199 from mlx.data.datasets import load_librispeech
200 from mlx.data.features import mfsc
201
202 dset = (
203 load_librispeech()
204 .squeeze("audio")
205 .key_transform("audio", mfsc(80, 16000))
206 .to_stream()
207 .prefetch(16, 8)
208 .batch(16)
209 .prefetch(2, 1)
210 )
211
212 Args:
213 n_filterbank (int): How many frequency bands to use. This number will
214 be the dimensionality of the resulting features.
215 sampling_freq (int): The sampling frequency of the input audio in Hz.
216 frame_size_ms (int): Each output feature will correspond to that many
217 milliseconds of input audio. (default: 25)
218 frame_stride_ms (int): Two consecutive features will correspond to
219 audio windows that are that many milliseconds apart. (default: 10)

Callers 1

iterateFunction · 0.90

Calls 7

num_sample_per_frameFunction · 0.85
next_pow_2Function · 0.85
pre_emphasisFunction · 0.85
windowingFunction · 0.85
power_spectrumFunction · 0.85
tri_filterbankFunction · 0.85
sliding_windowFunction · 0.70

Tested by

no test coverage detected