NeMo filter bank

NeMo-compatible buffered streaming filter-bank features (kaldi-native-fbank/csrc/online-nemo-fbank.h). NeMo buffered streaming re-featurizes each requested audio window: preemphasis, then a centered constant-zero-padded STFT, a symmetric Hann window, Slaney mel filters and \(\log(\mathrm{mel} + 2^{-24})\).

Input samples are floats in [-1, 1]; the class does not resample or normalize. There is no direct kaldi binary counterpart — this reproduces NeMo's streaming feature extraction.

import numpy as np
import kaldi_native_fbank as knf

opts = knf.NemoFbankOptions(num_mel_bins=80)
fbank = knf.OnlineNemoFbank(opts)

fbank.accept_waveform(16000, samples)   # samples in [-1, 1]
fbank.input_finished()
frames, offset = fbank.get_frames(0, fbank.num_frames_ready, is_final=True)

API reference

class kaldi_native_fbank.NemoFbankOptions(self: kaldi_native_fbank.NemoFbankOptions, samp_freq: SupportsFloat = 16000.0, frame_shift_ms: SupportsFloat = 10.0, frame_length_ms: SupportsFloat = 25.0, num_mel_bins: SupportsInt = 80, low_freq: SupportsFloat = 0, high_freq: SupportsFloat = 0, preemph_coeff: SupportsFloat = 0.97, buffered_capacity: SupportsInt = 0)

Options for OnlineNemoFbank.

See also

OnlineNemoFbank

Construct with the given options.

All fields are optional keyword arguments; the defaults are shown in the signature.

Parameters:
  • samp_freq -- Waveform sample frequency.

  • frame_shift_ms -- Frame shift in milliseconds.

  • frame_length_ms -- Frame length in milliseconds.

  • num_mel_bins -- Number of mel bins.

  • low_freq -- Lower frequency cutoff for the mel bins.

  • high_freq -- Upper cutoff; non-positive values are offsets from Nyquist.

  • preemph_coeff -- Preemphasis coefficient.

  • buffered_capacity -- Full-buffer length in frames; 0 disables the final sample-length cap.

__init__(self: kaldi_native_fbank.NemoFbankOptions, samp_freq: SupportsFloat = 16000.0, frame_shift_ms: SupportsFloat = 10.0, frame_length_ms: SupportsFloat = 25.0, num_mel_bins: SupportsInt = 80, low_freq: SupportsFloat = 0, high_freq: SupportsFloat = 0, preemph_coeff: SupportsFloat = 0.97, buffered_capacity: SupportsInt = 0) → None

Construct with the given options.

All fields are optional keyword arguments; the defaults are shown in the signature.

Parameters:
  • samp_freq -- Waveform sample frequency.

  • frame_shift_ms -- Frame shift in milliseconds.

  • frame_length_ms -- Frame length in milliseconds.

  • num_mel_bins -- Number of mel bins.

  • low_freq -- Lower frequency cutoff for the mel bins.

  • high_freq -- Upper cutoff; non-positive values are offsets from Nyquist.

  • preemph_coeff -- Preemphasis coefficient.

  • buffered_capacity -- Full-buffer length in frames; 0 disables the final sample-length cap.

as_dict(self: kaldi_native_fbank.NemoFbankOptions) → dict

Return the options as a dict.

property buffered_capacity

Full-buffer length in frames. 0 disables the final sample-length cap.

property frame_length_ms

Frame length in milliseconds.

property frame_shift_ms

Frame shift in milliseconds.

static from_dict(arg0: dict) → kaldi_native_fbank.NemoFbankOptions

Build options from a dict.

property high_freq

Upper frequency cutoff; non-positive values are offsets from Nyquist.

property low_freq

Lower frequency cutoff for the mel bins.

property num_mel_bins

Number of mel bins.

property preemph_coeff

Preemphasis coefficient.

property samp_freq

Waveform sample frequency.

class kaldi_native_fbank.OnlineNemoFbank(self: kaldi_native_fbank.OnlineNemoFbank, opts: kaldi_native_fbank.NemoFbankOptions)

NeMo-compatible buffered streaming filter-bank features.

NeMo buffered streaming re-featurizes each requested audio window: preemphasis over that window, then a centered, constant-zero-padded STFT, a symmetric Hann window, Slaney mel filters, and \(\log(\mathrm{mel} + 2^{-24})\). Input samples are floats in [-1, 1]. This class does not resample or normalize.

Construct from the given options.

Parameters:

opts -- Options; see NemoFbankOptions.

__init__(self: kaldi_native_fbank.OnlineNemoFbank, opts: kaldi_native_fbank.NemoFbankOptions) → None

Construct from the given options.

Parameters:

opts -- Options; see NemoFbankOptions.

accept_waveform(self: kaldi_native_fbank.OnlineNemoFbank, sampling_rate: SupportsFloat, waveform: collections.abc.Sequence[SupportsFloat]) → None

Add more waveform samples.

Parameters:
  • sampling_rate -- The sampling rate of waveform; must match opts.samp_freq.

  • waveform -- 1-D float32 samples in [-1, 1].

property dim

The feature dimension (number of mel bins).

property frame_shift_in_seconds

The frame shift in seconds.

get_frames(self: kaldi_native_fbank.OnlineNemoFbank, frame_index: SupportsInt, n: SupportsInt, is_final: bool = False) → tuple

Return n frames starting at the absolute frame_index.

Samples preceding the requested window are discarded; later calls cannot rewind. If is_final reaches the last ready frame after input_finished(), the partial hop is included. When n equals buffered_capacity, the window is capped at n hops by shifting its start by the remainder; that shift (in samples) is reported as the second element of the returned tuple.

Parameters:
  • frame_index -- Absolute index of the first frame to return.

  • n -- Number of frames.

  • is_final -- True if this is the final request.

Returns:

A tuple (frames, start_sample_offset) where frames is a float32 array of shape (n, dim) and start_sample_offset is 0 unless the buffer cap shifted the window.

input_finished(self: kaldi_native_fbank.OnlineNemoFbank) → None

Tell the extractor that no more waveform will be added.

is_last_frame(self: kaldi_native_fbank.OnlineNemoFbank, frame: SupportsInt) → bool

Return true if frame is the last frame; only after input_finished().

property num_frames_ready

The number of whole frames that are ready.

property num_trailing_samples

Buffered samples that do not make up a whole hop.