35 std::vector<Vector<BaseFloat>* > cached_frames;
47 output->
Resize(cached_frames.size(), dim);
48 for (
int32 i = 0;
i < cached_frames.size();
i++) {
50 delete cached_frames[
i];
52 cached_frames.clear();
58 std::vector<int32> *piece_dim,
62 piece_dim->resize(num_pieces, 0);
64 int32 dim_mean = wav_dim / (num_pieces * 2);
68 for (
int32 i = 0;
i < num_pieces - 1;
i++) {
69 (*piece_dim)[
i] = dim_mean + rand() % dim_mean;
70 dim_total += (*piece_dim)[
i];
72 (*piece_dim)[num_pieces - 1] = wav_dim - dim_total;
74 if (dim_total > 0 && dim_total < wav_dim)
84 int32 dim = 2 + rand() % 5;
85 int32 num_frames = 100 + rand() % 100;
98 int32 dim = 2 + rand() % 5;
99 int32 num_frames = 100 + rand() % 100;
101 opts.
order = rand() % 3;
102 opts.
window = 1 + rand() % 3;
107 input_feats.SetRandn();
122 int32 dim = 2 + rand() % 5;
123 int32 num_frames = 100 + rand() % 100;
131 input_feats.SetRandn();
137 GetOutput(&splice_frame, &output_feats1);
147 std::ifstream is(
"../feat/test_data/test.wav", std::ios_base::binary);
156 op.frame_opts.preemph_coeff = 0.0;
157 op.frame_opts.window_type =
"hamming";
158 op.frame_opts.remove_dc_offset =
false;
159 op.frame_opts.round_to_power_of_two =
true;
160 op.frame_opts.samp_freq = wave.
SampFreq();
161 op.mel_opts.low_freq = 0.0;
162 op.htk_compat =
false;
163 op.use_energy =
false;
165 op.frame_opts.snip_edges =
false;
170 mfcc.
Compute(waveform, 1.0, &mfcc_feats);
175 for (
int32 num_piece = 5; num_piece < 10; num_piece++) {
177 std::vector<int32> piece_length(num_piece, 0);
179 bool ret =
RandomSplit(waveform.Dim(), &piece_length, num_piece);
182 int32 offset_start = 0;
183 for (
int32 i = 0;
i < num_piece;
i++) {
185 waveform.Range(offset_start, piece_length[
i]));
187 offset_start += piece_length[
i];
192 GetOutput(&online_mfcc, &online_mfcc_feats);
199 std::ifstream is(
"../feat/test_data/test.wav", std::ios_base::binary);
208 op.frame_opts.preemph_coeff = 0.0;
209 op.frame_opts.window_type =
"hamming";
210 op.frame_opts.remove_dc_offset =
false;
211 op.frame_opts.round_to_power_of_two =
true;
212 op.frame_opts.samp_freq = wave.
SampFreq();
213 op.mel_opts.low_freq = 0.0;
214 op.htk_compat =
false;
215 op.use_energy =
false;
220 plp.
Compute(waveform, 1.0, &plp_feats);
225 for (
int32 num_piece = 5; num_piece < 10; num_piece++) {
227 std::vector<int32> piece_length(num_piece);
228 bool ret =
RandomSplit(waveform.Dim(), &piece_length, num_piece);
231 int32 offset_start = 0;
232 for (
int32 i = 0;
i < num_piece;
i++) {
234 waveform.Range(offset_start, piece_length[
i]));
236 offset_start += piece_length[
i];
241 GetOutput(&online_plp, &online_plp_feats);
248 std::ifstream is(
"../feat/test_data/test.wav", std::ios_base::binary);
257 op.frame_opts.preemph_coeff = 0.0;
258 op.frame_opts.window_type =
"hamming";
259 op.frame_opts.remove_dc_offset =
false;
260 op.frame_opts.round_to_power_of_two =
true;
261 op.frame_opts.samp_freq = wave.
SampFreq();
262 op.mel_opts.low_freq = 0.0;
263 op.htk_compat =
false;
264 op.use_energy =
false;
284 output_feats.CopyRowFromVec(vec_tmp,
i);
291 std::ifstream is(
"../feat/test_data/test.wav", std::ios_base::binary);
300 mfcc_op.frame_opts.preemph_coeff = 0.0;
301 mfcc_op.frame_opts.window_type =
"hamming";
302 mfcc_op.frame_opts.remove_dc_offset =
false;
303 mfcc_op.frame_opts.round_to_power_of_two =
true;
304 mfcc_op.frame_opts.samp_freq = wave.
SampFreq();
305 mfcc_op.mel_opts.low_freq = 0.0;
306 mfcc_op.htk_compat =
false;
307 mfcc_op.use_energy =
false;
312 mfcc.
Compute(waveform, 1.0, &mfcc_feats);
329 plp.
Compute(waveform, 1.0, &plp_feats);
334 for (
int32 num_piece = 5; num_piece < 10; num_piece++) {
339 std::vector<int32> piece_length(num_piece);
340 bool ret =
RandomSplit(waveform.Dim(), &piece_length, num_piece);
342 int32 offset_start = 0;
343 for (
int32 i = 0;
i < num_piece;
i++) {
345 waveform.Range(offset_start, piece_length[
i]));
348 offset_start += piece_length[
i];
354 GetOutput(&online_mfcc_plp, &online_mfcc_plp_feats);
360 == online_mfcc_plp_feats.
NumCols());
364 < 0.0001*std::max(1.0, static_cast<double>(std::abs(mfcc_feats(
i,
j))
365 + std::abs(online_mfcc_plp_feats(
i,
j)))));
369 std::abs(plp_feats(
i, k) -
370 online_mfcc_plp_feats(
i, mfcc_feats.
NumCols() + k))
371 < 0.0001*std::max(1.0, static_cast<double>(std::abs(plp_feats(
i, k))
372 +std::abs(online_mfcc_plp_feats(
i, mfcc_feats.
NumCols() + k)))));
381 for (
int i = 0;
i != 100; ++
i) {
391 for (
int i = 0;
i != 100; ++
i) {
398 int caught_exceptions = 0;
399 for (
int i = 0;
i != 90; ++
i) {
402 }
catch (
const std::runtime_error &) {
410 for (
int i = 90;
i != 100; ++
i) {
420 using namespace kaldi;
421 for (
int i = 0;
i < 10;
i++) {
431 std::cout <<
"Test OK.\n";
void Read(std::istream &is)
Read() will throw on error.
This class takes a Matrix<BaseFloat> and wraps it as an OnlineFeatureInterface: this can be useful wh...
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
virtual bool IsLastFrame(int32 frame) const
Returns true if this is the last frame.
void Compute(const VectorBase< BaseFloat > &wave, BaseFloat vtln_warp, Matrix< BaseFloat > *output)
virtual void GetFrame(int32 frame, VectorBase< BaseFloat > *feat)
Gets the feature vector for this frame.
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
MfccOptions contains basic options for computing MFCC features.
void GetOutput(OnlineFeatureInterface *a, Matrix< BaseFloat > *output)
bool ApproxEqual(const MatrixBase< Real > &other, float tol=0.01) const
Returns true if ((*this)-other).FrobeniusNorm() <= tol * (*this).FrobeniusNorm(). ...
void TestOnlineMatrixCacheFeature()
BaseFloat SampFreq() const
const Matrix< BaseFloat > & Data() const
void PushBack(Vector< BaseFloat > *item)
The ownership of the item is passed to this collection - do not delete the item.
int Size() const
This method returns the size as if no "recycling" had happened, i.e.
virtual void AcceptWaveform(BaseFloat sampling_rate, const VectorBase< BaseFloat > &waveform)
This would be called from the application, when you get more wave data.
This online-feature class implements combination of two feature streams (such as pitch, plp) into one stream.
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
FrameExtractionOptions frame_opts
FrameExtractionOptions frame_opts
void TestOnlineSpliceFrames()
void TestOnlineDeltaFeature()
void SetRandn()
Sets to random values of a normal distribution.
bool RandomSplit(int32 wav_dim, std::vector< int32 > *piece_dim, int32 num_pieces, int32 trials=5)
This class serves as a storage for feature vectors with an option to limit the memory usage by removi...
virtual void InputFinished()
InputFinished() tells the class you won't be providing any more waveform.
This class's purpose is to read in Wave files.
A class representing a vector.
void TestOnlineAppendFeature()
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void ComputeDeltas(const DeltaFeaturesOptions &delta_opts, const MatrixBase< BaseFloat > &input_features, Matrix< BaseFloat > *output_features)
void Set(Real f)
Set all members of a vector to a specified value.
void SpliceFrames(const MatrixBase< BaseFloat > &input_features, int32 left_context, int32 right_context, Matrix< BaseFloat > *output_features)
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
void CopyRowFromVec(const VectorBase< Real > &v, const MatrixIndexT row)
Copy vector into specific row of matrix.
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).
OnlineFeatureInterface is an interface for online feature processing (it is also usable in the offlin...
PlpOptions contains basic options for computing PLP features.
virtual int32 Dim() const
This templated class is intended for offline feature extraction, i.e.
void ApplyAffineTransform(const MatrixBase< BaseFloat > &xform, VectorBase< BaseFloat > *vec)
Applies the affine transform 'xform' to the vector 'vec' and overwrites the contents of 'vec'...
This is a templated class for online feature extraction; it's templated on a class like MfccComputer ...
Vector< BaseFloat > * At(int index) const
The ownership is being retained by this collection - do not delete the item.
void TestRecyclingVector()
This feature type can be used to cache its input, to avoid repetition of computation in a multi-pass ...
void TestOnlineTransform()
virtual int32 NumFramesReady() const =0
returns the feature dimension.
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
virtual int32 Dim() const =0
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)