Phonemizer
class Phonemizer
__init__
def __init__(predictor, lang_phoneme_dict)
Initializes a phonemizer with a ready predictor.
Args
-
predictor (Predictor): Predictor object carrying the trained transformer model.
-
lang_phoneme_dict (Dict[str, Dict[str, str]], optional): Word-phoneme dictionary for each language.
__call__
def __call__(text, lang, punctuation, expand_acronyms, batch_size)
Phonemizes a single text or list of texts.
Args
-
text (str): Text to phonemize as single string or list of strings.
-
lang (str): Language used for phonemization.
-
punctuation (str): Punctuation symbols by which the texts are split.
-
expand_acronyms (bool): Whether to expand an acronym, e.g. DIY -> D-I-Y.
-
batch_size (int): Batch size of model to speed up inference.
Returns
- Union[str, List[str]]: Phonemized text as string, or list of strings, respectively.
phonemise_list
def phonemise_list(texts, lang, punctuation, expand_acronyms, batch_size)
Phonemizes a list of texts and returns tokenized texts, phonemes and word predictions with probabilities.
Args
-
texts (List[str]): List texts to phonemize.
-
lang (str): Language used for phonemization.
-
punctuation (str): Punctuation symbols by which the texts are split. (Default value = DEFAULT_PUNCTUATION)
-
expand_acronyms (bool): Whether to expand an acronym, e.g. DIY -> D-I-Y. (Default value = True)
-
batch_size (int): Batch size of model to speed up inference. (Default value = 8)
Returns
- PhonemizerResult: Object containing original texts, phonemes, split texts, split phonemes, and predictions.
from_checkpoint
def from_checkpoint(cls, checkpoint_path, device, lang_phoneme_dict)
Initializes a Phonemizer object from a model checkpoint (.pt file).
Args
-
checkpoint_path (str): Path to the .pt checkpoint file.
-
device (str): Device to send the model to ('cpu' or 'cuda'). (Default value = 'cpu')
-
lang_phoneme_dict (Dict[str, Dict[str, str]], optional): Word-phoneme dictionary for each language.
Returns
- Phonemizer: Phonemizer object carrying the loaded model and, optionally, a phoneme dictionary.