The input/output style of Kaldi classes
Kaldi 定义的类有统一的I/O接口。标准接口如下所示:
class SomeKaldiClass { public: void Read(std::istream &is, bool binary); void Write(std::ostream &os, bool binary) const; };
注意函数返回 void;而错误会通过异常处理来显示(见 Kaldi logging and error-reporting).布尔变量“binary”标识对象是以二进制数据还是文本数据被写(或读)。调用代码必须知道被读写的对象是二进制还是文本形式(关于在读的过程中它是如何知道,见 How Kaldi objects are stored in files).注意“binary”变量的值没有必要和文件打开的方式(在 Windows下),即二进制还是文本模式,保持一致。更多注释请参照 How the binary/text mode relates to the file open mode。
Read和Write函数可以有额外的可选参数。一个常见的Read函数例子有如下形式:
class SomeKaldiClass { public: void Read(std::istream &is, bool binary, bool add = false); };
如果add==true,Read函数会添加所有在磁盘上的内容(e.g.statistics)到当前类中,前提该类不为空。