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