onlinebin-util.cc
Go to the documentation of this file.
1 // online/onlinebin-util.cc
2 
3 // Copyright 2012 Cisco Systems (author: Matthias Paulik)
4 
5 // Modifications to the original contribution by Cisco Systems made by:
6 // Vassil Panayotov
7 
8 // See ../../COPYING for clarification regarding multiple authors
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
18 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
19 // MERCHANTABLITY OR NON-INFRINGEMENT.
20 // See the Apache 2 License for the specific language governing permissions and
21 // limitations under the License.
22 
23 #include "onlinebin-util.h"
24 
25 namespace kaldi {
26 
27 fst::Fst<fst::StdArc> *ReadDecodeGraph(const std::string& filename) {
28  // read decoding network FST
29  Input ki(filename); // use ki.Stream() instead of is.
30  if (!ki.Stream().good()) KALDI_ERR << "Could not open decoding-graph FST "
31  << filename;
32 
33  fst::FstHeader hdr;
34  if (!hdr.Read(ki.Stream(), "<unknown>")) {
35  KALDI_ERR << "Reading FST: error reading FST header.";
36  }
37  if (hdr.ArcType() != fst::StdArc::Type()) {
38  KALDI_ERR << "FST with arc type " << hdr.ArcType() << " not supported.";
39  }
40  fst::FstReadOptions ropts("<unspecified>", &hdr);
41 
42  fst::Fst<fst::StdArc> *decode_fst = NULL;
43 
44  if (hdr.FstType() == "vector") {
45  decode_fst = fst::VectorFst<fst::StdArc>::Read(ki.Stream(), ropts);
46  } else if (hdr.FstType() == "const") {
47  decode_fst = fst::ConstFst<fst::StdArc>::Read(ki.Stream(), ropts);
48  } else {
49  KALDI_ERR << "Reading FST: unsupported FST type: " << hdr.FstType();
50  }
51  if (decode_fst == NULL) { // fst code will warn.
52  KALDI_ERR << "Error reading FST (after reading header).";
53  return NULL;
54  } else {
55  return decode_fst;
56  }
57 }
58 
59 
60 void PrintPartialResult(const std::vector<int32>& words,
61  const fst::SymbolTable *word_syms,
62  bool line_break) {
63  KALDI_ASSERT(word_syms != NULL);
64  for (size_t i = 0; i < words.size(); i++) {
65  std::string word = word_syms->Find(words[i]);
66  if (word == "")
67  KALDI_ERR << "Word-id " << words[i] <<" not in symbol table.";
68  std::cout << word << ' ';
69  }
70  if (line_break)
71  std::cout << "\n\n";
72  else
73  std::cout.flush();
74 }
75 
76 } // namespace kaldi
int32 words[kMaxOrder]
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void PrintPartialResult(const std::vector< int32 > &words, const fst::SymbolTable *word_syms, bool line_break)
std::istream & Stream()
Definition: kaldi-io.cc:826
#define KALDI_ERR
Definition: kaldi-error.h:147
fst::Fst< fst::StdArc > * ReadDecodeGraph(const std::string &filename)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185