summaryrefslogtreecommitdiff
path: root/htk_io/init.lua
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2015-06-25 12:56:45 +0800
committerDeterminant <[email protected]>2015-06-25 12:56:45 +0800
commita74183ddb4ab8383bfe214b3745eb8a0a99ee47a (patch)
treed5e69cf8c4c2db2e3a4722778352fc3c95953bb2 /htk_io/init.lua
parentb6301089cde20f4c825c7f5deaf179082aad63da (diff)
let HTK I/O implementation be a single package
Diffstat (limited to 'htk_io/init.lua')
-rw-r--r--htk_io/init.lua62
1 files changed, 62 insertions, 0 deletions
diff --git a/htk_io/init.lua b/htk_io/init.lua
new file mode 100644
index 0000000..27ece6e
--- /dev/null
+++ b/htk_io/init.lua
@@ -0,0 +1,62 @@
+require 'libhtkio'
+local TNetReader = nerv.class("nerv.TNetReader", "nerv.DataReader")
+
+function TNetReader:__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.TNetFeatureRepo(reader_conf.scp_file,
+ reader_conf.conf_file,
+ reader_conf.frm_ext)
+ self.lab_repo = {}
+ for id, mlf_spec in pairs(reader_conf.mlfs) do
+ self.lab_repo[id] = nerv.TNetLabelRepo(mlf_spec.file,
+ mlf_spec.format,
+ mlf_spec.format_arg,
+ mlf_spec.dir,
+ mlf_spec.ext)
+ end
+end
+
+function TNetReader:get_data()
+ if self.feat_repo:is_end() then
+ return nil
+ end
+ local res = {}
+ local frm_ext = self.frm_ext
+ local step = frm_ext * 2 + 1
+ -- read HTK feature
+ local feat_utter = self.feat_repo:cur_utter(self.debug)
+ -- expand the feature
+ local expanded = self.gconf.cumat_type(feat_utter:nrow(), feat_utter:ncol() * step)
+ expanded:expand_frm(self.gconf.cumat_type.new_from_host(feat_utter), frm_ext)
+ -- rearrange the feature (``transpose'' operation in TNet)
+ local rearranged = expanded:create()
+ rearranged:rearrange_frm(expanded, step)
+ -- prepare for transf
+ local input = {rearranged}
+ local output = {rearranged:create()}
+ -- do transf
+ self.global_transf:init(input[1]:nrow())
+ self.global_transf:propagate(input, output)
+ -- trim frames
+ expanded = self.gconf.mmat_type(output[1]:nrow() - frm_ext * 2, output[1]:ncol())
+ output[1]:copy_toh(expanded, frm_ext, feat_utter:nrow() - frm_ext)
+ res[self.feat_id] = expanded
+ -- add corresponding labels
+ for id, repo in pairs(self.lab_repo) do
+ local lab_utter = repo:get_utter(self.feat_repo,
+ expanded:nrow(),
+ self.debug)
+ res[id] = lab_utter
+ end
+ -- move the pointer to next
+ self.feat_repo:next()
+ collectgarbage("collect")
+ return res
+end