annotations.Align.models.acm package

Submodules

annotations.Align.models.acm.acfeatures module

filename

sppas.src.annotations.Align.models.acm.acfeatures.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Features of acoustic models.

class annotations.Align.models.acm.acfeatures.sppasAcFeatures[source]

Bases: object

Acoustic model features.

__init__()[source]

Create a sppasAcFeatures instance.

write_all(dirname)[source]

Write all files at once.

Write files with their default name, in the given directory.

Parameters

dirname – (str) a directory name (existing or to be created).

write_config(filename)[source]

Write the wav config into a file.

Parameters

filename – (str) Name of the file to save the features.

write_mfcconfig(filename)[source]

Write the wav config into a file. For HCopy only.

Parameters

filename – (str) Name of the file to save the features.

annotations.Align.models.acm.acmbaseio module

filename

sppas.src.annotations.Align.models.acm.acmbaseio.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Base object for readers and writers of acoustic models.

class annotations.Align.models.acm.acmbaseio.sppasBaseIO(name=None)[source]

Bases: annotations.Align.models.acm.acmodel.sppasAcModel

Base object for readers and writers of acm.

__init__(name=None)[source]

Initialize a new Acoustic Model reader-writer instance.

Parameters

name – (str) Name of the acoustic model.

static detect(filename)[source]
is_ascii()[source]

Return True if it supports to read/write ASCII files.

Returns

(bool)

is_binary()[source]

Return True if it supports to read and write binary files.

Returns

(bool)

read(folder)[source]

Read a folder content and fill the Acoustic Model.

Parameters

folder – (str)

read_phonesrepl(filename)[source]

Read a replacement table of phone names from a file.

Parameters

filename – (str)

read_tiedlist(filename)[source]

Read a tiedlist from a file.

Parameters

filename – (str)

set(other)[source]

Set self with other content.

Parameters

other – (sppasAcModel)

write(folder)[source]

Write the Acoustic Model into a folder.

Parameters

folder – (str)

static write_hmm_proto(proto_size, proto_filename)[source]

Write a proto file. The proto is based on a 5-states HMM.

Parameters

proto_size – (int) Number of mean and variance values.

It’s commonly either 25 or 39, it depends on the MFCC parameters. :param proto_filename: (str) Full name of the prototype to write.

annotations.Align.models.acm.acmodel module

filename

sppas.src.annotations.Align.models.acm.acmmodel.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Data structure of an acoustic model.

class annotations.Align.models.acm.acmodel.sppasAcModel(name=None)[source]

Bases: object

Acoustic model representation.

An acoustic model is made of:
  • ‘macros’ is an OrderedDict of options, transitions, states, …

  • ‘hmms’ models (one per phone/biphone/triphone): list of HMM instances

  • a tiedlist (if any)

  • a mapping table to replace phone names.

__init__(name=None)[source]

Create an sppasAcModel instance.

append_hmm(hmm)[source]

Append an HMM to the model.

Parameters

hmm – (OrderedDict)

Raises

TypeError, ValueError

compare_mfcc(other)[source]

Compare MFCC parameter kind with another one.

Parameters

other – (sppasAcModel)

Returns

bool

static create_model(macros, hmms)[source]

Create an empty sppasAcModel and return it.

Parameters
  • macros – OrderedDict of options, transitions, states, …

  • hmms – models (one per phone/biphone/triphone) is a list

of HMM instances

static create_options(vector_size, parameter_kind=None, stream_info=None, duration_kind='nulld', covariance_kind='diagc')[source]
static create_parameter_kind(base=None, options=[])[source]
extract_monophones()[source]

Return an Acoustic Model that includes only monophones.

  • hmms and macros are selected,

  • repllist is copied,

  • tiedlist is ignored.

Returns

sppasAcModel

fill_hmms()[source]

Fill HMM states and transitions.

  • replace all the “ST_…” by the corresponding macro, for states.

  • replace all the “T_…” by the corresponding macro, for transitions.

get_hmm(phone)[source]

Return the hmm corresponding to the given phoneme.

Parameters

phone – (str) the phoneme name to get hmm

Raises

ValueError if phoneme is not in the model

get_hmms()[source]
get_macros()[source]
get_mfcc_parameter_kind()[source]

Return the MFCC parameter kind, as a string, or an empty string.

get_name()[source]

Return the identifier name of the acoustic model.

get_repllist()[source]
get_tiedlist()[source]
merge_model(other, gamma=1.0)[source]

Merge another model with self.

All new phones/biphones/triphones are added and the shared ones are combined using a static linear interpolation.

Parameters
  • other – (sppasAcModel) the sppasAcModel to be merged with.

  • gamma – (float) coefficient to apply to the model: between 0.

and 1. This means that a coefficient value of 1. indicates to keep the current version of each shared hmm.

Raises

TypeError, ValueError

Returns

a tuple indicating the number of hmms that was

appended, interpolated, kept, changed.

pop_hmm(phone)[source]

Remove an HMM of the model.

Parameters

phone – (str) the phoneme name to get hmm

Raises

ValueError if phoneme is not in the model

replace_phones(reverse=False)[source]

Replace the phones by using a mapping table.

This is mainly useful due to restrictions in some acoustic model tks: X-SAMPA can’t be fully used and a “mapping” is required. As for example, the /2/ or /9/ can’t be represented directly in an HTK-ASCII acoustic model. We can replace respectively by /eu/ and /oe/.

Notice that ‘+’ and ‘-’ can’t be used as a phone name.

Parameters

reverse – (bool) reverse the replacement direction.

set_hmms(hmms)[source]

Set the list of HMMs the model.

Parameters

hmms – (list) List of HMM instances

set_macros(macros)[source]

Set the macros of the model.

Parameters

macros – (OrderedDict)

set_name(name=None)[source]

Set the name of the acoustic model.

Parameters

name – (str or None) The identifier name or None.

Returns

the name

set_repllist(repllist)[source]

Set the placement list of the model.

Parameters

repllist – (sppasMapping)

annotations.Align.models.acm.acmodelhtkio module

filename

sppas.src.annotations.Align.models.acm.acmodelhtkio.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

I/O for HTK acoustic models.

class annotations.Align.models.acm.acmodelhtkio.HtkModelParser(whitespace=None, nameguard=True, **kwargs)[source]

Bases: sppas.src.dependencies.grako.parsing.Parser

__init__(whitespace=None, nameguard=True, **kwargs)[source]
class annotations.Align.models.acm.acmodelhtkio.HtkModelSemantics[source]

Bases: object

Part of the Inspire package: https://github.com/rikrd/inspire.

Author

Ricard Marxer.

License

GPL, v2

__init__()[source]
float(ast)[source]
matrix(ast)[source]
short(ast)[source]
string(ast)[source]
transPdef(ast)[source]
vector(ast)[source]
class annotations.Align.models.acm.acmodelhtkio.sppasHtkIO(name=None)[source]

Bases: annotations.Align.models.acm.acmbaseio.sppasBaseIO

HTK-ASCII acoustic models reader/writer.

This class is able to load and save HMM-based acoustic models from HTK-ASCII files.

__init__(name=None)[source]

Create a sppasHtkIO instances.

Parameters

name – (str) An identifier name for the Acoustic Model.

By default, the name of the class is used.

static detect(folder)[source]

Return True if the folder contains the HTK-ASCII file(s) of an ACM.

Expected files of this reader is mainly “hmmdefs”.

read(folder, filename=None)[source]

Load all known data from a folder or only the given file.

The default file names are:

  • hmmdefs for an HTK-ASCII acoustic model;

  • macros for a separated macro description;

  • vFloors for a separated description allowing to construct the macro;

  • tiedlist for triphone models;

  • monophones.repl to map between phoneme representations.

Parameters
  • folder – (str) Folder name of the acoustic model

  • filename – (str) Optional name of a single file to read

static read_hmm(filename)[source]

Return the (first) HMM described into the given filename.

Parameters

filename – (str) File to read.

Returns

(sppasHMM)

read_macros_hmms(filenames)[source]

Load an HTK-ASCII model from one or more files.

Parameters

filenames – Name of the files of the model

(e.g. macros and/or hmms files and/or hmmdefs)

write(folder, filename='hmmdefs')[source]

Save the model into a file, in HTK-ASCII standard format.

The default file names are:
  • hmmdefs (macros + hmms);

  • tiedlist (if triphones);

  • monophones.repl.

Parameters
  • folder – (str) Folder name of the acoustic model

  • filename – (str) Optional name of the file to write macros and hmms

static write_hmm(hmm, filename)[source]

Save a single hmm into the given filename.

Parameters
  • hmm – (sppasHMM) The HMM model to write

  • filename – (str) Name of the file to write.

static write_hmm_proto(proto_size, proto_filename)[source]

Write a proto file. The proto is based on a 5-states HMM.

Parameters

proto_size – (int) Number of mean and variance values. It’s

commonly either 25 or 39, it depends on the MFCC parameters. :param proto_filename: (str) Full name of the prototype to write.

annotations.Align.models.acm.hmm module

filename

sppas.src.annotations.Align.models.acm.hmm.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Data structure of an HMM of a sound.

class annotations.Align.models.acm.hmm.HMMInterpolation[source]

Bases: object

HMM interpolation.

static linear_interpolate_matrix(matrices, gammas)[source]

Interpolate linearly matrix with gamma coefficients.

Parameters
  • matrices – List of matrix

  • gammas – List of coefficients (must sum to 1.)

static linear_interpolate_mixtures(mixtures, gammas)[source]

Linear interpolation of a set of mixtures, of one stream only.

Parameters
  • mixtures – (OrderedDict)

  • gammas – List of coefficients (must sum to 1.)

Returns

mixture (OrderedDict)

static linear_interpolate_states(states, gammas)[source]

Linear interpolation of a set of states, of one index only.

Parameters
  • states – (OrderedDict)

  • gammas – List of coefficients (must sum to 1.)

Returns

state (OrderedDict)

static linear_interpolate_streams(streams, gammas)[source]

Linear interpolation of a set of streams, of one state only.

Parameters
  • streams – (OrderedDict)

  • gammas – List of coefficients (must sum to 1.)

Returns

stream (OrderedDict)

static linear_interpolate_transitions(transitions, gammas)[source]

Linear interpolation of a set of transitions, of an hmm.

Parameters
  • transitions – (OrderedDict): with key=’dim’ and key=’matrix’

  • gammas – List of coefficients (must sum to 1.)

Returns

transition (OrderedDict)

static linear_interpolate_values(values, gammas)[source]

Interpolate linearly values with gamma coefficients.

Parameters
  • values – List of values

  • gammas – List of coefficients (must sum to 1.)

static linear_interpolate_vectors(vectors, gammas)[source]

Interpolate linearly vectors with gamma coefficients.

Parameters
  • vectors – List of vectors

  • gammas – List of coefficients (must sum to 1.)

static linear_states(states, coefficients)[source]

Linear interpolation of a set of states.

Parameters
  • states – (OrderedDict)

  • coefficients – List of coefficients (must sum to 1.)

Returns

state (OrderedDict)

static linear_transitions(transitions, coefficients)[source]

Linear interpolation of a set of transitions.

Parameters
  • transitions – (OrderedDict): with key=’dim’ and key=’matrix’

  • coefficients – List of coefficients (must sum to 1.)

Returns

transition (OrderedDict)

class annotations.Align.models.acm.hmm.sppasHMM(name='und')[source]

Bases: object

HMM representation for one phone.

Hidden Markov Models (HMMs) provide a simple and effective framework for modeling time-varying spectral vector sequences. As a consequence, most of speech technology systems are based on HMMs. Each base phone is represented by a continuous density HMM, with transition probability parameters and output observation distributions. One of the most commonly used extensions to standard HMMs is to model the state-output distribution as a mixture model, a mixture of Gaussians is a highly flexible distribution able to model, for example, asymmetric and multi-modal distributed data.

An HMM-definition is made of:
  • state_count: int

  • states: list of OrderedDict with “index” and “state” as keys.

  • transition: OrderedDict with “dim” and “matrix” as keys.

  • options

  • regression_tree

  • duration

DEFAULT_NAME = 'und'
__init__(name='und')[source]

Create a sppasHMM instance.

The model includes a default name and an empty definition.

Parameters

name – (str) Name of the HMM (usually the phoneme in SAMPA)

create(states, transition, name=None)[source]

Create the hmm and set it.

Parameters
  • states – (OrderedDict)

  • transition – (OrderedDict)

  • name – (string) The name of the HMM.

If name is set to None, the default name is assigned.

static create_default()[source]

Create a default ordered dictionary, used for states.

Returns

collections.OrderedDict()

static create_gmm(means, variances, gconsts=None, weights=None)[source]

Create and return a GMM.

Returns

collections.OrderedDict()

create_proto(proto_size, nb_mix=1)[source]

Create the 5-states HMM proto and set it.

Parameters

proto_size – (int) Number of mean and variance values.

It’s commonly either 25 or 39, it depends on the MFCC parameters. :param nb_mix: (int) Number of mixtures (i.e. the number of times means and variances occur)

create_sp()[source]

Create the 3-states HMM sp and set it.

The sp model is based on a 3-state HMM with string “silst” as state 2, and a 3x3 transition matrix as follow:

0.0 1.0 0.0 0.0 0.9 0.1 0.0 0.0 0.0

static create_square_matrix(matrix)[source]

Create a default matrix.

Returns

collections.OrderedDict()

static create_transition(state_stay_probabilities=(0.6, 0.6, 0.7))[source]

Create and return a transition matrix.

Parameters

state_stay_probabilities – (list) Center transition probabilities

Returns

collections.OrderedDict()

static create_vector(vector)[source]

Create a default vector.

Returns

collections.OrderedDict()

property definition

Return the definition (OrderedDict) of the model.

get_definition()[source]

Return the definition (OrderedDict) of the model.

get_name()[source]

Return the name (str) of the model.

get_state(index)[source]

Return the state of a given index or None if index is not found.

Parameters

index – (int) State index (commonly between 1 and 5)

Returns

collections.OrderedDict or None

get_vecsize()[source]

Return the number of means and variance of each state.

If state is pointing to a macro, 0 is returned.

property name

Return the name (str) of the model.

set(name, definition)[source]

Set the model.

Parameters
  • name – (str) Name of the HMM

  • definition – (OrderedDict) Definition of the HMM (states

and transitions)

set_default_definition()[source]

Set an empty definition.

set_definition(definition)[source]

Set the definition of the model.

Parameters

definition – (OrderedDict) Definition of the HMM

(states and transitions) :raises: ModelsDataTypeError

set_name(name)[source]

Set the name of the model.

Parameters

name – (str) Name of the HMM.

Raises

ModelsDataTypeError

static_linear_interpolation(hmm, gamma)[source]

Static Linear Interpolation.

This is perhaps one of the most straightforward manner to combine models. This is an efficient way for merging the GMMs of the component models.

Gamma coefficient is applied to self and (1-gamma) to the other hmm.

Parameters
  • hmm – (HMM) the hmm to be interpolated with.

  • gamma – (float) coefficient to be applied to self.

Returns

(bool) Status of the interpolation.

annotations.Align.models.acm.htkscripts module

filename

sppas.src.annotations.Align.models.acm.htkscripts.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Reader/Writers of HTK scripts.

class annotations.Align.models.acm.htkscripts.sppasHtkScripts[source]

Bases: object

HTK-ASCII scripts reader/writer.

This class is able to write all scripts of the VoxForge tutorial. They are used to train acoustic models thanks to the HTK toolbox.

For details, refer to: http://www.voxforge.org/

__init__()[source]

Create a sppasHtkScripts instance.

write_all(dirname)[source]

Write all scripts at once.

Write scripts with their default name, in the given directory.

Parameters

dirname – (str) a directory name (existing or to be created).

write_global_ded(filename)[source]

Write the htk script global.ded.

Parameters

filename – (str) Name of the script file.

write_maketriphones_ded(filename)[source]

Write the htk script maketriphones.ded.

Parameters

filename – (str) Name of the script file.

write_mkphones0_led(filename)[source]

Write the htk script mkphones0.led.

Parameters

filename – (str) Name of the script file.

write_mkphones1_led(filename)[source]

Write the htk script mkphones1.led.

Parameters

filename – (str) Name of the script file.

write_mktri_led(filename)[source]

Write the htk script mktri.led.

Parameters

filename – (str) Name of the script file.

write_sil_hed(filename)[source]

Write the htk script sil.hed.

Parameters

filename – (str) Name of the script file.

annotations.Align.models.acm.htktrain module

filename

sppas.src.annotations.Align.models.acm.htktrain.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Training procedure of an HTK acoustic model.

class annotations.Align.models.acm.htktrain.sppasDataTrainer[source]

Bases: object

Acoustic model trainer for HTK-ASCII models.

This class is a manager for the data created at each step of the acoustic training model procedure, following the HTK Handbook. It includes:

  • HTK scripts

  • phoneme prototypes

  • log files

  • features

__init__()[source]

Create a sppasDataTrainer instance.

Initialize all members to None or empty lists.

check()[source]

Check if all members are initialized with appropriate values.

Returns

None if success.

Raises

IOError

create(workdir=None, scriptsdir='scripts', featsdir='features', logdir='log', protodir=None, protofilename='proto.hmm')[source]

Create all folders and their content (if possible) with their default names.

Parameters
  • workdir – (str) Name of the working directory

  • scriptsdir – (str) The folder for HTK scripts

  • featsdir – (str) The folder for features

  • logdir – (str) Directory to store log files

  • protodir – (str) Name of the prototypes directory

  • protofilename – (str) Name of the file for the HMM prototype.

Raises

IOError

delete()[source]

Delete all folders and their content, then reset members.

fix_proto(proto_dir='protos', proto_filename='proto.hmm')[source]

(Re-)Create the proto.

If relevant, create a protos directory and add the proto file. Create the macro if any.

Parameters
  • proto_dir – (str) Directory in which prototypes will be stored

  • proto_filename – (str) File name of the default prototype

fix_storage_dirs(basename)[source]

Fix the folders to store annotated speech and audio files.

The given basename can be something like: align, phon, trans, …

Parameters

basename – (str) a name to identify storage folders

Raises

IOError

fix_working_dir(workdir=None, scriptsdir='scripts', featsdir='features', logdir='log')[source]

Set the working directory and its folders.

Create all of them if necessary.

Parameters
  • workdir – (str) The working main directory

  • scriptsdir – (str) The folder for HTK scripts

  • featsdir – (str) The folder for features

  • logdir – (str) The folder to write output logs

get_storemfc()[source]

Get the current folder name to store MFCC data files.

Returns

folder name or None.

get_storetrs()[source]

Get the current folder name to store transcribed data files.

Returns

folder name or None.

get_storewav()[source]

Get the current folder name to store audio data files.

Returns

folder name or None.

reset()[source]

Fix all members to their initial value.

class annotations.Align.models.acm.htktrain.sppasHTKModelInitializer(trainingcorpus, directory)[source]

Bases: object

Acoustic model initializer.

Monophones initialization is the step 2 of the acoustic model training procedure.

In order to create a HMM definition, it is first necessary to produce a prototype definition. The function of a prototype definition is to describe the form and topology of the HMM, the actual numbers used in the definition are not important.

Having set up an appropriate prototype, an HMM can be initialized by both methods: 1. create a flat start monophones model, a prototype trained from

phonetized data, and copied for each phoneme (using HCompV command). It reads in a prototype HMM definition and some training data and outputs a new definition in which every mean and covariance is equal to the global speech mean and covariance.

  1. create a prototype for each phoneme using time-aligned data (using Hinit command). Firstly, the Viterbi algorithm is used to find the most likely state sequence corresponding to each training example, then the HMM parameters are estimated. As a side-effect of finding the Viterbi state alignment, the log likelihood of the training data can be computed.

    Hence, the whole estimation process can be repeated until no further

    increase in likelihood is obtained.

This program trains the flat start model and fall back on this model for each phoneme that fails to be trained with Hinit (if there are not enough occurrences).

__init__(trainingcorpus, directory)[source]

Create an instance of sppasHTKModelInitializer.

Parameters
  • trainingcorpus – (sppasTrainingCorpus) The data prepared during step 1.

  • directory – (str) The current directory to write the result of this step.

Raises

IOError

create_hmmdefs()[source]

Create an hmmdefs file from a set of separated hmm files.

create_macros()[source]

Create macros file from vfloors.

create_model()[source]

Main method to create the initial acoustic model.

Raises

IOError

create_models()[source]

Create an initial model for each phoneme.

Create a start model for each phoneme:

  • either from time-aligned data [TRAIN],

  • or use the prototype trained by HCompV (i.e. a flat-start-model) [FLAT],

  • or use the existing saved prototype [PROTO],

  • or use the default prototype.

class annotations.Align.models.acm.htktrain.sppasHTKModelTrainer(corpus=None)[source]

Bases: object

Acoustic model trainer.

This class allows to train an acoustic model from audio data and their transcriptions (either phonetic or orthographic or both).

Acoustic models are trained with HTK toolbox using a training corpus of speech, previously segmented in utterances and transcribed. The trained models are Hidden Markov models (HMMs). Typically, the HMM states are modeled by Gaussian mixture densities whose parameters are estimated using an expectation maximization procedure. The outcome of this training procedure is dependent on the availability of accurately annotated data and on good initialization.

Acoustic models are trained from 16 bits, 16000 hz wav files. The Mel-frequency cepstrum coefficients (MFCC) along with their first and second derivatives are extracted from the speech.

Step 1 is the data preparation.

Step 2 is the monophones initialization.

Step 3 is the monophones generation. This first model is re-estimated using the MFCC files to create a new model, using ``HERest’’. Then, it fixes the ``sp’’ model from the ``sil’’ model by extracting only 3 states of the initial 5-states model. Finally, this monophone model is re-estimated using the MFCC files and the training data.

Step 4 creates tied-state triphones from monophones and from some language specificity defined by means of a configuration file.

__init__(corpus=None)[source]

Create a sppasHTKModelTrainer instance.

Parameters

corpus – (sppasTrainingCorpus)

align_trs(tokenizer, phonetizer, aligner)[source]

Alignment of the transcribed speech using the current model.

create_annotators()[source]

Return a sppasTextNorm, a sppasPhon and a sppasAlign.

get_current_macro()[source]

Return the macros of the current epoch, or None.

get_current_model()[source]

Return the model of the current epoch, or None.

init_epoch_dir()[source]

Create a new epoch folder and fill it with the macros.

make_triphones()[source]

Extract triphones from monophones data (mlf).

A new mlf file is created with triphones instead of monophones, and a file with the list of triphones is created. This latter is sorted in order of arrival (this is very important).

Command: HLEd -T 2 -n output/triphones -l ‘*’ -i output/wintri.mlf scripts/mktri.led corpus.mlf

small_pause()[source]

Create and save the “sp” model for short pauses.

  • create a “silst” macro, using state 3 of the “sil” HMM,

  • adapt state 3 of the “sil” HMM definition, to use “silst”,

  • create a “sp” HMM,

  • save the “sp” HMM into the directory of monophones.

train_step(scpfile, rounds=3, dopruning=True)[source]

Perform some rounds of HERest estimation.

It expects the input HMM definition to have been initialised and it uses the embedded Baum-Welch re-estimation. This involves finding the probability of being in each state at each time frame using the Forward-Backward algorithm.

Parameters
  • scpfile – (str) Description file with the list of data files

  • rounds – (int) Number of times HERest is called.

  • dopruning – (bool) Do the pruning

Returns

bool

training_recipe(outdir=None, delete=False, header_tree=None)[source]

Create an acoustic model and return it.

A corpus (sppasTrainingCorpus) must be previously defined.

Parameters
  • outdir – (str) Directory to save the final model and related files

  • delete – (bool) Delete the working directory.

  • header_tree – (str) Name of the script file to train a triphone (commonly header-tree.hed).

Returns

sppasAcModel

training_step1()[source]

Step 1 of the training procedure.

Data preparation.

training_step2()[source]

Step 2 of the training procedure.

Monophones initialization.

training_step3()[source]

Step 3 of the training procedure.

Monophones training.

  1. Train phonemes from manually time-aligned data.

  2. Create sp model.

  3. Train from phonetized data.

  4. Align transcribed data.

  5. Train from all data.

training_step4(header_tree)[source]

Step 4 of the training procedure. Not implemented yet.

Triphones training.

Parameters

header_tree – (str) Name of the script file to train a

triphone (commonly header-tree.hed).

class annotations.Align.models.acm.htktrain.sppasTrainingCorpus(datatrainer=None, lang='und')[source]

Bases: object

Manager of a training corpus, to prepare a set of data.

Data preparation is the step 1 of the acoustic model training procedure.

It establishes the list of phonemes. It converts the input data into the HTK-specific data format. It codes the audio data, also called “parameterizing the raw speech waveforms into sequences of feature vectors” (i.e. convert from wav to MFCC format).

Accepted input:

  • annotated files: one of sppasTrsRW.extensions_in()

  • audio files: one of audiodata.extensions

__init__(datatrainer=None, lang='und')[source]

Create a sppasTrainingCorpus instance.

Parameters
  • datatrainer – (sppasDataTrainer)

  • lang – (str) iso-8859-3 of the language

add_corpus(directory)[source]

Add a new corpus to deal with.

Find matching pairs of files (audio / transcription) of the given directory and its folders.

Parameters

directory – (str) The directory to find data files of a corpus.

Returns

the number of pairs appended.

add_file(trs_filename, audio_filename)[source]

Add a new set of files to deal with.

If such files are already in the data, they will be added again.

Parameters
  • trs_filename – (str) The annotated file.

  • audio_filename – (str) The audio file.

Returns

(bool)

create()[source]

Create files and directories.

fix_resources(vocab_file=None, dict_file=None, mapping_file=None)[source]

Fix resources using default values.

Ideally, resources are fixed after the datatrainer.

Parameters
  • vocab_file – (str) The lexicon, used during tokenization of the corpus.

  • dict_file – (str) The pronunciation dictionary, used both to

generate the list of phones and to perform phonetization of the corpus. :param mapping_file: (str) file that contains the mapping table for the phone set.

get_mlf()[source]

Fix the mlf file by defining the directories to add.

Example of a line of the MLF file is: “/mfc-align/” => “workdir/trs-align”

get_scp(aligned=True, phonetized=False, transcribed=False)[source]

Fix the train.scp file content.

Parameters
  • aligned – (bool) Add time-aligned data in the scp file

  • phonetized – (bool) Add phonetized data in the scp file

  • transcribed – (bool) Add transcribed data in the scp file

Returns

filename or None if no data is available.

reset()[source]

Fix all members to None or to their default values.

annotations.Align.models.acm.htktrain.test_command(command)[source]

Test if a command is available.

Parameters

command – (str) The command to execute as a sub-process.

annotations.Align.models.acm.phoneset module

filename

sppas.src.annotations.Align.models.acm.phoneset.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Data structure for the list of phonemes of an acm.

class annotations.Align.models.acm.phoneset.sppasPhoneSet(filename=None)[source]

Bases: sppas.src.resources.vocab.sppasVocabulary

Manager of the list of phonemes.

This class allows to manage the list of phonemes:

  • get it from a pronunciation dictionary,

  • read it from a file,

  • write it into a file,

  • check if a phone string is valid to be used with HTK toolkit.

__init__(filename=None)[source]

Create a sppasPhoneSet instance.

Add events to the list: laugh, dummy, noise, silence.

:param filename (str) A file with 1 column containing the list of phonemes.

add_from_dict(dict_filename)[source]

Add the list of phones from a pronunciation dictionary.

Parameters

dict_filename – (str) Name of an HTK-ASCII pronunciation dict

static check_as_htk_phone(phone)[source]

Check if a phone is correct to be used with HTK toolkit.

A phone can’t start by a digit nor ‘-’ nor ‘+’, and must be ASCII.

Parameters

phone – (str) Phone to be checked

Returns

(bool)

annotations.Align.models.acm.readwrite module

filename

sppas.src.annotations.Align.models.acm.readwrite.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Readers and writers of acoustic models.

class annotations.Align.models.acm.readwrite.sppasACMRW(folder)[source]

Bases: object

Generic reader and writer for acoustic models.

Currently, only HTK-ASCII is supported.

We expect to add readers and writers for several file formats in a – far – future.

ACM_TYPES = {'hmmdefs': <class 'annotations.Align.models.acm.acmodelhtkio.sppasHtkIO'>}
__init__(folder)[source]

Create an acoustic model reader-writer.

Parameters

folder – (str) Name of the folder with the acoustic model files

get_folder()[source]

Return the name of the folder of the acoustic model.

static get_formats()[source]

Return the list of accepted formats for acoustic models.

get_reader()[source]

Return an acoustic model according to the given folder.

Returns

sppasAcModel()

read()[source]

Read an acoustic model from the folder.

Returns

sppasAcModel()

set_folder(folder)[source]

Set a new folder to store files of the acoustic model.

Parameters

folder – (str) New name of the folder of the acoustic model.

write(acmodel, format='hmmdefs')[source]

Write an acoustic model into a folder.

Parameters
  • acmodel – (str)

  • format – The format to save the acoustic model

annotations.Align.models.acm.tiedlist module

filename

sppas.src.annotations.Align.models.acm.tiedlist.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Tiedlist of an HTK acoustic models.

class annotations.Align.models.acm.tiedlist.sppasTiedList[source]

Bases: object

Tiedlist of an acoustic model.

This class is used to manage the tiedlist of a triphone acoustic model, i.e:

  • the list of observed phones, biphones, triphones,

  • a list of biphones or triphones to tie.

__init__()[source]

Create a sppasTiedList instance.

add_observed(entry)[source]

Add an observed entry.

Parameters

entry – (str)

Returns

bool

add_tied(tied, observed=None)[source]

Add an entry into the tiedlist.

If observed is None, an heuristic will assign one.

Parameters
  • tied – (str) the biphone/triphone to add,

  • observed – (str) the biphone/triphone to tie with.

Returns

bool

add_to_tie(entries)[source]

Add several un-observed entries in the tiedlist.

Parameters

entries – (list)

Returns

list of entries really added into the tiedlist

is_empty()[source]

Return True if the tiedlist is empty.

is_observed(entry)[source]

Return True if entry is really observed (not tied!).

Parameters

entry – (str) triphone/biphone/monophone

is_tied(entry)[source]

Return True if entry is tied.

Parameters

entry – (str) a triphone/biphone/monophone

merge(other)[source]

Merge self with another tiedlist.

Parameters

other – (sppasTiedList)

read(filename)[source]

Read a tiedlist from a file and set it.

Parameters

filename – (str)

remove(entry, propagate=False)[source]

Remove an entry of the list of observed or tied entries.

Parameters
  • entry – (str) the entry to be removed

  • propagate – (bool) if entry is an observed item, remove all tied

that are using this observed item.

save(filename)[source]

Save the tiedlist into a file.

Parameters

filename – Name of the file of the tiedlist

Module contents