online-decodable.cc
Go to the documentation of this file.
1 // online/online-decodable.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 
24 
25 namespace kaldi {
26 
28  const AmDiagGmm &am, const TransitionModel &trans_model,
29  const BaseFloat scale, OnlineFeatureMatrix *input_feats):
30  features_(input_feats), ac_model_(am),
31  ac_scale_(scale), trans_model_(trans_model),
32  feat_dim_(input_feats->Dim()), cur_frame_(-1) {
33  if (!input_feats->IsValidFrame(0)) {
34  // It's not safe to throw from a constructor, so please check
35  // this condition yourself before reaching this point in the code.
36  KALDI_ERR << "Attempt to initialize decodable object with empty "
37  << "input: please check this before the initializer!";
38  }
39  int32 num_pdfs = trans_model_.NumPdfs();
40  cache_.resize(num_pdfs, std::pair<int32,BaseFloat>(-1, 0.0));
41 }
42 
44  KALDI_ASSERT(frame >= 0);
45  cur_feats_.Resize(feat_dim_);
46  if (!features_->IsValidFrame(frame))
47  KALDI_ERR << "Request for invalid frame (you need to check IsLastFrame, or, "
48  << "for frame zero, check that the input is valid.";
49  cur_feats_.CopyFromVec(features_->GetFrame(frame));
50  cur_frame_ = frame;
51 }
52 
54  if (frame != cur_frame_)
55  CacheFrame(frame);
56  int32 pdf_id = trans_model_.TransitionIdToPdf(index);
57  if (cache_[pdf_id].first == frame)
58  return cache_[pdf_id].second;
60  cache_[pdf_id].first = frame;
61  cache_[pdf_id].second = ans;
62  return ans;
63 }
64 
65 
67  return !features_->IsValidFrame(frame+1);
68 }
69 
70 } // namespace kaldi
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
OnlineDecodableDiagGmmScaled(const AmDiagGmm &am, const TransitionModel &trans_model, const BaseFloat scale, OnlineFeatureMatrix *input_feats)
std::vector< std::pair< int32, BaseFloat > > cache_
kaldi::int32 int32
int32 TransitionIdToPdf(int32 trans_id) const
const TransitionModel & trans_model_
BaseFloat LogLikelihood(const int32 pdf_index, const VectorBase< BaseFloat > &data) const
Definition: am-diag-gmm.h:108
#define KALDI_ERR
Definition: kaldi-error.h:147
SubVector< BaseFloat > GetFrame(int32 frame)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
virtual BaseFloat LogLikelihood(int32 frame, int32 index)
Returns the log likelihood, which will be negated in the decoder.
virtual bool IsLastFrame(int32 frame) const
Returns true if this is the last frame.