31 const fst::SymbolTable *word_syms,
32 const bool line_break,
33 const int32 serv_sock,
34 const sockaddr_in &client_addr) {
36 std::stringstream sstream;
37 for (
size_t i = 0;
i < words.size();
i++) {
38 std::string word = word_syms->Find(words[
i]);
40 KALDI_ERR <<
"Word-id " << words[
i] <<
" not in symbol table.";
41 sstream << word <<
' ';
46 ssize_t sent = sendto(serv_sock, sstream.str().c_str(), sstream.str().size(),
47 0,
reinterpret_cast<const sockaddr*
>(&client_addr),
50 KALDI_WARN <<
"sendto() call failed when tried to send recognition results";
56 int main(
int argc,
char *argv[]) {
58 using namespace kaldi;
64 const int32 kDeltaOrder = 2;
67 "Decode speech, using feature batches received over a network connection\n\n" 68 "Utterance segmentation is done on-the-fly.\n" 69 "Feature splicing/LDA transform is used, if the optional(last) argument " 71 "Otherwise delta/delta-delta(2-nd order) features are produced.\n\n" 72 "Usage: online-server-gmm-decode-faster [options] model-in" 73 "fst-in word-symbol-table silence-phones udp-port [lda-matrix-in]\n\n" 74 "Example: online-server-gmm-decode-faster --rt-min=0.3 --rt-max=0.5 " 75 "--max-active=4000 --beam=12.0 --acoustic-scale=0.0769 " 76 "model HCLG.fst words.txt '1:2:3:4:5' 1234 lda-matrix";
79 int32 cmn_window = 600,
81 int32 right_context = 4, left_context = 4;
90 po.
Register(
"left-context", &left_context,
"Number of frames of left context");
91 po.
Register(
"right-context", &right_context,
"Number of frames of right context");
92 po.
Register(
"acoustic-scale", &acoustic_scale,
93 "Scaling factor for acoustic likelihoods");
94 po.
Register(
"cmn-window", &cmn_window,
95 "Number of feat. vectors used in the running average CMN calculation");
96 po.
Register(
"min-cmn-window", &min_cmn_window,
97 "Minumum CMN window used at start of decoding (adds " 98 "latency only at start)");
106 std::string model_rxfilename = po.
GetArg(1),
107 fst_rxfilename = po.
GetArg(2),
108 word_syms_filename = po.
GetArg(3),
109 silence_phones_str = po.
GetArg(4),
111 int32 udp_port = atoi(po.
GetArg(5).c_str());
114 if (lda_mat_rspecifier !=
"") {
116 Input ki(lda_mat_rspecifier, &binary_in);
117 lda_transform.Read(ki.
Stream(), binary_in);
120 std::vector<int32> silence_phones;
122 KALDI_ERR <<
"Invalid silence-phones string " << silence_phones_str;
123 if (silence_phones.empty())
130 Input ki(model_rxfilename, &binary);
135 fst::SymbolTable *word_syms = NULL;
136 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
137 KALDI_ERR <<
"Could not read symbol table from file " 138 << word_syms_filename;
149 silence_phones, trans_model);
150 VectorFst<LatticeArc> out_fst;
151 int32 feature_dim = mfcc_opts.
num_ceps;
156 if (lda_mat_rspecifier !=
"") {
158 &cmn_input, lda_transform,
159 left_context, right_context);
162 opts.
order = kDeltaOrder;
173 std::cerr << std::endl <<
"Listening on UDP port " 174 << udp_port <<
" ... " << std::endl;
175 bool partial_res =
false;
178 std::vector<int32> word_ids;
182 static_cast<vector<int32> *
>(0),
184 static_cast<LatticeArc::Weight*>(0));
191 static_cast<vector<int32> *
>(0),
193 static_cast<LatticeArc::Weight*>(0));
197 partial_res = (word_ids.size() > 0);
202 delete feat_transform;
206 }
catch(
const std::exception& e) {
207 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
bool PartialTraceback(fst::MutableFst< LatticeArc > *out_fst)
void Register(OptionsItf *opts, bool full)
MfccOptions contains basic options for computing MFCC features.
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g.
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
DecodeState Decode(DecodableInterface *decodable)
int main(int argc, char *argv[])
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.
void Register(const std::string &name, bool *ptr, const std::string &doc)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void FinishTraceBack(fst::MutableFst< LatticeArc > *fst_out)
void Read(std::istream &is, bool binary)
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.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
fst::Fst< fst::StdArc > * ReadDecodeGraph(const std::string &filename)
#define KALDI_ASSERT(cond)
void Register(OptionsItf *opts)
void Register(OptionsItf *opts)
void Read(std::istream &in_stream, bool binary)
void SendPartialResult(const std::vector< int32 > &words, const fst::SymbolTable *word_syms, const bool line_break, const int32 serv_sock, const sockaddr_in &client_addr)
std::string GetOptArg(int param) const