63   using namespace kaldi;
    69         "Convert pairs of (phone-level, word-level) transcriptions to\n"    70         "output that indicates the phones assigned to each word.\n"    71         "Format is standard format for archives of vector<vector<int32> >\n"    73         "utt-id  600 4 7 19 ; 512 4 18 ; 0 1\n"    74         "where 600, 512 and 0 are the word-ids (0 for non-word phones, e.g.\n"    75         "optional-silence introduced by the lexicon), and the phone-ids\n"    76         "follow the word-ids.\n"    77         "Note: L_align.fst must have word-start and word-end symbols in it\n"    79         "Usage:  phones-to-prons [options] <L_align.fst> <word-start-sym> "    80         "<word-end-sym> <phones-rspecifier> <words-rspecifier> <prons-wspecifier>\n"    82         " ali-to-phones 1.mdl ark:1.ali ark:- | \\\n"    83         "  phones-to-prons L_align.fst 46 47 ark:- "    84         "'ark:sym2int.pl -f 2- words.txt text|' ark:1.prons\n";
    89     if (po.NumArgs() != 6) {
    95     std::string lex_fst_filename = po.GetArg(1),
    96         word_start_sym_str = po.GetArg(2),
    97         word_end_sym_str = po.GetArg(3),
    98         phones_rspecifier = po.GetArg(4),
    99         words_rspecifier = po.GetArg(5),
   100         prons_wspecifier = po.GetArg(6);
   102     int32 word_start_sym, word_end_sym;
   105         || word_start_sym <= 0)
   106       KALDI_ERR << 
"Invalid word start symbol (expecting integer >= 0): "   107                  << word_start_sym_str;
   109         || word_end_sym <= 0 || word_end_sym == word_start_sym)
   110       KALDI_ERR << 
"Invalid word end symbol (expecting integer >= 0"   111                  << 
", different from word start symbol): "   118       fst::OLabelCompare<StdArc> olabel_comp;
   119       ArcSort(L, olabel_comp);
   125     int32 n_done = 0, n_err = 0;
   130     for (; !phones_reader.Done(); phones_reader.Next()) {
   131       std::string key = phones_reader.Key();
   132       const std::vector<int32> &phones = phones_reader.Value();
   133       if (!words_reader.HasKey(key)) {
   134         KALDI_WARN << 
"Not processing utterance " << key << 
" because no word "   135                    << 
"transcription found.";
   139       const std::vector<int32> &
words = words_reader.Value(key);
   146       VectorFst<StdArc> phn2word;
   148         VectorFst<StdArc> words_acceptor;
   150         Compose(*L, words_acceptor, &phn2word);
   152       if (phn2word.Start() == fst::kNoStateId) {
   153         KALDI_WARN << 
"Phone to word FST for utterance " << key
   154                    << 
"is empty (either decoding for this utterance did "   155                    << 
"not reach end-state, or mismatched lexicon.)";
   160       VectorFst<StdArc> phones_alt_fst;
   165       VectorFst<StdArc> phnx2word;
   166       Compose(phones_alt_fst, phn2word, &phnx2word);
   168       if (phnx2word.Start() == fst::kNoStateId) {
   169         KALDI_WARN << 
"phnx2word FST for utterance " << key
   170                    << 
"is empty (either decoding for this utterance did "   171                    << 
"not reach end-state, or mismatched lexicon.)";
   174           fst::FstPrinter<StdArc> fstprinter(phn2word, NULL, NULL, NULL, 
false, 
true, 
"\t");
   175           fstprinter.Print(&std::cerr, 
"standard error");
   177           for (
size_t i = 0; 
i < phones.size(); 
i++)
   178             std::cerr << phones[
i] << 
' ';
   185       VectorFst<StdArc> phnx2word_best;
   186       ShortestPath(phnx2word, &phnx2word_best);
   189       std::vector<int32> phnx, words2;
   192                                         &phnx, &words2, &garbage))
   193         KALDI_ERR << 
"phnx2word is not a linear transducer (code error?)";
   195         KALDI_ERR << 
"words have changed! (code error?)";
   200       std::vector<std::vector<int32> > prons;
   202                               word_start_sym, word_end_sym,
   204         KALDI_WARN << 
"Error converting phones and words to prons "   205                    << 
" (mismatched or non-marked lexicon or partial "   210       prons_writer.Write(key, prons);
   213     KALDI_LOG << 
"Done " << n_done << 
" utterances; " << n_err << 
" had errors.";
   214   } 
catch(
const std::exception &e) {
   215     std::cerr << e.what();
 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
 
bool ConvertStringToInteger(const std::string &str, Int *out)
Converts a string into an integer via strtoll and returns false if there was any kind of problem (i...
 
bool ConvertPhnxToProns(const std::vector< int32 > &phnx, const std::vector< int32 > &words, int32 word_start_sym, int32 word_end_sym, std::vector< std::vector< int32 > > *prons)
 
A templated class for writing objects to an archive or script file; see The Table concept...
 
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST. 
 
Allows random access to a collection of objects in an archive or script file; see The Table concept...
 
void MakeLinearAcceptor(const std::vector< I > &labels, MutableFst< Arc > *ofst)
Creates unweighted linear acceptor from symbol sequence. 
 
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...
 
void CreatePhonesAltFst(const std::vector< int32 > &phones, int32 word_start_sym, int32 word_end_sym, fst::VectorFst< fst::StdArc > *ofst)
 
fst::StdArc::Weight Weight
 
int32 g_kaldi_verbose_level
This is set by util/parse-options. 
 
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)