summaryrefslogtreecommitdiff
path: root/htk_io/src/KaldiLib/Labels.h
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/src/KaldiLib/Labels.h
parentb6301089cde20f4c825c7f5deaf179082aad63da (diff)
let HTK I/O implementation be a single package
Diffstat (limited to 'htk_io/src/KaldiLib/Labels.h')
-rw-r--r--htk_io/src/KaldiLib/Labels.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/htk_io/src/KaldiLib/Labels.h b/htk_io/src/KaldiLib/Labels.h
new file mode 100644
index 0000000..409a080
--- /dev/null
+++ b/htk_io/src/KaldiLib/Labels.h
@@ -0,0 +1,90 @@
+#ifndef _LABELS_H_
+#define _LABELS_H_
+
+
+#include "Matrix.h"
+#include "MlfStream.h"
+#include "Features.h"
+
+#include <map>
+#include <iostream>
+
+namespace TNet {
+
+
+ class FeaCatPool;
+
+ /**
+ * Desired matrix generation object,
+ * supports background-reading and caching, however can be
+ * used in foreground as well by GenDesiredMatrix()
+ */
+ class LabelRepository
+ {
+ typedef std::map<std::string,size_t> TagToIdMap;
+
+ public:
+ enum MFormat {
+ MAP,
+ RAW
+ };
+
+ LabelRepository()
+ : _mpLabelStream(NULL), mpLabelStream(NULL), mpLabelDir(NULL), mpLabelExt(NULL), mGenDesiredMatrixTime(0), mIndexTime(0), mTrace(0)
+ { }
+
+ ~LabelRepository()
+ {
+ if(mTrace&4) {
+ std::cout << "[LabelRepository -- indexing:" << mIndexTime << "s"
+ " genDesiredMatrix:" << mGenDesiredMatrixTime << "s]" << std::endl;
+ }
+ delete mpLabelStream;
+ delete _mpLabelStream;
+ }
+
+ /// Initialize the LabelRepository
+ void Init(const char* pLabelMlfFile, const char* pOutputLabelMapFile, const char* pLabelDir, const char* pLabelExt);
+ void InitExt(const char* pLabelMlfFile, const char* fmt, const char* arg, const char* pLabelDir, const char* pLabelExt);
+ void InitMap(const char* pLabelMlfFile, const char* pOutputLabelMapFile, const char* pLabelDir, const char* pLabelExt);
+ void InitRaw(const char* pLabelMlfFile,const char* arg, const char* pLabelDir, const char* pLabelExt);
+
+ /// Set trace level
+ void Trace(int trace)
+ { mTrace = trace; }
+
+ /// Get desired matrix from labels
+ void GenDesiredMatrix(BfMatrix& rDesired, size_t nFrames, size_t sourceRate, const char* pFeatureLogical, bool has_vad = false);
+
+ void GenDesiredMatrixExt(std::vector<BfMatrix>& rDesired, size_t nFrames, size_t sourceRate, const char* pFeatureLogical);
+ void GenDesiredMatrixExtMap(std::vector<BfMatrix>& rDesired, size_t nFrames, size_t sourceRate, const char* pFeatureLogical);
+ void GenDesiredMatrixExtRaw(std::vector<BfMatrix>& rDesired, size_t nFrames, size_t sourceRate, const char* pFeatureLogical);
+ size_t getWidth() { return mLabelMap.size(); }
+ MFormat getFormat() { return mlf_fmt; }
+ private:
+ /// Prepare the state-label to state-id map
+ void ReadOutputLabelMap(const char* file);
+
+ private:
+ // Streams and state-map
+ std::ifstream* _mpLabelStream; ///< Helper stream for Label stream
+ IMlfStream* mpLabelStream; ///< Label stream
+ std::istringstream mGenDesiredMatrixStream; ///< Label file parsing stream
+
+ const char* mpLabelDir; ///< Label dir in MLF
+ const char* mpLabelExt; ///< Label ext in MLF
+ char mpLabelFile[4096]; ///< Buffer for filenames in MLF
+
+ TagToIdMap mLabelMap; ///< Map of state tags to net output indices
+
+ double mGenDesiredMatrixTime;
+ float mIndexTime;
+
+ int mTrace;
+ MFormat mlf_fmt;
+ size_t raw_dim;
+ };
+
+}//namespace
+
+#endif