73 const char *filename =
"tmpf";
75 Output ko(filename, binary);
76 std::ostream &outfile = ko.
Stream();
77 if (!binary) outfile <<
"\t";
78 int64 i1 =
Rand() % 10000;
80 uint16 i2 =
Rand() % 10000;
82 if (!binary) outfile <<
"\t";
85 if (!binary &&
Rand()%2 == 0) outfile <<
" \n";
86 std::vector<int32> vec1;
88 if (!binary &&
Rand()%2 == 0) outfile <<
" \n";
89 std::vector<uint16> vec2;
90 for (
size_t i = 0;
i < 10;
i++) vec2.push_back(
Rand()%100 - 10);
92 if (!binary) outfile <<
" \n";
93 std::vector<char> vec3;
94 for (
size_t i = 0;
i < 10;
i++) vec3.push_back(
Rand()%100);
96 if (!binary &&
Rand()%2 == 0) outfile <<
" \n";
97 const char *token1 =
"Hi";
99 if (!binary) outfile <<
" \n";
100 std::string token2 =
"There.";
102 if (!binary &&
Rand()%2 == 0) outfile <<
" \n";
103 std::string token3 =
"You.";
105 if (!binary &&
Rand()%2 == 0) outfile <<
" ";
108 if (!binary &&
Rand()%2 == 0) outfile <<
"\t";
113 if (!binary &&
Rand()%2 == 0) outfile <<
"\t";
116 if (!binary &&
Rand()%2 == 0) outfile <<
"\t";
121 Input ki(filename, &binary_in);
122 std::istream &infile = ki.
Stream();
132 std::vector<int32> vec1_in;
135 std::vector<uint16> vec2_in;
138 std::vector<char> vec3_in;
141 std::string token1_in, token2_in;
143 ReadToken(infile, binary_in, &token1_in);
145 ReadToken(infile, binary_in, &token2_in);
172 #if defined(_MSC_VER) && !defined(KALDI_CYGWIN_COMPAT) 174 const char *filename_out =
"|kaldi-io-test cat > tmpf.gz",
175 *filename_in =
"kaldi-io-test cat tmpf.gz|";
177 const char *filename_out =
"|gzip -c > tmpf.gz",
178 *filename_in =
"gunzip -c tmpf.gz |";
181 Output ko(filename_out, binary);
182 std::ostream &outfile = ko.
Stream();
183 if (!binary) outfile <<
"\t";
184 int64 i1 =
Rand() % 10000;
186 uint16 i2 =
Rand() % 10000;
188 if (!binary) outfile <<
"\t";
191 if (!binary &&
Rand()%2 == 0) outfile <<
" \n";
192 std::vector<int32> vec1;
194 if (!binary &&
Rand()%2 == 0) outfile <<
" \n";
195 std::vector<uint16> vec2;
196 for (
size_t i = 0;
i < 10;
i++) vec2.push_back(
Rand()%100 - 10);
198 if (!binary) outfile <<
" \n";
200 std::vector<char> vec3;
201 for (
size_t i = 0;
i < 10;
i++) vec3.push_back(
Rand()%100);
203 if (!binary &&
Rand()%2 == 0) outfile <<
" \n";
204 const char *token1 =
"Hi";
206 if (!binary) outfile <<
" \n";
207 std::string token2 =
"There.";
209 if (!binary &&
Rand()%2 == 0) outfile <<
" \n";
210 std::string token3 =
"You.";
212 if (!binary &&
Rand()%2 == 0) outfile <<
" ";
215 if (!binary &&
Rand()%2 == 0) outfile <<
"\t";
220 if (!binary &&
Rand()%2 == 0) outfile <<
"\t";
223 if (!binary &&
Rand()%2 == 0) outfile <<
"\t";
224 bool ans = ko.
Close();
232 Input ki(filename_in, &binary_in);
233 std::istream &infile = ki.
Stream();
243 std::vector<int32> vec1_in;
246 std::vector<uint16> vec2_in;
249 std::vector<char> vec3_in;
254 std::string token1_in, token2_in;
256 ReadToken(infile, binary_in, &token1_in);
258 ReadToken(infile, binary_in, &token2_in);
297 std::cout <<
"Should see: foo\n";
302 std::cout <<
"Should see: bar\n";
310 #ifdef KALDI_CYGWIN_COMPAT 311 extern std::string
MapCygwinPath(
const std::string &filename);
328 #if defined(_MSC_VER) && !defined(KALDI_CYGWIN_COMPAT) 331 static int TinyCat(
int argc,
const char** argv) {
332 const char* name_in = argc > 0 && strcmp(argv[0],
"-") ? argv[0] : NULL;
333 int fd_in = name_in ? _open(name_in, _O_RDONLY) : _fileno(stdin);
337 int fd_out = _fileno(stdout);
338 _setmode(fd_in, _O_BINARY);
339 _setmode(fd_out, _O_BINARY);
343 while ((last_read = _read(fd_in, buffer,
sizeof(buffer))) > 0)
344 _write(fd_out, buffer, last_read);
346 if (name_in) _close(fd_in);
351 int main(
int argc,
const char** argv) {
352 using namespace kaldi;
353 #if defined(_MSC_VER) && !defined(KALDI_CYGWIN_COMPAT) 354 if (argc > 1 && strcmp(argv[1],
"cat") == 0)
355 return TinyCat(argc - 2, argv + 2);
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void UnitTestClassifyWxfilename()
InputType ClassifyRxfilename(const std::string &filename)
ClassifyRxfilenames interprets filenames for reading as follows:
float RandUniform(struct RandomState *state=NULL)
Returns a random number strictly between 0 and 1.
void ReadBasicType(std::istream &is, bool binary, T *t)
ReadBasicType is the name of the read function for bool, integer types, and floating-point types...
void Sleep(float seconds)
void UnitTestNativeFilename()
void ReadToken(std::istream &is, bool binary, std::string *str)
ReadToken gets the next token and puts it in str (exception on failure).
int Peek(std::istream &is, bool binary)
Peek consumes whitespace (if binary == false) and then returns the peek() value of the stream...
void ReadIntegerVector(std::istream &is, bool binary, std::vector< T > *v)
Function for reading STL vector of integer types.
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
int PeekToken(std::istream &is, bool binary)
PeekToken will return the first character of the next token, or -1 if end of file.
int Rand(struct RandomState *state)
int main(int argc, const char **argv)
void UnitTestIoNew(bool binary)
void UnitTestIoStandard()
#define KALDI_ASSERT(cond)
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
OutputType ClassifyWxfilename(const std::string &filename)
ClassifyWxfilename interprets filenames as follows:
void WriteIntegerVector(std::ostream &os, bool binary, const std::vector< T > &v)
Function for writing STL vectors of integer types.
void WriteBasicType(std::ostream &os, bool binary, T t)
WriteBasicType is the name of the write function for bool, integer types, and floating-point types...
std::string MapCygwinPath(const std::string &filename)
void UnitTestClassifyRxfilename()
void UnitTestIoPipe(bool binary)