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