Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

left-over code, not sure what happened...

  • Loading branch information...
commit 348929ed877561f0c890663c0b13adb2cfda5384 1 parent d32638a
SCE speech authored
15 speechsvr/kaldi.mk
View
@@ -2,8 +2,10 @@ CC = g++
CCFLAGS = -g -O2 -Wall \
-Wno-sign-compare -Winit-self \
-FSTROOT = /Users/Ben/projects/kaldi/tools/openfst
-KALDIROOT = /Users/Ben/projects/kaldi/src
+FSTROOT = /home/scespeech/kaldi/tools/openfst
+KALDIROOT = /home/scespeech/kaldi/src
+ATLASINC = /home/scespeech/kaldi/tools/ATLAS/include
+ATLASLIBS = /home/scespeech/kaldi/src/../tools/ATLAS/build/install/lib//liblapack.a /home/scespeech/kaldi/src/../tools/ATLAS/build/install/lib//libcblas.a /home/scespeech/kaldi/src/../tools/ATLAS/build/install/lib//libatlas.a /home/scespeech/kaldi/src/../tools/ATLAS/build/install/lib//libf77blas.a
LIBS += $(KALDIROOT)/lat/kaldi-lat.a \
$(KALDIROOT)/decoder/kaldi-decoder.a \
@@ -16,11 +18,12 @@ LIBS += $(KALDIROOT)/lat/kaldi-lat.a \
$(KALDIROOT)/util/kaldi-util.a \
$(KALDIROOT)/base/kaldi-base.a \
$(FSTROOT)/lib/libfst.a \
- -framework Accelerate \
- -lm -ldl
+ -lm -ldl -lpthread \
+ $(ATLASLIBS) \
+ #-framework Accelerate \
CCFLAGS += -DKALDI_DOUBLEPRECISION=0 -DHAVE_POSIX_MEMALIGN \
-DHAVE_EXECINFO_H=1 -DHAVE_CXXABI_H -rdynamic \
- -DHAVE_CLAPACK \
+ -DHAVE_ATLAS -I$(ATLASINC) \
-I$(KALDIROOT) \
- -I$(FSTROOT)/include \
+ -I$(FSTROOT)/include
116 speechsvr/online-decoder/online-faster-decoder.cc
View
@@ -205,6 +205,122 @@ OnlineFasterDecoder::TracebackNFrames(int32 nframes,
}
+// IsReordered returns true if the transitions were possibly reordered. This reordering
+// can happen in AddSelfLoops, if the "reorder" option was true.
+// This makes the out-transition occur before the self-loop transition.
+// The function returns false (no reordering) if there is not enough information in
+// the alignment to tell (i.e. no self-loop were taken), and in this case the calling
+// code doesn't care what the answer is.
+// The "alignment" vector contains a sequence of TransitionIds.
+
+
+static bool IsReordered(const TransitionModel &trans_model,
+ const std::vector<int32> &alignment) {
+ for (size_t i = 0; i+1 < alignment.size(); i++) {
+ int32 tstate1 = trans_model.TransitionIdToTransitionState(alignment[i]),
+ tstate2 = trans_model.TransitionIdToTransitionState(alignment[i+1]);
+ if (tstate1 != tstate2) {
+ bool is_loop_1 = trans_model.IsSelfLoop(alignment[i]),
+ is_loop_2 = trans_model.IsSelfLoop(alignment[i+1]);
+ KALDI_ASSERT(!(is_loop_1 && is_loop_2)); // Invalid.
+ if (is_loop_1) return true; // Reordered. self-loop is last.
+ if (is_loop_2) return false; // Not reordered. self-loop is first.
+ }
+ }
+
+ // Just one trans-state in whole sequence.
+ if (alignment.empty()) return false;
+ else {
+ bool is_loop_front = trans_model.IsSelfLoop(alignment.front()),
+ is_loop_back = trans_model.IsSelfLoop(alignment.back());
+ if (is_loop_front) return false; // Not reordered. Self-loop is first.
+ if (is_loop_back) return true; // Reordered. Self-loop is last.
+ return false; // We really don't know in this case but calling code should
+ // not care.
+ }
+}
+
+
+// SplitToPhonesInternal takes as input the "alignment" vector containing
+// a sequence of transition-ids, and appends a single vector to
+// "split_output" for each instance of a phone that occurs in the
+// output.
+// Returns true if the alignment passes some non-exhaustive consistency
+// checks (if the input does not start at the start of a phone or does not
+// end at the end of a phone, we should expect that false will be returned).
+
+static bool SplitToPhonesInternal(const TransitionModel &trans_model,
+ const std::vector<int32> &alignment,
+ bool reordered,
+ std::vector<std::vector<int32> > *split_output) {
+ if (alignment.empty()) return true; // nothing to split.
+ std::vector<size_t> end_points; // points at which phones end [in an
+ // stl iterator sense, i.e. actually one past the last transition-id within
+ // each phone]..
+
+ bool was_ok = true;
+ for (size_t i = 0; i < alignment.size(); i++) {
+ int32 trans_id = alignment[i];
+ if (trans_model.IsFinal(trans_id)) { // is final-prob
+ if (!reordered) end_points.push_back(i+1);
+ else { // reordered.
+ while (i+1 < alignment.size() &&
+ trans_model.IsSelfLoop(alignment[i+1])) {
+ assert(trans_model.TransitionIdToTransitionState(alignment[i]) ==
+ trans_model.TransitionIdToTransitionState(alignment[i+1]));
+ i++;
+ }
+ end_points.push_back(i+1);
+ }
+ } else if (i+1 == alignment.size()) {
+ // need to have an end-point at the actual end.
+ // but this is an error- should have been detected already.
+ was_ok = false;
+ end_points.push_back(i+1);
+ } else {
+ int32 this_state = trans_model.TransitionIdToTransitionState(alignment[i]),
+ next_state = trans_model.TransitionIdToTransitionState(alignment[i+1]);
+ if (this_state == next_state) continue; // optimization.
+ int32 this_phone = trans_model.TransitionStateToPhone(this_state),
+ next_phone = trans_model.TransitionStateToPhone(next_state);
+ if (this_phone != next_phone) {
+ // The phone changed, but this is an error-- we should have detected this via the
+ // IsFinal check.
+ was_ok = false;
+ end_points.push_back(i+1);
+ }
+ }
+ }
+
+ size_t cur_point = 0;
+ for (size_t i = 0; i < end_points.size(); i++) {
+ split_output->push_back(std::vector<int32>());
+ // The next if-statement just checks that the initial trans-id
+ // of the alignment is an initial-state of a phone (a cursory check
+ // that the alignment is plausible).
+ if (trans_model.TransitionStateToHmmState
+ (trans_model.TransitionIdToTransitionState
+ (alignment[cur_point])) != 0) was_ok= false;
+ for (size_t j = cur_point; j < end_points[i]; j++)
+ split_output->back().push_back(alignment[j]);
+ cur_point = end_points[i];
+ }
+ return was_ok;
+}
+
+
+bool SplitToPhones(const TransitionModel &trans_model,
+ const std::vector<int32> &alignment,
+ std::vector<std::vector<int32> > *split_alignment) {
+ assert(split_alignment != NULL);
+ split_alignment->clear();
+
+ bool is_reordered = IsReordered(trans_model, alignment);
+ return SplitToPhonesInternal(trans_model, alignment,
+ is_reordered, split_alignment);
+}
+
+
bool OnlineFasterDecoder::EndOfUtterance() {
fst::VectorFst<LatticeArc> trace;
int32 sil_frm = opts_.inter_utt_sil / (1 + utt_frames_ / opts_.max_utt_len_);
8 speechsvr/server.conf
View
@@ -6,7 +6,7 @@ lattice_beam = 6.0
left_context = 3
right_context = 3
acoustic_scale = 0.08
-symbol_file = /media/demo_updated/tri2b/graph_tg222pr/words.txt
-model_file = /media/demo_updated/tri2b/final.mdl
-fst_file = /media/demo_updated/tri2b/graph_tg222pr/HCLG.fst
-lda_file = /media/demo_updated/tri2b/final.mat
+symbol_file = /home/scespeech/demo_updated/tri2b/graph_tg222pr/words.txt
+model_file = /home/scespeech/demo_updated/tri2b/final.mdl
+fst_file = /home/scespeech/demo_updated/tri2b/graph_tg222pr/HCLG.fst
+lda_file = /home/scespeech/demo_updated/tri2b/final.mat
Please sign in to comment.
Something went wrong with that request. Please try again.