Edinburgh Speech Tools  2.1-release
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ch_lab_main.cc
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 int check_vocab(EST_Relation &a, EST_StrList &vocab);
47 
48 int main(int argc, char *argv[])
49 {
50  EST_String out_file, ext;
51  EST_StrList files;
52  EST_Option al, op;
53  EST_Relation lab, key;
54  EST_RelationList mlf;
55  EST_Litem *p;
56 
57  parse_command_line
58  (argc, argv,
59  EST_String(" [input file1] [input file2] -o [output file]\n") +
60  "Summary: change/copy label files\n"+
61  "use \"-\" to make input and output files stdin/out\n"+
62  "-h Options help\n"+
63  "-S <float> frame spacing of output\n"+
64  "-base use base filenames for lists of label files\n"+
65  "-class <string> Name of class defined in op file\n"+
66  "-combine \n"+
67  "-divide \n"+
68  "-end <float> end time (secs) for label extraction\n"+
69  "-ext <string> filename extension\n"+
70  "-extend <float> extend track file beyond label file\n"+
71  "-extract <string> extract a single file from a list of label files\n"+
72  "-f <int> sample frequency of label file\n"+
73  "-itype <string> type of input label file: esps htk ogi\n"+
74  "-key <string> key label file\n"+
75  "-lablist <string> list of labels to be considered as blank\n"+
76  "-length <float> length of track produced\n"+
77  "-lf <int> sample frequency for labels\n"+
78  "-map <string> name of file containing label mapping\n"+
79  "-name <string> eg. Fo Phoneme\n"+
80  "-nopath ignore pathnames when searching label lists\n"+
81  "-o <ofile> output gile name\n"+
82  "-off <float> vertical offset of track\n"+
83  "-ops print options\n"+
84  "-otype <string> {esps}\n"+
85  " output file type: xmg, ascii, esps, htk\n"+
86  "-pad <string> Pad with \"high\" or \"low\" values\n"+
87  "-pos <string> list of labels to be regarded as 'pos'\n"+
88  "-q <float> quantize label timings to nearest value\n"+
89  "-range <float> different between high and low values\n"+
90  "-sed <ifile> perform regex editing using sed file\n"+
91  "-shift <float> shift the times of the labels\n"+
92  "-start <float> start time for label extraction\n"+
93  "-style <string> output stype e.g. track\n"+
94  "-vocab <ifile> file containing list of words in vocab\n"+
95  "-verify check that only labels in vocab file are in label file\n",
96  files, al);
97 
98  init_lib_ops(al, op);
99 
100  out_file = al.present("-o") ? al.val("-o") : (EST_String)"-";
101 
102  read_RelationList(mlf, files, al);
103 
104  // perform all utility functions on all relations in mlf
105  for (p = mlf.head(); p; p = p->next())
106  relation_convert(mlf(p), al, op);
107 
108  if (al.present("-verify"))
109  {
110  EST_StrList vocab;
111  if (load_StrList(al.val("-vocab"), vocab) != format_ok)
112  {
113  cerr << "Couldn't read vocab file " << al.val("-vocab")
114  << " for verification\n";
115  exit(-1);
116  }
117  for (p = mlf.head(); p; p = p->next())
118  check_vocab(mlf(p), vocab);
119  exit(0);
120  }
121 
122  if (files.length() == 1) // special case of only one input file
123  lab = mlf.first();
124 
125  if (al.present("-extract")) // extract a single relation
126  lab = RelationList_extract(mlf, al.val("-extract"),
127  (bool)al.present("-base"));
128 
129  if (al.present("-combine")) // join all relations into lab sequentially
130  {
131  if (al.present("-key"))
132  {
133  key.load(al.val("-key"));
134  lab = RelationList_combine(mlf, key);
135  }
136  else
137  lab = RelationList_combine(mlf);
138  }
139 
140  if (al.present("-divide")) // make mlf from single relation and keylab
141  {
142  EST_StrList blank;
143  ext = al.present("-ext") ? al.val("-ext") : (EST_String)"";
144  key.load(al.val("-key"));
145  if (al.present("-lablist"))
146  StringtoStrList(al.val("-lablist"), blank);
147  if (relation_divide(mlf, lab, key, blank, ext) == -1)
148  exit(-1);
149 // if (al.present("-newkey")) // the function reassigns keylab boundaries
150 // key.save(al.val("-newkey"));
151  }
152 
153  if (al.val("-style", 0) == "track")
154  {
155  EST_Track tr;
156  label_to_track(lab, al, op, tr);
157  tr.save(out_file, op.val("track_file_type", 0));
158  exit(0);
159  }
160 
161  int path = al.present("-nopath") ? 0 : 1;
162  if (al.val("-otype", 0) == "mlf")
163  save_RelationList(out_file, mlf, 1, path); // i.e. print times
164  else if (al.val("-otype", 0) == "wmlf")
165  save_RelationList(out_file, mlf, 0, path); // i.e. don't print times
166  else if (al.val("-otype", 0) == "words")
167  save_WordList(out_file, mlf, 0);
168  else if (al.val("-otype", 0) == "sentence")
169  save_WordList(out_file, mlf, 1);
170  else if (al.val("-otype", 0) == "ind")
171  {
172  if (al.present("-a"))
173  save_ind_RelationList(out_file, mlf, "Addresses", path);
174  else
175  save_ind_RelationList(out_file, mlf, "None", path);
176  }
177  else
178 // lab.save(out_file, al.val("-otype", 0), "None");
179  lab.save(out_file,al.val("-otype"));
180 
181  return 0;
182 }
183 
184 void override_lib_ops(EST_Option &a_list, EST_Option &al)
185 {
186  a_list.override_val("frame_shift", al.val("-S", 0));
187  a_list.override_val("in_lab_file_type", al.val("-itype", 0));
188  a_list.override_val("out_lab_file_type", al.val("-otype", 0));
189  a_list.override_val("label_offset", al.val("-off", 0));
190  a_list.override_val("label_range", al.val("-range", 0));
191 
192  if (al.val("-style", 0) == "track")
193  a_list.override_val("track_file_type", al.val("-otype", 0));
194 }
195 
const T & first() const
return const reference to first item in list
Definition: EST_TList.h:154
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:48
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...
EST_write_status save(const EST_String name, const EST_String EST_filetype="")
Definition: EST_Track.cc:1230
const int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition: EST_TKVL.cc:145
EST_write_status save(const EST_String &filename, bool evaluate_ff=false) const
EST_read_status load(const EST_String &filename, const EST_String &type="esps")
EST_read_status load_StrList(EST_String filename, EST_StrList &l)
Load tokens from a file and return them in a EST_StrList.
Utility EST_String Functions header file.