Edinburgh Speech Tools  2.1-release
ch_utt_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  /* */
34  /* Authors: Richard Caley */
35  /* ------------------------------------------------------------------- */
36  /* Label conversion main file */
37  /* */
38  /*************************************************************************/
39 
40 
41 #include <cstdlib>
42 #include "EST_error.h"
43 #include "EST_ling_class.h"
44 #include "EST_cmd_line.h"
45 
46 using namespace std;
47 
48 int main(int argc, char *argv[])
49 {
50  EST_String out_file, ext;
51  EST_StrList files;
52  EST_Option al;
53 
54  parse_command_line(argc, argv,
55  EST_String("Usage: "
56  "ch_utt <input file> -o <output file> <options>\n"
57  "Summary: change/copy utterance file\n"
58  "use \"-\" to make input and output files stdin/out\n"
59  "-h Options help\n"
60  "-f <string> Feature to use as item ID when merging utterances.\n"
61  "-o <ofile> output file name\n"
62  "-otype <string> output file type: \n"
63  "-sysdir <string> Look for unqualified system entities in this directory"
65  files, al);
66 
67  EST_Utterance utt;
68  EST_read_status rstat;
69 
70  EST_String feat = al.present("-f")?al.sval("-f"):EST_String("name");
71 
72  if (al.present("-sysdir"))
73  utterance_xml_register_id("^\\([^/]*\\)",
74  al.sval("-sysdir") + "/\\1");
75 
76  rstat=utt.load(files.first());
77 
78  if (rstat == read_format_error)
79  EST_error("Bad format in %s", (const char *)files.first());
80  else if (rstat != read_ok)
81  EST_sys_error("Error reading %s", (const char *)files.first());
82 
83  EST_Utterance u;
84 
85  EST_Litem *fp = files.head()->next();
86  for(; fp != NULL; fp=fp->next())
87  {
88  rstat = u.load(files(fp));
89 
90  if (rstat == read_format_error)
91  EST_error("Bad format in %s", (const char *)files(fp));
92  else if (rstat != read_ok)
93  EST_sys_error("Error reading %s", (const char *)files(fp));
94 
95  utterance_merge(utt, u, feat);
96  }
97 
98  EST_String otype = al.present("-otype")? al.sval("-otype") : (EST_String)"est";
99 
100  if (al.present("-o"))
101  utt.save(al.sval("-o"), otype);
102  else
103  {
104  utt.save("-", otype);
105  }
106 
107  return 0;
108 }
109 
int utterance_merge(EST_Utterance &utt, EST_Utterance &sub_utt, EST_Item *utt_root, EST_Item *sub_root)
EST_write_status save(const EST_String &filename, const EST_String &type="est_ascii") const
EST_read_status load(const EST_String &filename)
The file was read in successfully.
EST_UItem * next()
Definition: EST_UList.h:55
EST_String options_utterance_filetypes_long(void)
const EST_String & sval(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:93
#define EST_sys_error
Definition: EST_error.h:108
The file exists but is not in the format specified.
NULL
Definition: EST_WFST.cc:55
#define EST_error
Definition: EST_error.h:104
const T & first() const
return const reference to first item in list
Definition: EST_TList.h:152
EST_read_status
int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
EST_UItem * head() const
Definition: EST_UList.h:97
LISP fp
Definition: kkcompile.cc:63
EST_String
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
void utterance_xml_register_id(const EST_String pattern, const EST_String result)
int main(int argc, char *argv[])
Definition: ch_utt_main.cc:48