From 119f9091ea60d81efabd7d20ff2490b9e7084778 Mon Sep 17 00:00:00 2001 From: Eric Bi Date: Tue, 1 Dec 2015 17:03:39 +0800 Subject: add detection of utterances without alignment, and skip them --- kaldi_io/init.lua | 8 ++++++++ kaldi_io/src/cwrapper_kaldi.cpp | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/kaldi_io/init.lua b/kaldi_io/init.lua index e538ee5..5193504 100644 --- a/kaldi_io/init.lua +++ b/kaldi_io/init.lua @@ -36,6 +36,7 @@ function KaldiReader:__init(global_conf, reader_conf) end function KaldiReader:get_data() + local fail_to_read_alignment = false if self.feat_repo:is_end() then return nil end @@ -75,6 +76,9 @@ function KaldiReader:get_data() local lab_utter = repo:get_utter(self.feat_repo, feat_utter:nrow(), self.debug) + if lab_utter == nil then + fail_to_read_alignment = true + end res[id] = lab_utter end -- add corresponding lookup features @@ -98,5 +102,9 @@ function KaldiReader:get_data() -- move the pointer to next self.feat_repo:next() collectgarbage("collect") + if fail_to_read_alignment then + nerv.info("[Kaldi IO] utterance %s alignment not found, skip it.", self.feat_repo:key()) + res = self:get_data() + end return res end diff --git a/kaldi_io/src/cwrapper_kaldi.cpp b/kaldi_io/src/cwrapper_kaldi.cpp index d16f316..542f1d0 100644 --- a/kaldi_io/src/cwrapper_kaldi.cpp +++ b/kaldi_io/src/cwrapper_kaldi.cpp @@ -150,8 +150,12 @@ extern "C" { Matrix *kaldi_label_repo_read_utterance(KaldiLabelRepo *repo, KaldiFeatureRepo *frepo, int nframes, lua_State *L, int debug) { - Matrix *mat; - kaldi::Posterior targets = repo->targets_reader->Value(frepo->utt); + Matrix *mat = NULL; + /* check if the alignment of the utterance exists, otherwise return NULL */ + kaldi::Posterior targets; + if (repo->targets_reader->HasKey(frepo->utt)) + targets = repo->targets_reader->Value(frepo->utt); + else return mat; int n = targets.size() < nframes ? targets.size() : nframes; int m = (int)targets[0].size(); -- cgit v1.2.3-70-g09d2