Whisper Fbank

Whisper-style log-mel features (kaldi-native-fbank/csrc/whisper-feature.h).

import kaldi_native_fbank as knf

opts = knf.WhisperFeatureOptions()
f = knf.OnlineWhisperFbank(opts)
f.accept_waveform(16000, samples)
f.input_finished()
frame = f.get_frame(0)

Note: whisper features follow OpenAI Whisper's front-end, not kaldi; there is no kaldi binary counterpart to compare against.

API reference

class kaldi_native_fbank.WhisperFeatureOptions(self: kaldi_native_fbank.WhisperFeatureOptions, frame_opts: kaldi_native_fbank.FrameExtractionOptions = FrameExtractionOptions(), dim: SupportsInt = 80)

Options for computing Whisper mel features.

Note that most fields of frame_opts are ignored and reset inside WhisperFeatureComputer: 16 kHz sampling rate, 25 ms window, 10 ms shift, "hann" window, snip_edges=False, etc.

Construct with the given frame options and number of mel bins.

Parameters:
  • frame_opts -- Frame options (mostly ignored and reset by the computer).

  • dim -- Number of mel bins: 80 for most Whisper models, 128 for Whisper large v3.

__init__(self: kaldi_native_fbank.WhisperFeatureOptions, frame_opts: kaldi_native_fbank.FrameExtractionOptions = FrameExtractionOptions(), dim: SupportsInt = 80) → None

Construct with the given frame options and number of mel bins.

Parameters:
  • frame_opts -- Frame options (mostly ignored and reset by the computer).

  • dim -- Number of mel bins: 80 for most Whisper models, 128 for Whisper large v3.

as_dict(self: kaldi_native_fbank.WhisperFeatureOptions) → dict

Return the options as a dict.

property dim

Number of mel bins: 80 for most Whisper models, 128 for Whisper large v3.

property frame_opts

Frame-extraction options (mostly ignored and reset by the computer).

static from_dict(arg0: dict) → kaldi_native_fbank.WhisperFeatureOptions

Build options from a dict.

class kaldi_native_fbank.OnlineWhisperFbank(self: kaldi_native_fbank.OnlineWhisperFbank, opts: kaldi_native_fbank.WhisperFeatureOptions)

Construct from the options of the wrapped feature computer.

Parameters:

opts -- Options of the computer, e.g. FbankOptions for kaldi_native_fbank.OnlineFbank.

__init__(self: kaldi_native_fbank.OnlineWhisperFbank, opts: kaldi_native_fbank.WhisperFeatureOptions) → None

Construct from the options of the wrapped feature computer.

Parameters:

opts -- Options of the computer, e.g. FbankOptions for kaldi_native_fbank.OnlineFbank.

accept_waveform(self: kaldi_native_fbank.OnlineWhisperFbank, 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.OnlineWhisperFbank) → None

Tell the extractor that no more waveform will be added.

This flushes out the last frame or two when snip_edges is False and also affects the return value of is_last_frame().

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

Return true if frame is 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.OnlineWhisperFbank, n: SupportsInt) → None

Discard the first n frames.

Parameters:

n -- Number of frames to discard.