summaryrefslogtreecommitdiff
path: root/kaldi_io/init.lua
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2015-08-14 11:51:42 +0800
committerDeterminant <[email protected]>2015-08-14 11:51:42 +0800
commit96a32415ab43377cf1575bd3f4f2980f58028209 (patch)
tree30a2d92d73e8f40ac87b79f6f56e227bfc4eea6e /kaldi_io/init.lua
parentc177a7549bd90670af4b29fa813ddea32cfe0f78 (diff)
add implementation for kaldi io (by ymz)
Diffstat (limited to 'kaldi_io/init.lua')
-rw-r--r--kaldi_io/init.lua47
1 files changed, 47 insertions, 0 deletions
diff --git a/kaldi_io/init.lua b/kaldi_io/init.lua
new file mode 100644
index 0000000..0ad3a60
--- /dev/null
+++ b/kaldi_io/init.lua
@@ -0,0 +1,47 @@
+require 'libkaldiio'
+require 'speech_utils'
+local KaldiReader = nerv.class("nerv.KaldiReader", "nerv.DataReader")
+
+function KaldiReader:__init(global_conf, reader_conf)
+ self.feat_id = reader_conf.id
+ self.frm_ext = reader_conf.frm_ext
+ self.gconf = global_conf
+ self.global_transf = reader_conf.global_transf
+ self.debug = global_conf.debug
+ if self.debug == nil then
+ self.debug = false
+ end
+ self.feat_repo = nerv.KaldiFeatureRepo(reader_conf.feature_rspecifier)
+
+ self.lab_repo = {}
+ for id, mlf_spec in pairs(reader_conf.mlfs) do
+ self.lab_repo[id] = nerv.KaldiLabelRepo(mlf_spec.targets_rspecifier,
+ mlf_spec.format)
+ end
+end
+
+function KaldiReader:get_data()
+ if self.feat_repo:is_end() then
+ return nil
+ end
+ local res = {}
+ -- read Kaldi feature
+ local feat_utter = self.feat_repo:cur_utter(self.debug)
+ -- global transf
+ local transformed = nerv.speech_utils.global_transf(feat_utter,
+ self.global_transf, self.frm_ext, 0, self.gconf)
+ res[self.feat_id] = transformed
+ -- add corresponding labels
+ for id, repo in pairs(self.lab_repo) do
+ local lab_utter = repo:get_utter(self.feat_repo,
+ self.frm_ext,
+ transformed:nrow(),
+ self.debug)
+ res[id] = lab_utter
+ --print(lab_utter)
+ end
+ -- move the pointer to next
+ self.feat_repo:next()
+ collectgarbage("collect")
+ return res
+end