summaryrefslogblamecommitdiff
path: root/htk_io/init.lua
blob: b836e15dea2120b30f1ca6f196cb0a5df5476268 (plain) (tree)
1
2
3
4
5
6
7
8
                  
                      




                                                                   
                            



                                  










                                                                


                              


                                   
                  

                                                           
                                  
                               
                                           
                                                        
                                                          
                                                   

                           
                               
                         
                             

              
require 'libhtkio'
require 'speech_utils'
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.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 = {}
    -- read HTK feature
    local feat_utter = self.feat_repo:cur_utter(self.debug)
    res[self.feat_id] = feat_utter
    -- add corresponding labels
    for id, repo in pairs(self.lab_repo) do
        local lab_utter = repo:get_utter(self.feat_repo,
                                        feat_utter:nrow(),
                                        self.debug)
        res[id] = lab_utter
    end
    -- move the pointer to next
    self.feat_repo:next()
    collectgarbage("collect")
    return res
end