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.fbank_htk.1",
125 std::ios::in | std::ios_base::binary);
126 bool ans =
ReadHtk(is, &htk_features, 0);
146 fbank.
Compute(waveform, 1.0, &kaldi_features);
149 std::cout <<
"<<<=== Compare with HTK features...\n";
161 if ((std::abs(b - a)) > 0.001) {
164 std::cout <<
"\n\n\n[HTK-row: " <<
i <<
"] " << htk_features.Row(
i) <<
"\n";
165 std::cout <<
"[Kaldi-row: " <<
i <<
"] " << kaldi_features.
Row(
i) <<
"\n\n\n";
169 std::cout <<
"[" <<
i <<
", " <<
j <<
"]";
178 static_cast<int16
>(
sizeof(
float)*kaldi_features.
NumCols()),
182 std::ofstream os(
"tmp.test.wav.fbank_kaldi.1",
183 std::ios::out|std::ios::binary);
184 WriteHtk(os, kaldi_features, header);
187 std::cout <<
"Test passed :)\n\n";
189 unlink(
"tmp.test.wav.fbank_kaldi.1");
194 std::cout <<
"=== UnitTestHTKCompare2() ===\n";
196 std::ifstream is(
"test_data/test.wav", std::ios_base::binary);
205 std::ifstream is(
"test_data/test.wav.fbank_htk.2",
206 std::ios::in | std::ios_base::binary);
207 bool ans =
ReadHtk(is, &htk_features, 0);
227 fbank.
Compute(waveform, 1.0, &kaldi_features);
230 std::cout <<
"<<<=== Compare with HTK features...\n";
242 if ((std::abs(b - a)) > 0.001) {
245 std::cout <<
"\n\n\n[HTK-row: " <<
i <<
"] " << htk_features.Row(
i) <<
"\n";
246 std::cout <<
"[Kaldi-row: " <<
i <<
"] " << kaldi_features.
Row(
i) <<
"\n\n\n";
250 std::cout <<
"[" <<
i <<
", " <<
j <<
"]";
259 static_cast<int16
>(
sizeof(
float)*kaldi_features.
NumCols()),
263 std::ofstream os(
"tmp.test.wav.fbank_kaldi.1",
264 std::ios::out|std::ios::binary);
265 WriteHtk(os, kaldi_features, header);
268 std::cout <<
"Test passed :)\n\n";
270 unlink(
"tmp.test.wav.fbank_kaldi.1");
274 std::cout <<
"=== UnitTestHTKCompare3() ===\n";
276 std::ifstream is(
"test_data/test.wav", std::ios_base::binary);
285 std::ifstream is(
"test_data/test.wav.fbank_htk.3",
286 std::ios::in | std::ios_base::binary);
287 bool ans =
ReadHtk(is, &htk_features, 0);
311 fbank.
Compute(waveform, vtln_warp, &kaldi_features);
314 std::cout <<
"<<<=== Compare with HTK features...\n";
326 if ((std::abs(b - a)) > 0.001) {
329 std::cout <<
"\n\n\n[HTK-row: " <<
i <<
"] " << htk_features.Row(
i) <<
"\n";
330 std::cout <<
"[Kaldi-row: " <<
i <<
"] " << kaldi_features.
Row(
i) <<
"\n\n\n";
334 std::cout <<
"[" <<
i <<
", " <<
j <<
"]";
335 if (j < 20) passed =
false;
336 else KALDI_WARN <<
"Ignoring difference in last fbanks, we know the algorithms differ.";
344 static_cast<int16
>(
sizeof(
float)*kaldi_features.
NumCols()),
348 std::ofstream os(
"tmp.test.wav.fbank_kaldi.1",
349 std::ios::out|std::ios::binary);
350 WriteHtk(os, kaldi_features, header);
353 std::cout <<
"Test passed :)\n\n";
355 unlink(
"tmp.test.wav.fbank_kaldi.1");
360 std::cout <<
"=== UnitTestHTKCompare4() ===\n";
362 std::ifstream is(
"test_data/test.wav", std::ios_base::binary);
371 std::ifstream is(
"test_data/test.wav.fbank_htk.4",
372 std::ios::in | std::ios_base::binary);
373 bool ans =
ReadHtk(is, &htk_features, 0);
397 fbank.
Compute(waveform, vtln_warp, &kaldi_features);
400 std::cout <<
"<<<=== Compare with HTK features...\n";
412 if ((std::abs(b - a)) > 0.01) {
415 std::cout <<
"\n\n\n[HTK-row: " <<
i <<
"] " << htk_features.Row(
i) <<
"\n";
416 std::cout <<
"[Kaldi-row: " <<
i <<
"] " << kaldi_features.
Row(
i) <<
"\n\n\n";
420 std::cout <<
"[" <<
i <<
", " <<
j <<
"]";
429 static_cast<int16
>(
sizeof(
float)*kaldi_features.
NumCols()),
433 std::ofstream os(
"tmp.test.wav.fbank_kaldi.1",
434 std::ios::out|std::ios::binary);
435 WriteHtk(os, kaldi_features, header);
438 std::cout <<
"Test passed :)\n\n";
440 unlink(
"tmp.test.wav.fbank_kaldi.1");
460 for (
int i = 0;
i < 5;
i++)
462 std::cout <<
"Tests succeeded.\n";
464 }
catch (
const std::exception &e) {
465 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 void UnitTestHTKCompare1()
static void UnitTestReadWave()
void Compute(const VectorBase< BaseFloat > &wave, BaseFloat vtln_warp, Matrix< BaseFloat > *output)
static void UnitTestHTKCompare4()
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
static void UnitTestHTKCompare3()
static void UnitTestFeat()
bool WriteHtk(std::ostream &os, const MatrixBase< Real > &M, HtkHeader htk_hdr)
static void UnitTestSimple()
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
const Matrix< BaseFloat > & Data() const
FrameExtractionOptions frame_opts
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].
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).
This templated class is intended for offline feature extraction, i.e.
FbankOptions contains basic options for computing filterbank features.
bool ReadHtk(std::istream &is, Matrix< Real > *M_ptr, HtkHeader *header_ptr)
Extension of the HTK header.
static void UnitTestHTKCompare2()
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...