42 using namespace kaldi;
45 typedef kaldi::uint64 uint64;
48 "Build a linear acceptor for each transcription in the archive. " 49 "Read in the transcriptions in archive format and write out the linear " 50 "acceptors in archive format with the same key. The costs of " 51 "the arcs are set to be zero. The cost of the acceptor can be changed\n" 52 "by supplying the costs archive. In that case, the first arc's cost\n" 53 "will be set to the value obtained from the archive, i.e. the total\n" 54 "cost will be equal to cost. The cost archive can be sparse, i.e.\n" 55 "does not have to include zero-cost transcriptions. It is prefered\n" 56 "for the archive to be sorted (for efficiency).\n" 59 " transcripts-to-fsts [options] <transcriptions-rspecifier>" 60 " [<costs-rspecifier>] <fsts-wspecifier>\n" 62 " transcripts-to-fsts ark:train.tra ark,s,cs,t:costs.txt " 67 std::string left_compose =
"";
68 std::string right_compose =
"";
69 bool project_input =
false;
70 bool project_output =
false;
72 po.Register(
"left-compose", &left_compose,
73 "Compose the given FST to the left");
74 po.Register(
"right-compose", &right_compose,
75 "Compose the given FST to the right");
76 po.Register(
"project-input", &project_input,
77 "Project input labels if true " 78 "(makes sense only with connection to left|right composition)");
79 po.Register(
"project-output", &project_output,
80 "Project output labels if true" 81 "(makes sense only with connection to left|right composition)");
85 if (po.NumArgs() < 2 || po.NumArgs() > 3) {
90 std::string transcript_rspecifier,
94 if ( po.NumArgs() == 2 ) {
95 transcript_rspecifier = po.GetArg(1);
96 fst_wspecifier = po.GetArg(2);
98 transcript_rspecifier = po.GetArg(1);
99 costs_rspecifier = po.GetArg(2);
100 fst_wspecifier = po.GetArg(3);
109 VectorFst<StdArc> *lfst = NULL;
110 VectorFst<StdArc> *rfst = NULL;
111 if (left_compose !=
"") {
114 if (right_compose !=
"") {
119 for (; !transcript_reader.Done(); transcript_reader.Next()) {
120 std::string key = transcript_reader.Key();
121 std::vector<int32> transcript = transcript_reader.Value();
122 transcript_reader.FreeCurrent();
124 VectorFst<StdArc>
fst;
126 if (costs_reader.IsOpen() && costs_reader.HasKey(key)) {
127 double cost = costs_reader.Value(key);
132 VectorFst<StdArc> composed_fst;
133 Compose(*lfst, fst, &composed_fst);
138 VectorFst<StdArc> composed_fst;
139 Compose(fst, *rfst, &composed_fst);
144 Project(&fst, PROJECT_INPUT);
147 if (project_output) {
148 Project(&fst, PROJECT_OUTPUT);
151 fst_writer.Write(key, fst);
159 KALDI_LOG <<
"Done " << n_done <<
" transcriptions";
160 return (n_done != 0 ? 0 : 1);
161 }
catch(
const std::exception &e) {
162 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
A templated class for writing objects to an archive or script file; see The Table concept...
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.
void SetLinearAcceptorWeight(double cost, fst::VectorFst< fst::StdArc > *fst)
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 ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)