28 using namespace kaldi;
32 "Display alignments in human-readable form\n" 33 "Usage: show-alignments [options] <phone-syms> <model> <alignments-rspecifier>\n" 35 " show-alignments phones.txt 1.mdl ark:1.ali\n" 36 "See also: ali-to-phones, copy-int-vector\n";
41 if (po.NumArgs() != 3) {
46 std::string phones_symtab_filename = po.GetArg(1),
47 model_filename = po.GetArg(2),
48 alignments_rspecifier = po.GetArg(3);
53 fst::SymbolTable *phones_symtab = NULL;
55 std::ifstream is(phones_symtab_filename.c_str());
56 phones_symtab = fst::SymbolTable::ReadText(is, phones_symtab_filename);
57 if (!phones_symtab || phones_symtab->NumSymbols() == 0)
58 KALDI_ERR <<
"Error opening symbol table file "<<phones_symtab_filename;
64 for (; !reader.Done(); reader.Next()) {
65 std::string key = reader.Key();
66 const std::vector<int32> &alignment = reader.Value();
68 std::vector<std::vector<int32> > split;
72 std::vector<std::string> split_str(split.size());
73 std::vector<std::string> split_str_phones(split.size());
74 for (
size_t i = 0;
i < split.size();
i++) {
75 std::ostringstream ss;
77 for (
size_t j = 0;
j < split[
i].size();
j++)
78 ss << split[
i][
j] <<
" ";
80 split_str[
i] = ss.str();
82 int32 tid = split[
i][0],
86 phones_symtab->Find(phone) +
" ";
88 int len = abs(static_cast<int>(split_str[
i].size())-
89 static_cast<int>(split_str_phones[
i].size()));
90 for (
int j = 0;
j < len;
j++)
92 if (split_str[
i].size() < split_str_phones[
i].size())
93 split_str[
i] += space;
95 split_str_phones[
i] += space;
97 std::cout << key <<
" ";
98 for (
size_t i = 0;
i < split_str.size();
i++)
99 std::cout << split_str[
i];
101 std::cout << key <<
" ";
102 for (
size_t i = 0;
i < split_str_phones.size();
i++)
103 std::cout << split_str_phones[
i];
107 delete phones_symtab;
108 phones_symtab = NULL;
109 }
catch(
const std::exception &e) {
110 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
bool SplitToPhones(const TransitionModel &trans_model, const std::vector< int32 > &alignment, std::vector< std::vector< int32 > > *split_alignment)
SplitToPhones splits up the TransitionIds in "alignment" into their individual phones (one vector per...
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...
int32 TransitionIdToTransitionState(int32 trans_id) const
int32 TransitionStateToPhone(int32 trans_state) const