1 # Copyright (c) 2006 Carnegie Mellon University
3 # You may copy and modify this freely under the same terms as
6 """Read/write Sphinx-III Gaussian mixture weight files.
8 This module reads and writes the Gaussian mixture weight files used by
9 SphinxTrain, Sphinx-III, and PocketSphinx.
12 __author__ = "David Huggins-Daines <dhuggins@cs.cmu.edu>"
13 __version__ = "$Revision: 8994 $"
15 from s3file import S3File, S3File_write
17 def open(filename, mode="rb"):
18 if mode in ("r", "rb"):
19 return S3MixwFile(filename, mode)
20 elif mode in ("w", "wb"):
21 return S3MixwFile_write(filename, mode)
23 raise Exception, "mode must be 'r', 'rb', 'w', or 'wb'"
25 class S3MixwFile(S3File):
26 "Read Sphinx-III format mixture weight files"
27 def __init__(self, file, mode):
28 S3File.__init__(self, file, mode)
29 self._params = self._load()
31 def readgauheader(self):
32 if self.fileattr["version"] != "1.0":
33 raise Exception("Version mismatch: must be 1.0 but is "
34 + self.fileattr["version"])
38 self.fh.seek(self.data_start, 0)
41 class S3MixwFile_write(S3File_write):
42 "Write Sphinx-III format mixture weight files"
44 def writeall(self, stuff):