Raw audio framing
Frame raw waveform samples without any processing — no dithering, preemphasis, DC offset removal or windowing (kaldi-native-fbank/csrc/feature-raw-audio-samples.h). This is useful for models that consume raw waveform chunks and want the same streaming interface as the feature extractors. There is no kaldi counterpart.
import numpy as np
import kaldi_native_fbank as knf
opts = knf.RawAudioSamplesOptions()
framer = knf.OnlineRawAudioSamples(opts)
framer.accept_waveform(16000, samples)
framer.input_finished()
chunk = framer.get_frame(0) # (dim,) raw samples of the first frame
API reference
- class kaldi_native_fbank.RawAudioSamplesOptions(self: kaldi_native_fbank.RawAudioSamplesOptions, frame_opts: kaldi_native_fbank.FrameExtractionOptions = RawAudioSamplesOptions().frame_opts)
Options for framing raw audio samples without any processing.
The default
frame_optsperforms no processing on the samples: rectangular window, no dithering, no preemphasis, no DC offset removal, no zero-padding.Construct;
frame_optsdefaults to un-processed framing.The default is a rectangular window with no dithering, preemphasis, DC offset removal or zero-padding.
- Parameters:
frame_opts -- Frame-extraction options; see
FrameExtractionOptions.
- __init__(self: kaldi_native_fbank.RawAudioSamplesOptions, frame_opts: kaldi_native_fbank.FrameExtractionOptions = RawAudioSamplesOptions().frame_opts) None
Construct;
frame_optsdefaults to un-processed framing.The default is a rectangular window with no dithering, preemphasis, DC offset removal or zero-padding.
- Parameters:
frame_opts -- Frame-extraction options; see
FrameExtractionOptions.
- as_dict(self: kaldi_native_fbank.RawAudioSamplesOptions) dict
Return the options as a dict.
- property frame_opts
Frame-extraction options; see
FrameExtractionOptions.
- static from_dict(arg0: dict) kaldi_native_fbank.RawAudioSamplesOptions
Build options from a dict.
- class kaldi_native_fbank.OnlineRawAudioSamples(self: kaldi_native_fbank.OnlineRawAudioSamples, opts: kaldi_native_fbank.RawAudioSamplesOptions)
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.OnlineRawAudioSamples, opts: kaldi_native_fbank.RawAudioSamplesOptions) 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.OnlineRawAudioSamples, 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.OnlineRawAudioSamples) 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.OnlineRawAudioSamples, 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.OnlineRawAudioSamples, n: SupportsInt) None
Discard the first
nframes.- Parameters:
n -- Number of frames to discard.