kaldi-native-fbank C++ API
Kaldi-compatible feature extraction C++ API
Loading...
Searching...
No Matches
online-nemo-fbank.h
Go to the documentation of this file.
1
18
26
27#ifndef KALDI_NATIVE_FBANK_CSRC_ONLINE_NEMO_FBANK_H_
28#define KALDI_NATIVE_FBANK_CSRC_ONLINE_NEMO_FBANK_H_
29
30#include <cstdint>
31#include <deque>
32#include <memory>
33#include <ostream>
34#include <string>
35#include <vector>
36
39
40namespace knf {
41
45 float samp_freq = 16000;
46
48 float frame_shift_ms = 10;
49
51 float frame_length_ms = 25;
52
54 int32_t num_mel_bins = 80;
55
57 float low_freq = 0;
58
61 float high_freq = 0;
62
64 float preemph_coeff = 0.97f;
65
67 int32_t buffered_capacity = 0;
68
70 std::string ToString() const;
71};
72
74std::ostream &operator<<(std::ostream &os, const NemoFbankOptions &opts);
75
87 public:
89 explicit OnlineNemoFbank(const NemoFbankOptions &opts);
90
92 int32_t Dim() const { return opts_.num_mel_bins; }
93
95 float FrameShiftInSeconds() const { return hop_ / opts_.samp_freq; }
96
98 int32_t NumFramesReady() const { return num_samples_ / hop_; }
99
101 int32_t NumTrailingSamples() const { return num_samples_ % hop_; }
102
105 bool IsLastFrame(int32_t frame) const;
106
109 void AcceptWaveform(float sampling_rate, const float *waveform, int32_t n);
110
112 void InputFinished() { input_finished_ = true; }
113
121 std::vector<float> GetFrames(int32_t frame_index, int32_t n,
122 bool is_final = false,
123 int32_t *start_sample_offset = nullptr);
124
125 private:
126 NemoFbankOptions opts_;
127 int32_t hop_;
128 int64_t num_samples_ = 0;
129 int64_t sample_offset_ = 0;
130 bool input_finished_ = false;
131 std::deque<float> samples_;
132 std::unique_ptr<Stft> stft_;
133 std::unique_ptr<MelBanks> mel_;
134};
135
136} // namespace knf
137
138#endif // KALDI_NATIVE_FBANK_CSRC_ONLINE_NEMO_FBANK_H_
OnlineNemoFbank(const NemoFbankOptions &opts)
Construct from the given options.
int32_t Dim() const
Return the number of mel bins.
Definition online-nemo-fbank.h:92
void InputFinished()
Tell the class that no more waveform will be added.
Definition online-nemo-fbank.h:112
float FrameShiftInSeconds() const
Return the frame shift in seconds.
Definition online-nemo-fbank.h:95
int32_t NumTrailingSamples() const
Return the number of buffered samples that do not make up a whole hop.
Definition online-nemo-fbank.h:101
int32_t NumFramesReady() const
Return the number of whole frames that are ready.
Definition online-nemo-fbank.h:98
std::vector< float > GetFrames(int32_t frame_index, int32_t n, bool is_final=false, int32_t *start_sample_offset=nullptr)
Return n row-major frames starting at the absolute frame_index.
void AcceptWaveform(float sampling_rate, const float *waveform, int32_t n)
Add more waveform samples; the sampling rate must match opts.samp_freq.
bool IsLastFrame(int32_t frame) const
Return true if frame is the last frame.
Copyright 2009-2011 Phonexia s.r.o.; Microsoft Corporation 2016 Johns Hopkins University (author: Dan...
This file is part of kaldi-native-fbank.
Definition feature-cmvn.h:42
std::ostream & operator<<(std::ostream &os, const FbankOptions &opts)
Write the options to the stream, one option per line.
Copyright (c) 2025 Xiaomi Corporation (authors: Fangjun Kuang).
Options for OnlineNemoFbank.
Definition online-nemo-fbank.h:43
float samp_freq
Waveform sample frequency.
Definition online-nemo-fbank.h:45
std::string ToString() const
Return the options as a string.
int32_t num_mel_bins
Number of mel bins.
Definition online-nemo-fbank.h:54
float frame_length_ms
Frame length in milliseconds.
Definition online-nemo-fbank.h:51
float high_freq
Upper frequency cutoff for mel bins; non-positive values are offsets from Nyquist.
Definition online-nemo-fbank.h:61
float preemph_coeff
Preemphasis coefficient.
Definition online-nemo-fbank.h:64
float low_freq
Lower frequency cutoff for mel bins.
Definition online-nemo-fbank.h:57
int32_t buffered_capacity
Full-buffer length in frames. Zero disables the final sample-length cap.
Definition online-nemo-fbank.h:67
float frame_shift_ms
Frame shift in milliseconds.
Definition online-nemo-fbank.h:48