Delta features¶
Compute time derivatives on existing features
Uses the Kaldi implementation (see [kaldi-delta]):
Examples
>>> import numpy as np
>>> from shennong.audio import Audio
>>> from shennong.features.processor.mfcc import MfccProcessor
>>> from shennong.features.postprocessor.delta import DeltaPostProcessor
>>> audio = Audio.load('./test/data/test.wav')
>>> mfcc = MfccProcessor().process(audio)
Initialize the delta processor and compute first and second order time derivatives of MFCC features:
>>> processor = DeltaPostProcessor(order=2)
>>> delta = processor.process(mfcc)
The resulting matrice is the concatenation of the original features, their first and second order derivatives:
>>> nmfcc = mfcc.shape[1]
>>> delta.shape[1] == nmfcc * 3
True
>>> original = delta.data[:, :nmfcc]
>>> np.array_equal(original, mfcc.data)
True
>>> first_order = delta.data[:, nmfcc:2*nmfcc]
>>> second_order = delta.data[:, 2*nmfcc:]
>>> original.shape == first_order.shape == second_order.shape
True
References
-
class
shennong.features.postprocessor.delta.
DeltaPostProcessor
(order=2, window=2)[source]¶ Bases:
shennong.features.postprocessor.base.FeaturesPostProcessor
-
property
name
¶ Name of the processor
-
property
order
¶ Order of delta computation
-
get_params
(deep=True)¶ Get parameters for this processor.
- Parameters
deep (boolean, optional) – If True, will return the parameters for this processor and contained subobjects that are processors. Default to True.
- Returns
params (mapping of string to any) – Parameter names mapped to their values.
-
process_all
(signals, njobs=None)¶ Returns features processed from several input signals
This function processes the features in parallel jobs.
- Parameters
signals (dict of :class`~shennong.audio.Audio`) – A dictionnary of input audio signals to process features on, where the keys are item names and values are audio signals.
njobs (int, optional) – The number of parallel jobs to run in background. Default to the number of CPU cores available on the machine.
- Returns
features (
FeaturesCollection
) – The computed features on each input signal. The keys of output features are the keys of the input signals.- Raises
ValueError – If the njobs parameter is <= 0
-
set_params
(**params)¶ Set the parameters of this processor.
- Returns
self
- Raises
ValueError – If any given parameter in
params
is invalid for the processor.
-
property
window
¶ Parameter controlling window for delta computation
The actual window size for each delta order is 1 + 2 * window. The behavior at the edges is to replicate the first or last frame.
-
property
ndims
¶ Dimension of the output features frames
-
process
(features)[source]¶ Compute deltas on features with the specified options
- Parameters
features (Features, shape = [nframes, ncols]) – The input features on which to compute the deltas
- Returns
deltas (Features, shape = [nframes, ncols * (order + 1)]) – The computed deltas with as much orders as specified. The output features are the concatenation of the input features and it’s time derivative at each orders.
-
property