28 using namespace kaldi;
34 std::cout <<
"=== UnitTestReadWave() ===\n";
38 std::cout <<
"<<<=== Reading waveform\n";
41 std::ifstream is(
"test_data/test.wav", std::ios_base::binary);
50 std::cout <<
"<<<=== Reading Vector<BaseFloat> waveform, prepared by matlab\n";
52 "test_data/test_matlab.ascii" 55 v2.
Read(input,
false);
58 std::cout <<
"<<<=== Comparing freshly read waveform to 'libsndfile' waveform\n";
63 std::cout <<
"<<<=== Comparing done\n";
68 std::cout <<
"Test passed :)\n\n";
77 std::cout <<
"=== UnitTestSimple() ===\n";
84 v(
i) = (abs(
i * 433024253 ) % 65535) - (65535 / 2);
87 std::cout <<
"<<<=== Just make sure it runs... Nothing is compared\n";
108 std::cout <<
"Test passed :)\n\n";
113 std::cout <<
"=== UnitTestHTKCompare1() ===\n";
115 std::ifstream is(
"test_data/test.wav", std::ios_base::binary);
124 std::ifstream is(
"test_data/test.wav.fea_htk.1",
125 std::ios::in | std::ios_base::binary);
126 bool ans =
ReadHtk(is, &htk_features, 0);
146 mfcc.
Compute(waveform, 1.0, &kaldi_raw_features);
164 if ((std::abs(b - a)) > 1.0) {
167 std::cout <<
"\n\n\n[HTK-row: " <<
i <<
"] " << htk_features.Row(
i) <<
"\n";
168 std::cout <<
"[Kaldi-row: " <<
i <<
"] " << kaldi_features.
Row(
i) <<
"\n\n\n";
172 std::cout <<
"[" <<
i <<
", " <<
j <<
"]";
181 static_cast<int16
>(
sizeof(
float)*kaldi_features.
NumCols()),
185 std::ofstream os(
"tmp.test.wav.fea_kaldi.1",
186 std::ios::out|std::ios::binary);
187 WriteHtk(os, kaldi_features, header);
190 std::cout <<
"Test passed :)\n\n";
192 unlink(
"tmp.test.wav.fea_kaldi.1");
197 std::cout <<
"=== UnitTestHTKCompare2() ===\n";
199 std::ifstream is(
"test_data/test.wav", std::ios_base::binary);
208 std::ifstream is(
"test_data/test.wav.fea_htk.2",
209 std::ios::in | std::ios_base::binary);
210 bool ans =
ReadHtk(is, &htk_features, 0);
230 mfcc.
Compute(waveform, 1.0, &kaldi_raw_features);
248 if ((std::abs(b - a)) > 1.0) {
251 std::cout <<
"\n\n\n[HTK-row: " <<
i <<
"] " << htk_features.Row(
i) <<
"\n";
252 std::cout <<
"[Kaldi-row: " <<
i <<
"] " << kaldi_features.
Row(
i) <<
"\n\n\n";
256 std::cout <<
"[" <<
i <<
", " <<
j <<
"]";
265 static_cast<int16
>(
sizeof(
float)*kaldi_features.
NumCols()),
269 std::ofstream os(
"tmp.test.wav.fea_kaldi.2",
270 std::ios::out|std::ios::binary);
271 WriteHtk(os, kaldi_features, header);
274 std::cout <<
"Test passed :)\n\n";
276 unlink(
"tmp.test.wav.fea_kaldi.2");
281 std::cout <<
"=== UnitTestHTKCompare3() ===\n";
283 std::ifstream is(
"test_data/test.wav", std::ios_base::binary);
292 std::ifstream is(
"test_data/test.wav.fea_htk.3",
293 std::ios::in | std::ios_base::binary);
294 bool ans =
ReadHtk(is, &htk_features, 0);
315 mfcc.
Compute(waveform, 1.0, &kaldi_raw_features);
333 if ((std::abs(b - a)) > 1.0) {
335 if (static_cast<int32>(i_old) !=
i) {
336 std::cout <<
"\n\n\n[HTK-row: " <<
i <<
"] " << htk_features.Row(
i) <<
"\n";
337 std::cout <<
"[Kaldi-row: " <<
i <<
"] " << kaldi_features.
Row(
i) <<
"\n\n\n";
341 std::cout <<
"[" <<
i <<
", " <<
j <<
"]";
350 static_cast<int16
>(
sizeof(
float)*kaldi_features.
NumCols()),
354 std::ofstream os(
"tmp.test.wav.fea_kaldi.3",
355 std::ios::out|std::ios::binary);
356 WriteHtk(os, kaldi_features, header);
359 std::cout <<
"Test passed :)\n\n";
361 unlink(
"tmp.test.wav.fea_kaldi.3");
366 std::cout <<
"=== UnitTestHTKCompare4() ===\n";
368 std::ifstream is(
"test_data/test.wav", std::ios_base::binary);
377 std::ifstream is(
"test_data/test.wav.fea_htk.4",
378 std::ios::in | std::ios_base::binary);
379 bool ans =
ReadHtk(is, &htk_features, 0);
398 mfcc.
Compute(waveform, 1.0, &kaldi_raw_features);
416 if ((std::abs(b - a)) > 1.0) {
418 if (static_cast<int32>(i_old) !=
i) {
419 std::cout <<
"\n\n\n[HTK-row: " <<
i <<
"] " << htk_features.Row(
i) <<
"\n";
420 std::cout <<
"[Kaldi-row: " <<
i <<
"] " << kaldi_features.
Row(
i) <<
"\n\n\n";
424 std::cout <<
"[" <<
i <<
", " <<
j <<
"]";
433 static_cast<int16
>(
sizeof(
float)*kaldi_features.
NumCols()),
437 std::ofstream os(
"tmp.test.wav.fea_kaldi.4",
438 std::ios::out|std::ios::binary);
439 WriteHtk(os, kaldi_features, header);
442 std::cout <<
"Test passed :)\n\n";
444 unlink(
"tmp.test.wav.fea_kaldi.4");
449 std::cout <<
"=== UnitTestHTKCompare5() ===\n";
451 std::ifstream is(
"test_data/test.wav", std::ios_base::binary);
460 std::ifstream is(
"test_data/test.wav.fea_htk.5",
461 std::ios::in | std::ios_base::binary);
462 bool ans =
ReadHtk(is, &htk_features, 0);
486 mfcc.
Compute(waveform, vtln_warp, &kaldi_raw_features);
504 if ((std::abs(b - a)) > 1.0) {
506 if (static_cast<int32>(i_old) !=
i) {
507 std::cout <<
"\n\n\n[HTK-row: " <<
i <<
"] " << htk_features.Row(
i) <<
"\n";
508 std::cout <<
"[Kaldi-row: " <<
i <<
"] " << kaldi_features.
Row(
i) <<
"\n\n\n";
512 std::cout <<
"[" <<
i <<
", " <<
j <<
"]";
521 static_cast<int16
>(
sizeof(
float)*kaldi_features.
NumCols()),
525 std::ofstream os(
"tmp.test.wav.fea_kaldi.5",
526 std::ios::out|std::ios::binary);
527 WriteHtk(os, kaldi_features, header);
530 std::cout <<
"Test passed :)\n\n";
532 unlink(
"tmp.test.wav.fea_kaldi.5");
536 std::cout <<
"=== UnitTestHTKCompare6() ===\n";
539 std::ifstream is(
"test_data/test.wav", std::ios_base::binary);
548 std::ifstream is(
"test_data/test.wav.fea_htk.6",
549 std::ios::in | std::ios_base::binary);
550 bool ans =
ReadHtk(is, &htk_features, 0);
571 mfcc.
Compute(waveform, 1.0, &kaldi_raw_features);
589 if ((std::abs(b - a)) > 1.0) {
591 if (static_cast<int32>(i_old) !=
i) {
592 std::cout <<
"\n\n\n[HTK-row: " <<
i <<
"] " << htk_features.Row(
i) <<
"\n";
593 std::cout <<
"[Kaldi-row: " <<
i <<
"] " << kaldi_features.
Row(
i) <<
"\n\n\n";
597 std::cout <<
"[" <<
i <<
", " <<
j <<
"]";
606 static_cast<int16
>(
sizeof(
float)*kaldi_features.
NumCols()),
610 std::ofstream os(
"tmp.test.wav.fea_kaldi.6",
611 std::ios::out|std::ios::binary);
612 WriteHtk(os, kaldi_features, header);
615 std::cout <<
"Test passed :)\n\n";
617 unlink(
"tmp.test.wav.fea_kaldi.6");
622 BaseFloat low_freq = 10, high_freq = 7800,
623 vtln_low_cutoff = 20, vtln_high_cutoff = 7400;
625 for (
size_t i = 0;
i < 100;
i++) {
628 low_freq, high_freq, warp_factor,
633 low_freq, high_freq, warp_factor,
637 low_freq, high_freq, warp_factor,
643 low_freq, high_freq, warp_factor,
646 low_freq, high_freq, warp_factor,
650 low_freq, high_freq, 1.0,
669 std::cout <<
"Tests succeeded.\n";
676 for (
int i = 0;
i < 5;
i++)
678 std::cout <<
"Tests succeeded.\n";
680 }
catch (
const std::exception &e) {
681 std::cerr << e.what();
void Read(std::istream &is)
Read() will throw on error.
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
static BaseFloat VtlnWarpFreq(BaseFloat vtln_low_cutoff, BaseFloat vtln_high_cutoff, BaseFloat low_freq, BaseFloat high_freq, BaseFloat vtln_warp_factor, BaseFloat freq)
void Compute(const VectorBase< BaseFloat > &wave, BaseFloat vtln_warp, Matrix< BaseFloat > *output)
float RandUniform(struct RandomState *state=NULL)
Returns a random number strictly between 0 and 1.
static void UnitTestReadWave()
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
MfccOptions contains basic options for computing MFCC features.
static void UnitTestHTKCompare6()
bool WriteHtk(std::ostream &os, const MatrixBase< Real > &M, HtkHeader htk_hdr)
static void UnitTestSimple()
static void UnitTestHTKCompare1()
static void UnitTestHTKCompare2()
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
const Matrix< BaseFloat > & Data() const
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
static void UnitTestFeat()
FrameExtractionOptions frame_opts
static void UnitTestHTKCompare3()
static void UnitTestHTKCompare5()
MatrixIndexT Dim() const
Returns the dimension of the vector.
This class's purpose is to read in Wave files.
A class representing a vector.
#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)
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
This templated class is intended for offline feature extraction, i.e.
bool ReadHtk(std::istream &is, Matrix< Real > *M_ptr, HtkHeader *header_ptr)
Extension of the HTK header.
void Read(std::istream &in, bool binary, bool add=false)
Read function using C++ streams.
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
static void UnitTestHTKCompare4()