paddlespeech.s2t.frontend.normalizer module

Contains feature normalizers.

class paddlespeech.s2t.frontend.normalizer.FeatureNormalizer(mean_std_filepath, manifest_path=None, featurize_func=None, num_samples=500, num_workers=0, random_seed=0)[source]

Bases: object

Feature normalizer. Normalize features to be of zero mean and unit stddev.

if mean_std_filepath is provided (not None), the normalizer will directly initilize from the file. Otherwise, both manifest_path and featurize_func should be given for on-the-fly mean and stddev computing.

Parameters:
  • mean_std_filepath (None|str) -- File containing the pre-computed mean and stddev.

  • manifest_path -- Manifest of instances for computing mean and stddev.

  • featurize_func (None|callable) -- Function to extract features. It should be callable with featurize_func(audio_segment).

  • num_samples (int) -- Number of random samples for computing mean and stddev.

  • random_seed (int) -- Random seed for sampling instances.

Raises:

ValueError -- If both mean_std_filepath and manifest_path (or both mean_std_filepath and featurize_func) are None.

Methods

apply(features)

Normalize features to be of zero mean and unit stddev.

write_to_file(filepath)

Write the mean and stddev to the file.

apply(features)[source]

Normalize features to be of zero mean and unit stddev.

Parameters:
  • features (ndarray, shape (T, D)) -- Input features to be normalized.

  • eps (float) -- added to stddev to provide numerical stablibity.

Returns:

Normalized features.

Return type:

ndarray

write_to_file(filepath)[source]

Write the mean and stddev to the file.

Parameters:

filepath (str) -- File to write mean and stddev.