Edinburgh Speech Tools  2.1-release
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tilt_analysis_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 */
34 /* Date : Oct 95 */
35 /*-----------------------------------------------------------------------*/
36 /* Event RFC and Tilt labelling */
37 /* */
38 /*=======================================================================*/
39 
40 #include <cstdlib>
41 #include "EST_tilt.h"
42 #include "sigpr/EST_sigpr_utt.h"
43 #include "EST_cmd_line_options.h"
44 #include "ling_class/EST_relation_aux.h"
45 #include "EST_string_aux.h"
46 
47 #define SIL_NAMES "sil !ENTER !EXIT"
48 #define EVENT_NAMES "a rb arb m mrb"
49 
50 void set_fn_start(EST_Relation &ev);
52 void override_rfc_params(EST_Features &rfc, EST_Option &al);
54 void change_label(EST_Relation &seg, const EST_StrList &oname,
55  const EST_String &nname);
56 
57 void set_options(EST_Option &al, EST_Features &op);
58 
59 void option_override(EST_Features &op, EST_Option al,
60  const EST_String &option, const EST_String &arg);
61 
62 
63 
64 
65 
66 void extract_channels(EST_Wave &single, const EST_Wave &multi, EST_IList &ch_list);
67 
68 
69 
70 
71 int main(int argc, char *argv[])
72 {
73  EST_Track fz, nfz;
74  EST_Relation ev;
75  EST_Option al;
76  EST_Features op;
77  EST_StrList files, event_list, sil_list;
78  EST_String out_file, pstring;
79  EST_Track speech, raw_fz;
80  EST_Relation sil_lab;
81  EST_Features rfc_op;
82 
83  parse_command_line
84  (argc, argv,
85  EST_String("[input f0 file] -e [input event label file] -o [output file]"
86  "[options]")+
87  "Summary: produce rfc file from events and f0 contour\n"
88  "use \"-\" to make input and output files stdin/out\n"
89  "-h Options help\n\n"+
90  options_track_input()+ "\n"
91  "-event_names <string> List of labels to be classed as events. \n"
92  " Lists are specified as quoted strings with spaces \n"
93  " separating each item, e.g.: \"a b c d\"\n\n"
94  "-sil_names <string> List of labels to be classed as silence \n"
95  " Lists are specified as quoted strings with spaces \n"
96  " separating each item, e.g.: \"pau sil #\"\n\n"
97  "-e <ifile> Input event label file. This file contains \n"
98  " the list of events to be parameterized, each with its approximate \n"
99  " start and stop time marked. This file also contains silencesn \n"
100  " which are used to decide where to insert and stop phrases \n\n"
101  "-o <ofile> Output label file\n\n"
102  "-otype <string> File type of output file \n\n"
103  "-limit <float> start and stop limit in seconds. The rfc \n"
104  " matching algorithm defines a search region within which it tries \n"
105  " all possible rise and fall shapes. This option specifies how much \n"
106  " before the input label start time and how much after the input \n"
107  " label end time the search region should be. Typical value, 0.1 \n\n"
108  "-range <float> Range of RFC search region. In addition to \n"
109  " the limit, the range defines the limits of the rfc matching \n"
110  " search region as a percentage of the overal input label \n"
111  " duration. Typical value, 0.25 (the search region is the first and \n"
112  " last 25% of the label) \n\n"
113  "-smooth Smooth and Interpolate input F0 contour. \n"
114  " rfc matching can only operate on smooth fully interpolated \n"
115  " contours. This option must be used if the contour hasn't already \n"
116  " been smoothed and interpolated\n\n"
117  "-w1 <float> length in seconds of smoothing window prior\n"
118  " to interpolation. Default value 0.05 \n\n"
119  "-w2 <float> length in seconds of smoothing window after\n"
120  " to interpolation. Default value 0.05 \n\n"
121  "-sf0 <ofile> Save f0 contour that results from smoothing \n"
122  "-rfc Save as RFC parameters instead of tilt\n\n",
123  files, al);
124 
125  default_rfc_params(rfc_op);
126  override_rfc_params(rfc_op, al);
127  set_options(al, op);
128 
129  out_file = al.present("-o") ? al.val("-o") : (EST_String)"-";
130 
131  if (read_track(nfz, files.first(), al) == -1)
132  exit(-1);
133  // REORG - extract proper f0 channel here
134  nfz.copy_sub_track(fz, 0, EST_ALL, 0, 1);
135 
136  if (ev.load(al.val("-e")) != format_ok)
137  exit(-1);
138 
139  pstring = (al.present("-event_names") ? al.val("-event_names"):
140  EST_String("a b ab pos"));
141  StringtoStrList(pstring, event_list);
142  convert_to_broad(ev, event_list, "int_event", 1);
143 
144  // ensure all sil_names are re-written as sil
145  pstring = (al.present("-sil_names") ? al.val("-sil_names"):
146  EST_String(SIL_NAMES));
147  StringtoStrList(pstring, sil_list);
148  change_label(ev, sil_list, "sil");
149 
150  if (al.present("-smooth"))
151  {
152  sil_lab = ev;
153  StringtoStrList("sil", sil_list);
154  convert_to_broad(sil_lab, sil_list, "pos", 0);
155  label_to_track(sil_lab, speech, fz.shift());
156  raw_fz = fz;
157  smooth_phrase(raw_fz, speech, op, fz);
158  }
159 
160  if (al.present("-sf0"))
161  fz.save(al.val("-sf0"));
162 
163  ev.f.set("name", "intevents");
164  ev.f.set("timing_style", "segment");
165 
166 // set_fn_start(ev);
167 
168  // main RFC analysis function
169  rfc_analysis(fz, ev, rfc_op);
170 
171  // convert to Tilt if necessary
172  if (!al.present("-rfc"))
173  {
174  rfc_to_tilt(ev);
175  ev.remove_item_feature("rfc");
176  }
177 
178  ev.save(out_file);
179 }
180 
181 
182 
183 void override_rfc_params(EST_Features &rfc, EST_Option &al)
184 {
185  if (al.present("-limit"))
186  {
187  rfc.set("start_limit", al.fval("-limit"));
188  rfc.set("stop_limit", al.fval("-limit", 0));
189  }
190  if (al.present("-range"))
191  rfc.set("range", al.fval("-range"));
192  if (al.present("-min_dur"))
193  rfc.set("min_event_duration", al.fval("-min_dur"));
194 }
195 
196 void set_options(EST_Option &al, EST_Features &op)
197 {
198  // Nobody else has set window_length or second_length so
199  // set defaults here
200  op.set("window_length",0.05);
201  op.set("second_length",0.05);
202  option_override(op, al, "window_length", "-w1");
203  option_override(op, al, "second_length", "-w2");
204 }
A class for storing digital waveforms. The waveform is stored as an array of 16 bit shorts...
Definition: EST_Wave.h:64
const T & first() const
return const reference to first item in list
Definition: EST_TList.h:154
float fval(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:98
void set(const EST_String &name, int ival)
Definition: EST_Features.h:186
void rfc_analysis(EST_Track &fz, EST_Relation &ev, EST_Features &op)
void smooth_phrase(EST_Track &c, EST_Track &speech, EST_Features &options, EST_Track &sm)
Definition: smooth_pda.cc:54
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
void rfc_to_tilt(EST_Features &rfc, EST_Features &tilt)
Convert a single set of local RFC parameters to local tilt parameters. See RFC to F0 Synthesis for a ...
Definition: tilt_utils.cc:172
EST_Features f
Definition: EST_Relation.h:100
EST_write_status save(const EST_String &filename, bool evaluate_ff=false) const
float shift() const
Definition: EST_Track.cc:599
void remove_item_feature(const EST_String &name)
EST_read_status load(const EST_String &filename, const EST_String &type="esps")
void copy_sub_track(EST_Track &st, int start_frame=0, int nframes=EST_ALL, int start_chan=0, int nchans=EST_ALL) const
Definition: EST_Track.cc:1136
void default_rfc_params(EST_Features &op)
Utility EST_String Functions header file.