kaldi-native-fbank C++ API
Kaldi-compatible feature extraction C++ API
Loading...
Searching...
No Matches
online-feature.h
Go to the documentation of this file.
1
23
33
34#ifndef KALDI_NATIVE_FBANK_CSRC_ONLINE_FEATURE_H_
35#define KALDI_NATIVE_FBANK_CSRC_ONLINE_FEATURE_H_
36
37#include <cstdint>
38#include <deque>
39#include <vector>
40
46
47namespace knf {
48
60 public:
62 explicit RecyclingVector(int32_t items_to_hold = -1);
63
65 ~RecyclingVector() = default;
66
69
72
76 const float *At(int32_t index) const;
77
80 void PushBack(std::vector<float> item);
81
85 int32_t Size() const;
86
88 void Pop(int32_t n);
89
90 private:
91 std::deque<std::vector<float>> items_;
92 int32_t items_to_hold_;
93 int32_t first_available_index_ = 0;
94};
95
106template <class C>
108 public:
110 explicit OnlineGenericBaseFeature(const typename C::Options &opts);
111
113 int32_t Dim() const { return computer_.Dim(); }
114
116 float FrameShiftInSeconds() const {
117 return computer_.GetFrameOptions().frame_shift_ms / 1000.0f;
118 }
119
121 int32_t NumFramesReady() const { return features_.Size(); }
122
127 bool IsLastFrame(int32_t frame) const {
128 return input_finished_ && frame == NumFramesReady() - 1;
129 }
130
134 const float *GetFrame(int32_t frame) const { return features_.At(frame); }
135
146 void AcceptWaveform(float sampling_rate, const float *waveform, int32_t n);
147
153
155 void Pop(int32_t n) { features_.Pop(n); }
156
157 private:
165 void ComputeFeatures();
166
167 C computer_;
168
169 FeatureWindowFunction window_function_;
170
172 RecyclingVector features_;
173
174 bool input_finished_ =
175 false;
176
179 int64_t waveform_offset_ = 0;
180
184 std::vector<float> waveform_remainder_;
185};
186
189
192
195
198
199} // namespace knf
200
201#endif // KALDI_NATIVE_FBANK_CSRC_ONLINE_FEATURE_H_
Stores the windowing coefficients and applies them to a frame.
Definition feature-window.h:156
This is a templated class for online feature extraction; it's templated on a class like MfccComputer ...
Definition online-feature.h:107
void InputFinished()
InputFinished() tells the class you won't be providing any more waveform.
OnlineGenericBaseFeature(const typename C::Options &opts)
Construct from the options class of the wrapped computer C.
int32_t NumFramesReady() const
Return the number of frames that are already computed.
Definition online-feature.h:121
const float * GetFrame(int32_t frame) const
Return a pointer to the frame-th feature vector.
Definition online-feature.h:134
void Pop(int32_t n)
Discard the first n frames.
Definition online-feature.h:155
float FrameShiftInSeconds() const
Return the frame shift in seconds.
Definition online-feature.h:116
void AcceptWaveform(float sampling_rate, const float *waveform, int32_t n)
This would be called from the application, when you get more wave data.
bool IsLastFrame(int32_t frame) const
Return true if frame is the last frame.
Definition online-feature.h:127
int32_t Dim() const
Return the dimension of the output features.
Definition online-feature.h:113
This class serves as a storage for feature vectors with an option to limit the memory usage by removi...
Definition online-feature.h:59
int32_t Size() const
This method returns the size as if no "recycling" had happened, i.e.
~RecyclingVector()=default
Destructor.
void PushBack(std::vector< float > item)
Append one feature vector to the end.
RecyclingVector(int32_t items_to_hold=-1)
By default it does not remove any elements.
RecyclingVector & operator=(const RecyclingVector &)=delete
Assignment is not allowed.
RecyclingVector(const RecyclingVector &)=delete
Copy construction is not allowed.
void Pop(int32_t n)
Discard the first n frames.
const float * At(int32_t index) const
Return a pointer to the feature vector at the given index.
Copyright 2009-2012 Karel Vesely 2016 Johns Hopkins University (author: Daniel Povey) Copyright (c) 2...
Copyright 2009-2011 Karel Vesely; Petr Motlicek; Saarland University 2014-2016 Johns Hopkins Universi...
Copyright (c) 2025 Xiaomi Corporation (authors: Fangjun Kuang).
Waveform windowing and frame extraction.
This file is part of kaldi-native-fbank.
Definition feature-cmvn.h:42
OnlineGenericBaseFeature< RawAudioSamplesComputer > OnlineRawAudioSamples
Streaming raw audio samples, framed without any processing.
Definition online-feature.h:188
OnlineGenericBaseFeature< MfccComputer > OnlineMfcc
Streaming MFCC features; see MfccComputer.
Definition online-feature.h:194
OnlineGenericBaseFeature< FbankComputer > OnlineFbank
Streaming filter-bank features; see FbankComputer.
Definition online-feature.h:191
OnlineGenericBaseFeature< WhisperFeatureComputer > OnlineWhisperFbank
Streaming Whisper log-mel features; see WhisperFeatureComputer.
Definition online-feature.h:197
Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang).