Archive#

class montreal_forced_aligner.models.Archive(source, root_directory=None)[source]#

Bases: MfaModel

Class representing data in a directory or archive file (zip, tar, tar.gz/tgz)

Based on the prosodylab-aligner (prosodylab/Prosodylab-Aligner) archive class.

Parameters:
  • source (Path) – Source path

  • root_directory (Path) – Root directory to unpack and store temporary files

add(source)[source]#

Add file into archive

Parameters:

source (str) – Path to file to copy into the directory

add_meta_file(trainer)[source]#

Add a metadata file from a given trainer to the model

Parameters:

trainer (ModelExporterMixin) – The trainer to construct the metadata from

clean_up()[source]#

Remove temporary directory

dump(path, archive_fmt='zip')[source]#

Write archive to disk, and return the name of final archive

Parameters:
  • path (Path) – Path to write to

  • archive_fmt (str, optional) – Archive extension to use, defaults to “.zip”

Returns:

Path of constructed archive

Return type:

str

classmethod empty(head, root_directory=None)[source]#

Initialize an archive using an empty directory

Parameters:
  • head (str) – Directory name to create

  • root_directory (str, optional) – Root directory to create temporary data, defaults to the MFA temporary directory

Returns:

Model constructed from the empty directory

Return type:

Archive, AcousticModel, G2PModel, LanguageModel, TokenizerModel, or IvectorExtractorModel

classmethod generate_path(root, name, enforce_existence=True)[source]#

Generate a path for a given model from the root directory and the name of the model

Parameters:
  • root (Path) – Root directory for the full path

  • name (str) – Name of the model

  • enforce_existence (bool) – Flag to return None if the path doesn’t exist, defaults to True

Returns:

Full path in the root directory for the model

Return type:

Path

get_subclass_object()[source]#

Instantiate subclass models based on files contained in the archive

Returns:

Subclass model that was auto detected

Return type:

AcousticModel, G2PModel, LanguageModel, or IvectorExtractorModel

Raises:

ModelLoadError – If the model type cannot be determined

property meta#

Get the meta data associated with the model

model_type = None#
parse_old_features()[source]#

Parse MFA model’s features and ensure that they are up-to-date with current functionality

pretty_print()[source]#

Pretty print the archive’s meta data using rich

classmethod valid_extension(filename)[source]#

Check whether a file has a valid extension for the given model archive

Parameters:

filename (Path) – File name to check

Returns:

True if the extension matches the models allowed extensions

Return type:

bool