25 int main(
int argc,
char *argv[]) {
27 using namespace kaldi;
31 "Reads lattices which must be linear (single path), and must be in\n" 32 "CompactLattice form where the transition-ids on the arcs\n" 33 "have been aligned with the word boundaries (see lattice-align-words*)\n" 34 "and outputs a vaguely ctm-like format where each line is of the form:\n" 35 "<utterance-id> <begin-frame> <num-frames> <word> <phone1> <phone2> ... <phoneN>\n" 36 "where the words and phones will both be written as integers. For arcs\n" 37 "in the input lattice that don't correspond to words, <word> may be zero; this\n" 38 "will typically be the case for the optional silences.\n" 40 "Usage: nbest-to-prons [options] <model> <aligned-linear-lattice-rspecifier> <output-wxfilename>\n" 41 "e.g.: lattice-1best --acoustic-weight=0.08333 ark:1.lats | \\\n" 42 " lattice-align-words data/lang/phones/word_boundary.int exp/dir/final.mdl ark:- ark:- | \\\n" 43 " nbest-to-prons exp/dir/final.mdl ark:- 1.prons\n" 44 "Note: the type of the model doesn't matter as only the transition-model is read.\n";
48 bool print_lengths_per_phone =
false;
49 po.
Register(
"print-lengths-per-phone", &print_lengths_per_phone,
50 "If true, in place of the length of the word, " 51 "print out a comma-separated list of the lengths of each phone in the word.");
61 std::string model_rxfilename = po.
GetArg(1),
62 lats_rspecifier = po.
GetArg(2),
71 int32 n_done = 0, n_err = 0;
73 Output ko(wxfilename,
false);
75 for (; !clat_reader.
Done(); clat_reader.
Next()) {
76 std::string utt = clat_reader.
Key();
79 std::vector<int32>
words, times, lengths;
80 std::vector<std::vector<int32> > prons;
81 std::vector<std::vector<int32> > phone_lengths;
84 &prons, &phone_lengths)) {
86 KALDI_WARN <<
"Format conversion failed for utterance " << utt;
89 words.size() == lengths.size() &&
90 words.size() == prons.size());
91 for (
size_t i = 0;
i < words.size();
i++) {
92 int32 sum_of_plengths = 0;
93 for (
size_t j = 0;
j < phone_lengths[
i].size();
j++)
94 sum_of_plengths += phone_lengths[
i][
j];
97 if (!print_lengths_per_phone)
98 ko.
Stream() << utt <<
' ' << times[
i] <<
' ' << lengths[
i] <<
' ' 101 ko.
Stream() << utt <<
' ' << times[
i] <<
' ';
102 for (
size_t pl = 0; pl < phone_lengths[
i].size()-1; pl++)
103 ko.
Stream() << phone_lengths[
i][pl] <<
',';
104 ko.
Stream() << phone_lengths[
i][phone_lengths[
i].size()-1]
107 for (
size_t j = 0;
j < prons[
i].size();
j++)
119 KALDI_LOG <<
"Printed prons for " << n_done <<
" linear lattices; " 120 << n_err <<
" had errors.";
121 return (n_done != 0 ? 0 : 1);
122 }
catch(
const std::exception &e) {
123 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void Register(const std::string &name, bool *ptr, const std::string &doc)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
int main(int argc, char *argv[])
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
fst::VectorFst< CompactLatticeArc > CompactLattice
int NumArgs() const
Number of positional parameters (c.f. argc-1).
#define KALDI_ASSERT(cond)
bool CompactLatticeToWordProns(const TransitionModel &tmodel, const CompactLattice &clat, std::vector< int32 > *words, std::vector< int32 > *begin_times, std::vector< int32 > *lengths, std::vector< std::vector< int32 > > *prons, std::vector< std::vector< int32 > > *phone_lengths)
This function takes a CompactLattice that should only contain a single linear sequence (e...