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.processor.mfcc import MfccProcessor
>>> from shennong.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.postprocessor.delta.
DeltaPostProcessor
(order=2, window=2)[source]¶ Bases:
shennong.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.
-
property
log
¶ Processor logger
-
process_all
(utterances, njobs=None, **kwargs)¶ Returns features processed from several input utterances
This function processes the features in parallel jobs.
- Parameters
utterances (:class`~shennong.uttterances.Utterances`) – The utterances on which to process features on.
njobs (int, optional) – The number of parallel jobs to run in background. Default to the number of CPU cores available on the machine.
**kwargs (dict, optional) – Extra arguments to be forwarded to the process method. Keys must be the same as for utterances.
- Returns
features (
FeaturesCollection
) – The computed features on each input signal. The keys of output features are the keys of the input utterances.- Raises
ValueError – If the njobs parameter is <= 0 or if an entry is missing in optioanl kwargs.
-
set_logger
(level, formatter='%(levelname)s - %(name)s - %(message)s')¶ Change level and/or format of the processor’s logger
- Parameters
level (str) – The minimum log level handled by the logger (any message above this level will be ignored). Must be ‘debug’, ‘info’, ‘warning’ or ‘error’.
formatter (str, optional) – A string to format the log messages, see https://docs.python.org/3/library/logging.html#formatter-objects. By default display level and message. Use ‘%(asctime)s - %(levelname)s - %(name)s - %(message)s’ to display time, level, name and message.
-
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