summaryrefslogtreecommitdiff
path: root/src/KaldiLib/Labels.h
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2014-04-14 08:14:45 +0800
committerJoe Zhao <ztuowen@gmail.com>2014-04-14 08:14:45 +0800
commitcccccbf6cca94a3eaf813b4468453160e91c332b (patch)
tree23418cb73a10ae3b0688681a7f0ba9b06424583e /src/KaldiLib/Labels.h
downloadtnet-cccccbf6cca94a3eaf813b4468453160e91c332b.tar.gz
tnet-cccccbf6cca94a3eaf813b4468453160e91c332b.tar.bz2
tnet-cccccbf6cca94a3eaf813b4468453160e91c332b.zip
First commit
Diffstat (limited to 'src/KaldiLib/Labels.h')
-rw-r--r--src/KaldiLib/Labels.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/KaldiLib/Labels.h b/src/KaldiLib/Labels.h
new file mode 100644
index 0000000..6b78d1a
--- /dev/null
+++ b/src/KaldiLib/Labels.h
@@ -0,0 +1,75 @@
+#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:
+ 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);
+
+ /// 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);
+
+ 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;
+ };
+
+}//namespace
+
+#endif