Fbank
Filter-bank features, kaldi-compatible (kaldi-native-fbank/csrc/feature-fbank.h). Numerically equal to kaldi's compute-fbank-feats for identical parameters.
Usage
import kaldi_native_fbank as knf
opts = knf.FbankOptions()
opts.frame_opts.samp_freq = 16000
opts.frame_opts.snip_edges = True
opts.frame_opts.dither = 0.0
opts.mel_opts.num_bins = 23
opts.mel_opts.low_freq = 20
opts.mel_opts.high_freq = 7800
opts.use_energy = False
opts.use_log_fbank = True
opts.use_power = True
fbank = knf.OnlineFbank(opts)
fbank.accept_waveform(16000, samples)
fbank.input_finished()
frame = fbank.get_frame(0) # dim = num_bins
Equivalent in kaldi
# kaldi
compute-fbank-feats --dither=0.0 --num-mel-bins=23 --low-freq=20 \\
--high-freq=7800 --sample-frequency=16000 --snip-edges=true \\
scp:wav.scp ark:fbank.ark
Mapping
kaldi option |
python API |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
API reference
- class kaldi_native_fbank.FbankOptions(self: kaldi_native_fbank.FbankOptions, frame_opts: kaldi_native_fbank.FrameExtractionOptions = FrameExtractionOptions(), mel_opts: kaldi_native_fbank.MelBanksOptions = MelBanksOptions(num_bins=23), use_energy: bool = False, energy_floor: SupportsFloat = 0, raw_energy: bool = True, htk_compat: bool = False, use_log_fbank: bool = True, use_log_floor: bool = True, eps: SupportsFloat = 1.1920929e-07, use_power: bool = True)
Options for computing filter-bank features.
This is kaldi's FbankOptions. It only includes things that can be done in a "stateless" way: it does not include energy max-normalization and it does not include delta computation.
See also
FrameExtractionOptionsFrame extraction settings (
frame_opts).MelBanksOptionsMel filter-bank settings (
mel_opts).kaldi_native_fbank.OnlineFbankThe streaming extractor that consumes these options.
Construct with the given options.
All fields are optional keyword arguments; the defaults are shown in the signature.
- Parameters:
frame_opts -- Frame-extraction options; see
FrameExtractionOptions.mel_opts -- Mel filter-bank options (default 23 bins); see
MelBanksOptions.use_energy -- Append an extra energy dimension to the filter banks.
energy_floor -- Absolute floor on energy (only with use_energy; needed when dither is 0).
raw_energy -- Compute energy before preemphasis/windowing (only with use_energy).
htk_compat -- Put energy last instead of first (only with use_energy).
use_log_fbank -- Produce log-filterbank (True) or linear (False).
use_log_floor -- Use kaldi's hard floor (True) or the additive NeMo guard (False).
eps -- Value of the log-zero guard (default FLT_EPSILON).
use_power -- Use power (True) or magnitude (False) in the analysis.
- __init__(self: kaldi_native_fbank.FbankOptions, frame_opts: kaldi_native_fbank.FrameExtractionOptions = FrameExtractionOptions(), mel_opts: kaldi_native_fbank.MelBanksOptions = MelBanksOptions(num_bins=23), use_energy: bool = False, energy_floor: SupportsFloat = 0, raw_energy: bool = True, htk_compat: bool = False, use_log_fbank: bool = True, use_log_floor: bool = True, eps: SupportsFloat = 1.1920929e-07, use_power: bool = True) None
Construct with the given options.
All fields are optional keyword arguments; the defaults are shown in the signature.
- Parameters:
frame_opts -- Frame-extraction options; see
FrameExtractionOptions.mel_opts -- Mel filter-bank options (default 23 bins); see
MelBanksOptions.use_energy -- Append an extra energy dimension to the filter banks.
energy_floor -- Absolute floor on energy (only with use_energy; needed when dither is 0).
raw_energy -- Compute energy before preemphasis/windowing (only with use_energy).
htk_compat -- Put energy last instead of first (only with use_energy).
use_log_fbank -- Produce log-filterbank (True) or linear (False).
use_log_floor -- Use kaldi's hard floor (True) or the additive NeMo guard (False).
eps -- Value of the log-zero guard (default FLT_EPSILON).
use_power -- Use power (True) or magnitude (False) in the analysis.
- as_dict(self: kaldi_native_fbank.FbankOptions) dict
Return the options as a dict.
- property energy_floor
Floor on energy (absolute, not relative). Active only if
use_energyis True; only necessary ifframe_opts.ditheris 0. Suggested values: 0.1 or 1.0.
- property eps
Value of the log-zero guard selected by
use_log_floor; defaults toFLT_EPSILON(NeMo models useFLT_EPSILON / 2).
- property frame_opts
Frame-extraction options; see
FrameExtractionOptions.
- static from_dict(arg0: dict) kaldi_native_fbank.FbankOptions
Build options from a dict.
- property htk_compat
If True, put energy last instead of first. Active only if
use_energyis True. Warning: not sufficient for HTK-compatible features (other parameters must change too).
- property mel_opts
Mel filter-bank options; see
MelBanksOptions. The default has 23 mel bins.
- property raw_energy
If True, compute log energy before preemphasis and windowing; if False, after. Active only if
use_energyis True.
- property use_energy
If True, append an extra dimension with energy to the filter banks.
- property use_log_fbank
If True (default), produce log-filterbank; else linear.
- property use_log_floor
If True (default), use kaldi's hard floor
log(max(e, eps)); if False, the additive guardlog(e + eps)used by NeMo models.
- property use_power
If True (default), use power in the filterbank analysis; else magnitude.
- class kaldi_native_fbank.OnlineFbank(self: kaldi_native_fbank.OnlineFbank, opts: kaldi_native_fbank.FbankOptions)
Construct from the options of the wrapped feature computer.
- Parameters:
opts -- Options of the computer, e.g.
FbankOptionsforkaldi_native_fbank.OnlineFbank.
- __init__(self: kaldi_native_fbank.OnlineFbank, opts: kaldi_native_fbank.FbankOptions) None
Construct from the options of the wrapped feature computer.
- Parameters:
opts -- Options of the computer, e.g.
FbankOptionsforkaldi_native_fbank.OnlineFbank.
- accept_waveform(self: kaldi_native_fbank.OnlineFbank, sampling_rate: SupportsFloat, waveform: collections.abc.Sequence[SupportsFloat]) None
Add more waveform samples.
- Parameters:
sampling_rate -- The sampling rate of
waveform; must match the rate in the options.waveform -- 1-D float32 samples.
- property dim
The dimension of the output features.
- property frame_shift_in_seconds
The frame shift in seconds.
- get_frame(self: object, frame: SupportsInt) numpy.typing.NDArray[numpy.float32]
Return the
frame-th feature vector.- Parameters:
frame -- Frame index.
- Returns:
np.ndarray of shape
(dim,)and dtype float32. The buffer is owned by the extractor.
- input_finished(self: kaldi_native_fbank.OnlineFbank) None
Tell the extractor that no more waveform will be added.
This flushes out the last frame or two when
snip_edgesis False and also affects the return value ofis_last_frame().
- is_last_frame(self: kaldi_native_fbank.OnlineFbank, frame: SupportsInt) bool
Return true if
frameis the last frame.Note: this can only return true after
input_finished()has been called.- Parameters:
frame -- Frame index.
- Returns:
True if the frame is the last one.
- property num_frames_ready
The number of frames that have already been computed.
- pop(self: kaldi_native_fbank.OnlineFbank, n: SupportsInt) None
Discard the first
nframes.- Parameters:
n -- Number of frames to discard.