Edinburgh Speech Tools  2.1-release
ch_lab_main.cc
Go to the documentation of this file.
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1995,1996 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 /* Authors: Paul Taylor and Simon King */
34 /* Date : June 1995 */
35 /*-----------------------------------------------------------------------*/
36 /* Label conversion main file */
37 /* */
38 /*=======================================================================*/
39 
40 #include <cstdlib>
41 #include "EST_ling_class.h"
42 #include "EST_Track.h"
43 #include "EST_cmd_line.h"
44 #include "EST_string_aux.h"
45 
46 using namespace std;
47 
49 
50 int main(int argc, char *argv[])
51 {
52  EST_String out_file, ext;
53  EST_StrList files;
54  EST_Option al, op;
55  EST_Relation lab, key;
56  EST_RelationList mlf;
57  EST_Litem *p;
58 
60  (argc, argv,
61  EST_String(" [input file1] [input file2] -o [output file]\n") +
62  "Summary: change/copy label files\n"+
63  "use \"-\" to make input and output files stdin/out\n"+
64  "-h Options help\n"+
65  "-S <float> frame spacing of output\n"+
66  "-base use base filenames for lists of label files\n"+
67  "-class <string> Name of class defined in op file\n"+
68  "-combine \n"+
69  "-divide \n"+
70  "-end <float> end time (secs) for label extraction\n"+
71  "-ext <string> filename extension\n"+
72  "-extend <float> extend track file beyond label file\n"+
73  "-extract <string> extract a single file from a list of label files\n"+
74  "-f <int> sample frequency of label file\n"+
75  "-itype <string> type of input label file: esps htk ogi\n"+
76  "-key <string> key label file\n"+
77  "-lablist <string> list of labels to be considered as blank\n"+
78  "-length <float> length of track produced\n"+
79  "-lf <int> sample frequency for labels\n"+
80  "-map <string> name of file containing label mapping\n"+
81  "-name <string> eg. Fo Phoneme\n"+
82  "-nopath ignore pathnames when searching label lists\n"+
83  "-o <ofile> output gile name\n"+
84  "-off <float> vertical offset of track\n"+
85  "-ops print options\n"+
86  "-otype <string> {esps}\n"+
87  " output file type: xmg, ascii, esps, htk\n"+
88  "-pad <string> Pad with \"high\" or \"low\" values\n"+
89  "-pos <string> list of labels to be regarded as 'pos'\n"+
90  "-q <float> quantize label timings to nearest value\n"+
91  "-range <float> different between high and low values\n"+
92  "-sed <ifile> perform regex editing using sed file\n"+
93  "-shift <float> shift the times of the labels\n"+
94  "-start <float> start time for label extraction\n"+
95  "-style <string> output stype e.g. track\n"+
96  "-vocab <ifile> file containing list of words in vocab\n"+
97  "-verify check that only labels in vocab file are in label file\n",
98  files, al);
99 
100  init_lib_ops(al, op);
101 
102  out_file = al.present("-o") ? al.val("-o") : (EST_String)"-";
103 
104  read_RelationList(mlf, files, al);
105 
106  // perform all utility functions on all relations in mlf
107  for (p = mlf.head(); p; p = p->next())
108  relation_convert(mlf(p), al, op);
109 
110  if (al.present("-verify"))
111  {
113  if (load_StrList(al.val("-vocab"), vocab) != format_ok)
114  {
115  cerr << "Couldn't read vocab file " << al.val("-vocab")
116  << " for verification\n";
117  exit(-1);
118  }
119  for (p = mlf.head(); p; p = p->next())
120  check_vocab(mlf(p), vocab);
121  exit(0);
122  }
123 
124  if (files.length() == 1) // special case of only one input file
125  lab = mlf.first();
126 
127  if (al.present("-extract")) // extract a single relation
128  lab = RelationList_extract(mlf, al.val("-extract"),
129  (bool)al.present("-base"));
130 
131  if (al.present("-combine")) // join all relations into lab sequentially
132  {
133  if (al.present("-key"))
134  {
135  key.load(al.val("-key"));
136  lab = RelationList_combine(mlf, key);
137  }
138  else
139  lab = RelationList_combine(mlf);
140  }
141 
142  if (al.present("-divide")) // make mlf from single relation and keylab
143  {
144  EST_StrList blank;
145  ext = al.present("-ext") ? al.val("-ext") : (EST_String)"";
146  key.load(al.val("-key"));
147  if (al.present("-lablist"))
148  StringtoStrList(al.val("-lablist"), blank);
149  if (relation_divide(mlf, lab, key, blank, ext) == -1)
150  exit(-1);
151 // if (al.present("-newkey")) // the function reassigns keylab boundaries
152 // key.save(al.val("-newkey"));
153  }
154 
155  if (al.val("-style", 0) == "track")
156  {
157  EST_Track tr;
158  label_to_track(lab, al, op, tr);
159  tr.save(out_file, op.val("track_file_type", 0));
160  exit(0);
161  }
162 
163  int path = al.present("-nopath") ? 0 : 1;
164  if (al.val("-otype", 0) == "mlf")
165  save_RelationList(out_file, mlf, 1, path); // i.e. print times
166  else if (al.val("-otype", 0) == "wmlf")
167  save_RelationList(out_file, mlf, 0, path); // i.e. don't print times
168  else if (al.val("-otype", 0) == "words")
169  save_WordList(out_file, mlf, 0);
170  else if (al.val("-otype", 0) == "sentence")
171  save_WordList(out_file, mlf, 1);
172  else if (al.val("-otype", 0) == "ind")
173  {
174  if (al.present("-a"))
175  save_ind_RelationList(out_file, mlf, "Addresses", path);
176  else
177  save_ind_RelationList(out_file, mlf, "None", path);
178  }
179  else
180 // lab.save(out_file, al.val("-otype", 0), "None");
181  lab.save(out_file,al.val("-otype"));
182 
183  return 0;
184 }
185 
187 {
188  a_list.override_val("frame_shift", al.val("-S", 0));
189  a_list.override_val("in_lab_file_type", al.val("-itype", 0));
190  a_list.override_val("out_lab_file_type", al.val("-otype", 0));
191  a_list.override_val("label_offset", al.val("-off", 0));
192  a_list.override_val("label_range", al.val("-range", 0));
193 
194  if (al.val("-style", 0) == "track")
195  a_list.override_val("track_file_type", al.val("-otype", 0));
196 }
197 
int override_val(const EST_String rkey, const EST_String rval)
add to end of list or overwrite. If rval is empty, do nothing
Definition: EST_Option.cc:54
EST_write_status save_ind_RelationList(const EST_String &filename, const EST_RelationList &plist, const EST_String &features, int path)
Definition: relation_io.cc:562
EST_Relation RelationList_combine(EST_RelationList &mlf)
EST_read_status read_RelationList(EST_RelationList &mlf, EST_StrList &files, EST_Option &al)
Definition: relation_io.cc:636
EST_UItem * next()
Definition: EST_UList.h:55
EST_write_status save_WordList(const EST_String &filename, const EST_RelationList &plist, int n)
Definition: relation_io.cc:523
void override_lib_ops(EST_Option &a_list, EST_Option &al)
Definition: ch_lab_main.cc:186
void label_to_track(const EST_Relation &lab, const EST_Option &al, const EST_Option &op, EST_Track &tr)
void StringtoStrList(EST_String s, EST_StrList &l, EST_String sep)
Convert a EST_String to a EST_StrList by separating tokens in s delimited by the separator sep...
int init_lib_ops(EST_Option &al, EST_Option &options)
Definition: cmd_line.cc:69
EST_Relation RelationList_extract(EST_RelationList &mlf, const EST_String &filename, bool base)
EST_write_status save(const EST_String name, const EST_String EST_filetype="")
Definition: EST_Track.cc:1233
void relation_convert(EST_Relation &lab, EST_Option &al, EST_Option &op)
const T & first() const
return const reference to first item in list
Definition: EST_TList.h:152
EST_write_status save_RelationList(const EST_String &filename, const EST_RelationList &plist)
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition: EST_TKVL.cc:145
int relation_divide(EST_RelationList &mlf, EST_Relation &lab, EST_Relation &keylab, EST_String ext)
int length() const
Definition: EST_UList.cc:57
#define format_ok
int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
int main(int argc, char *argv[])
Definition: ch_lab_main.cc:50
EST_write_status save(const EST_String &filename, bool evaluate_ff=false) const
EST_UItem * head() const
Definition: EST_UList.h:97
EST_read_status load(const EST_String &filename, const EST_String &type="esps")
EST_String
EST_read_status load_StrList(EST_String filename, EST_StrList &l)
Load tokens from a file and return them in a EST_StrList.
int parse_command_line(int argc, char *argv[], const EST_String &usage, EST_StrList &files, EST_Option &al, int make_stdio=1)
Definition: cmd_line.cc:101
#define bool
Definition: EST_bool.h:117
EST_StrVector vocab
Definition: dp_main.cc:85
int check_vocab(EST_Relation &a, EST_StrList &vocab)
Utility EST_String Functions header file.