53 #define DEF_SAMPLE_RATE 16000 54 #define HTK_UNITS_PER_SECOND 10000000 56 static EST_Regex RXleadingwhitespace(
"^[ \t\n\r][ \t\n\r]*.*$");
70 key = ts.
get().string();
76 if (val.
matches(RXleadingwhitespace))
88 si->
set(
"end",(
float)atof(ts.
get().string()));
91 for (name =
""; (!ts.
eoln()) && (ts.
peek() !=
";"); )
117 outf =
new ofstream(filename);
121 cerr <<
"save_esps_label: can't open label output file \"" <<
122 filename <<
"\"" << endl;
140 *outf <<
"separator ;\n";
142 *outf <<
"nfields 1\n";
145 for (p.
begin(s.
f); p; ++p)
146 *outf << p->k <<
" " << p->v << endl;
155 for (ptr = s.
head(); ptr != 0; ptr = ptr->
next())
158 std::streamsize oldprecision = outf->precision(5);
159 std::ios_base::fmtflags oldsetf = outf->setf(ios::fixed, ios::floatfield);
160 std::streamsize oldwidth = outf->width(8);
162 if (s.
f(
"timing_style",
"0") ==
"event")
163 *outf << ptr->
F(
"time",0);
165 *outf << ptr->
F(
"end",0);
167 *outf <<
" 26 \t" << ptr->
S(
"name",
"0");
183 outf->precision(oldprecision);
185 outf->width(oldwidth);
207 if ((ts.
peek().
col() == 0) && (ts.
peek() ==
"END"))
209 if (ts.
peek() ==
"END")
217 key = ts.
get().string();
218 val = ts.
get().string();
221 sr = 1000.0 / atof(val);
226 cerr <<
"Error: couldn't find header in label file " 233 cerr <<
"error: in label file " << ts.
filename() <<
" at line " <<
250 item->
set(
"end",0.0);
256 static float convert_long_num_string_to_time(
const char *s,
int sample)
263 return atof(s)/sample;
269 (strchr(
" \n\r\t",s[i]) !=
NULL) && (s[i] !=
'\0');
273 (s[i] !=
'\0') && (s[i] >=
'0') && (s[i] <=
'9');
278 a += (d/(double)sample);
294 str = ts.
get().string();
301 str = ts.
get().string();
302 hend = convert_long_num_string_to_time(str,sample);
304 item->
set(
"end",hend);
305 item->
set(
"name",ts.
get().string());
327 cerr <<
"error: in label file " << ts.
filename() <<
" at line " <<
341 outf =
new ofstream(filename);
345 cerr <<
"save_htk_label: can't open label output file \"" <<
346 filename <<
"\"" << endl;
368 for (ptr = a.
head(); ptr != 0; ptr = ptr->
next())
374 end = ptr->
F(
"end",0.0);
375 *outf << (
int)(end * HTK_UNITS_PER_SECOND);
376 *outf <<
" " << ptr->
name() << endl;
387 EST_Stream_Item *ptr;
393 outf =
new ofstream(filename);
397 cerr <<
"save_label_spn: can't open label output file \"" 398 << filename <<
"\"" << endl;
406 *outf << ptr->
name();
407 outf->setf(ios::fixed, ios::floatfield);
409 *outf << (ptr->dur() * 1000.0) <<
"\t (0,140)" << endl;
411 for (; next(ptr) != 0; ptr = ptr->next())
416 *outf << ptr->name();
417 outf->setf(ios::fixed, ios::floatfield);
419 *outf << (ptr->dur() * 1000.0) << endl;
424 *outf << ptr->name();
425 outf->setf(ios::fixed, ios::floatfield);
427 *outf << (ptr->dur() * 1000.0) <<
"\t (99,80)" << endl;
439 EST_Stream_Item *ptr;
445 outf =
new ofstream(filename);
449 cerr <<
"save_label_name: can't open label output file \"" 450 << filename <<
"\"" << endl;
454 for (ptr = a.
head(); next(ptr) != 0; ptr = ptr->
next())
456 *outf << ptr->name();
457 if ((features !=
"") && (features !=
"OneLine"))
463 *outf << ptr->name() << endl;
484 outf =
new ofstream(filename);
488 cerr <<
"save_StreamList: can't open MLF output file \"" 489 << filename <<
"\"\n";
493 *outf <<
"#!MLF!#\n";
497 for (p = plist.
head(); p != 0; p = p->
next())
499 outname = path ? plist(p).name() :
basename(plist(p).name());
500 *outf <<
"\"*/" << outname<<
"\"\n";
501 for (ptr = plist(p).head(); ptr != 0; ptr = ptr->
next())
509 end = ptr->
F(
"end",0.0);
510 *outf << (
int)(end * HTK_UNITS_PER_SECOND) <<
" ";
513 *outf << ptr->
S(
"name",
"0") << endl;
534 outf =
new ofstream(filename);
538 cerr <<
"save:WordList: can't open WordList output file \"" 539 << filename <<
"\"\n";
543 for (p = plist.
head(); p != 0; p = p->
next())
545 for (ptr = plist(p).
head(); ptr->
next() != 0; ptr = ptr->
next())
547 *outf << ptr->
name();
554 *outf << ptr->
name() << endl;
572 for (p = plist.
head(); p != 0; p = p->
next())
574 outname = path ? plist(p).name() :
basename(plist(p).name());
588 if (((filename ==
"-") ? ts.
open(cin) : ts.
open(filename)) != 0)
590 cerr <<
"Can't open label input file " << filename << endl;
597 if (ts.
get().string() !=
"#!MLF!#")
599 cerr <<
"Not MLF file\n";
607 fns = ts.
get().string();
610 s.
f.
set(
"name", fns);
615 cerr <<
"error: in reading MLF file\n";
616 cerr <<
"section for file " << fns <<
617 " at line " << ts.
linenum() <<
" is badly formatted\n";
632 for (i = 0, p = s.
head(); p; p = p->
next(), ++i)
633 p->
set(
"end",(length *
float(i)/
float(s.
length())));
641 if (al.
val(
"-itype", 0) ==
"mlf")
647 for (p = files.
head(); p; p = p->
next())
654 if (plist(plp).load(files(p), al.
val(
"-itype")) !=
format_ok)
659 if ((al.
val(
"-itype", 0) ==
"words") && (al.
present(
"-length")))
660 pad_ends(s, al.
fval(
"-length"));
EST_TokenStream & get(EST_Token &t)
get next token in stream
float end(const EST_Item &item)
const EST_String name() const
#define HTK_UNITS_PER_SECOND
void set(const EST_String &name, ssize_t ival)
A Regular expression class to go with the CSTR EST_String class.
STATIC void left(STATUS Change)
void set_SingleCharSymbols(const EST_String &sc)
set which characters are to be treated as single character symbols
bool save(Lattice &lattice, EST_String filename)
const T & last() const
return const reference to last item in list
const EST_String filename() const
The originating filename (if there is one)
EST_read_status load(EST_TokenStream &ts)
load features from already opened EST_TokenStream
bool load(Lattice &lattice, EST_String filename)
const EST_String & whitespace()
float fval(const EST_String &rkey, int m=1) const
void set(const EST_String &name, int ival)
int open(const EST_String &filename)
open a EST_TokenStream for a file.
EST_read_status load_esps_label(EST_TokenStream &ts, EST_Relation &rel)
void set_name(const EST_String &name) const
EST_write_status save_RelationList(const EST_String &filename, const EST_RelationList &plist, int time, int path)
EST_write_status save_WordList(const EST_String &filename, const EST_RelationList &plist, int style)
float F(const EST_String &name) const
EST_read_status load_words_label(EST_TokenStream &ts, EST_Relation &s)
EST_Regex RXwhite("[ \n\t\r]+")
White space.
void evaluate(EST_Item *a, EST_Features &f)
int linenum(void) const
returns line number of EST_TokenStream
The file was written successfully.
void remove(const EST_String &name)
EST_read_status load_ogi_label(EST_TokenStream &ts, EST_Relation &s)
float time(const EST_Item &item)
int present(const EST_String &name) const
int col(void) const
Line position in original EST_TokenStream.
const T & first() const
return const reference to first item in list
EST_Token & peek(void)
peek at next token
EST_Features & features() const
EST_write_status save(ostream &outf) const
save features in already opened ostream
void set_quotes(char q, char e)
set characters to be used as quotes and escape, and set quote mode
int matches(const char *e, ssize_t pos=0) const
Exactly match this string?
The file was not written successfully.
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
void append(const T &item)
add item onto end of list
EST_String basename(EST_String full, EST_String ext="")
This acts like the bourne shell basename command. By default, it strips any leading path from a strin...
EST_read_status load_RelationList(const EST_String &filename, EST_RelationList &plist)
EST_read_status read_label_portion(EST_TokenStream &ts, EST_Relation &s, int sample)
float start(const EST_Item &item)
size_t length(void) const
Length of string ({not} length of underlying chunk)
EST_write_status save_esps_label(const EST_String &filename, const EST_Relation &s, bool evaluate_ff)
const EST_String & string() const
void begin(const Container &over)
Set the iterator ready to run over this container.
int present(const K &rkey) const
Returns true if key is present.
EST_write_status save_htk_label(const EST_String &filename, const EST_Relation &a)
EST_Token get_upto_eoln(void)
get up to s in end of line as a single token.
void strip_quotes(EST_String &s, const EST_String quote_char="\"")
remove quotes from a string
EST_write_status save_ind_RelationList(const EST_String &filename, const EST_RelationList &plist, const EST_String &features, int path)
const EST_String S(const EST_String &name) const
EST_read_status read_RelationList(EST_RelationList &plist, EST_StrList &files, EST_Option &al)
EST_Item * append(EST_Item *si)
EST_String after(int pos, int len=1) const
Part after pos+len.
EST_read_status load_sample_label(EST_TokenStream &ts, EST_Relation &s, int sample)
Utility EST_String Functions header file.