summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kaldi_io/init.lua8
-rw-r--r--kaldi_io/src/cwrapper_kaldi.cpp9
2 files changed, 15 insertions, 2 deletions
diff --git a/kaldi_io/init.lua b/kaldi_io/init.lua
index 2173230..751247a 100644
--- a/kaldi_io/init.lua
+++ b/kaldi_io/init.lua
@@ -41,6 +41,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
@@ -87,6 +88,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
@@ -110,5 +114,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] 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 e8b11a1..788128b 100644
--- a/kaldi_io/src/cwrapper_kaldi.cpp
+++ b/kaldi_io/src/cwrapper_kaldi.cpp
@@ -159,8 +159,13 @@ extern "C" {
Matrix *kaldi_label_repo_read_utterance(KaldiLabelRepo *repo, KaldiFeatureRepo *frepo, int nframes,
lua_State *L,
int debug, MContext *context) {
- 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();