Package gmisclib :: Module HTK_MLF_io
[frames] | no frames]

Module HTK_MLF_io

source code

This reads MLF (Master Label Files) for/from the HTK speech recognition toolkit.

Classes
  ReferencedFileNotFound
  writer
Functions
 
parse_label_line(s, tq)
This parses a line from a MLF into a tuple.
source code
 
readone(mlf_efn, postfix='.wav', datapath='.', strict=True, findfile=True, pathedit=None, time_quantum=1e-07, verbose=False)
Read a single set of labels from a MLF file.
source code
an iterator producing dict(str: various)
readiter(mlf_fn, postfix='.wav', datapath='.', strict=True, findfile=True, pathedit=None, time_quantum=1e-07, verbose=False)
Read a HTK Master Label (MLF) file.
source code
list of dict. See readiter for details.
read(mlf_fn, **kw)
Read a HTK Master Label (MLF) file.
source code
Variables
  TIME_QUANTUM = 1e-07
  __package__ = 'gmisclib'

Imports: os, glob, die, DataError, NoSuchFileError, DataOutOfOrderError, BadFileFormatError, Error


Function Details

parse_label_line(s, tq)

source code 

This parses a line from a MLF into a tuple.

Parameters:
  • tq (float) - time quantum (normally 1e-7 seconds)
  • s (str) - line to be parsed
Raises:

readone(mlf_efn, postfix='.wav', datapath='.', strict=True, findfile=True, pathedit=None, time_quantum=1e-07, verbose=False)

source code 

Read a single set of labels from a MLF file. You specify the labels as part of the extended filename, like this: name_of_MLF_file:name_of_labels'. The function returns only a single value and raises an exception if the extended filename is ambiguous.

Parameters:
  • mlf_efn (string in the form "F:S" @rtype dict())
Returns:
a dictionary that describes the labels as per readiter.

readiter(mlf_fn, postfix='.wav', datapath='.', strict=True, findfile=True, pathedit=None, time_quantum=1e-07, verbose=False)

source code 

Read a HTK Master Label (MLF) file. Datapath and pathedit are ways to deal with the situation where the MLF file has been moved, or (for other reasons) the filenames in the MLF file don't point to the actual data.

Parameters:
  • mlf_fn (str) - filename of the data file.
  • strict (bool) - If true, raise an exception if an audio file cannot be found.
  • time_quantum (float) - A factor to convert from the time information in the MLF to real units of time (like seconds). Ideally, time_quantum=1e-7 seconds for MLF files, but that isn't exactly accurate for some sampling rates (like 11025 samples/sec) when the sampling interval is not an integral multiple of 100 nanoseconds.
Returns: an iterator producing dict(str: various)
sequence of {'filespec':path, 'd': d, 'f': f, 'symbols': [...] }, ... . This is an iterator of dictionaries. Each dictionary corresponds to one utterance, or one "label file" in the MLF. Attributes 'd' and 'f' are only present if findfile==True; os.path.join(x['d'], x['f']) is a path to the corresponding audio. x['filespec'] is the path information in the MLF, x['i'] is an int indexing which utterance this is within the MLF, and x['symbols'] is the label information for that utterance. It is a list of tuples produced by parse_label_line.

read(mlf_fn, **kw)

source code 

Read a HTK Master Label (MLF) file. Datapath and pathedit are ways to deal with the situation where the MLF file has been moved, or (for other reasons) the filenames in the MLF file don't point to the actual data.

Parameters:
  • mlf_fn (str) - filename of the data file.
  • kw - Key-value parameters from readiter.
Returns: list of dict. See readiter for details.
see readiter for details.