Provides the FilterbankProcessor class to extract filterbank features

Extract mel-filterbank features from an audio signal. Use the Kaldi implementation (see [kaldi-fbank]).

Audio —> FilterbankProcessor —> Features


>>> from import Audio
>>> from shennong.processor.filterbank import FilterbankProcessor
>>> audio = Audio.load('./test/data/test.wav')

Initialize the filterbank processor with some options and compute the features:

>>> processor = FilterbankProcessor(sample_rate=audio.sample_rate)
>>> processor.use_energy = False
>>> fbank = processor.process(audio)
>>> fbank.shape
(140, 23)

Using energy adds a column to the output:

>>> processor.use_energy = True
>>> fbank = processor.process(audio)
>>> fbank.shape
(140, 24)



class shennong.processor.filterbank.FilterbankProcessor(sample_rate=16000, frame_shift=0.01, frame_length=0.025, dither=1.0, preemph_coeff=0.97, remove_dc_offset=True, window_type='povey', round_to_power_of_two=True, blackman_coeff=0.42, snip_edges=True, num_bins=23, low_freq=20, high_freq=0, vtln_low=100, vtln_high=- 500, use_energy=False, energy_floor=0.0, raw_energy=True, htk_compat=False, use_log_fbank=True, use_power=True)[source]

Bases: shennong.processor.base.MelFeaturesProcessor

Mel-filterbank features

property name

Name of the processor

property blackman_coeff

Constant coefficient for generalized Blackman window

Used only if window_type is ‘blackman’

property dither

Amount of dithering

0.0 means no dither

property frame_length

Frame length in seconds

property frame_shift

Frame shift in seconds


Get parameters for this processor.


deep (boolean, optional) – If True, will return the parameters for this processor and contained subobjects that are processors. Default to True.


params (mapping of string to any) – Parameter names mapped to their values.


Return the processors properties as a dictionary

property high_freq

High cutoff frequency for mel bins in Hertz

If high_freq < 0, offset from the Nyquist frequency

property log

Processor logger

property low_freq

Low cutoff frequency for mel bins in Hertz

property num_bins

Number of triangular mel-frequency bins

The minimal number of bins is 3

property preemph_coeff

Coefficient for use in signal preemphasis

process(signal, vtln_warp=1.0)

Compute features with the specified options

Do an optional feature-level vocal tract length normalization (VTLN) when vtln_warp != 1.0.

  • signal (Audio, shape = [nsamples, 1]) – The input audio signal to compute the features on, must be mono

  • vtln_warp (float, optional) – The VTLN warping factor to be applied when computing features. Be 1.0 by default, meaning no warping is to be done.


features (Features, shape = [nframes, ndims]) – The computed features, output will have as many rows as there are frames (depends on the specified options frame_shift and frame_length).


ValueError – If the input signal has more than one channel (i.e. is not mono). If sample_rate != signal.sample_rate.

process_all(utterances, njobs=None, **kwargs)

Returns features processed from several input utterances

This function processes the features in parallel jobs.

  • 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.


features (FeaturesCollection) – The computed features on each input signal. The keys of output features are the keys of the input utterances.


ValueError – If the njobs parameter is <= 0 or if an entry is missing in optioanl kwargs.

property remove_dc_offset

If True, subtract mean from waveform on each frame

property round_to_power_of_two

If true, round window size to power of two

This is done by zero-padding input to FFT

property sample_rate

Waveform sample frequency in Hertz

Must match the sample rate of the signal specified in process

set_logger(level, formatter='%(levelname)s - %(name)s - %(message)s')

Change level and/or format of the processor’s logger

  • 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 By default display level and message. Use ‘%(asctime)s - %(levelname)s - %(name)s - %(message)s’ to display time, level, name and message.


Set the parameters of this processor.




ValueError – If any given parameter in params is invalid for the processor.

property snip_edges

If true, output only frames that completely fit in the file

When True the number of frames depends on the frame_length. If False, the number of frames depends only on the frame_shift, and we reflect the data at the ends.


Returns the times label for the rows given by process()

property use_energy

Add an extra dimension with energy to the filterbank output

property vtln_high

High inflection point in piecewise linear VTLN warping function

In Hertz. If vtln_high < 0, offset from high_freq

property vtln_low

Low inflection point in piecewise linear VTLN warping function

In Hertz

property window_type

Type of window

Must be ‘hamming’, ‘hanning’, ‘povey’, ‘rectangular’ or ‘blackman’

property energy_floor

Floor on energy (absolute, not relative) in filterbanks

property raw_energy

If true, compute energy before preemphasis and windowing

property htk_compat

If True, get closer to HTK filterbank features.

Put energy last.

Warning: Not sufficient to get HTK compatible features (need to change other parameters)

property use_log_fbank

If true, produce log-filterbank, else produce linear

property ndims

Dimension of the output features frames

property use_power

If true, use power, else use magnitude