mirror of
https://github.com/storytold/storyteller-ml.git
synced 2026-10-18 07:41:03 +00:00
76c6dbf12b
This breaks the text pipeline into the following pieces: - input parsing (split known bracketed phoneme sections out first) - normalization (fix spacing, numbers, abbreviations, etc.) - phonetization (do CMUdict lookup or g2p prediction) - sequencing (convert the symbolic representation to integer representation) Each "pipeline" can have a unique combination of operations for each of these pipeline steps. This will grow over time.
31 lines
1.3 KiB
Python
31 lines
1.3 KiB
Python
from typing import List
|
|
from text.pipeline_components.input_parsing.parser import ArpabetSequence, GraphemeSequence, ParsedSequence
|
|
from text.pipeline_components.phonetization.base_phonetization import BasePhonetization
|
|
from text.pipeline_components.phonetization.cmudict import CMUDict
|
|
|
|
class EnglishPhonetization(BasePhonetization):
|
|
|
|
def __init__(self, phoneme_dictionary: CMUDict):
|
|
super().__init__(phoneme_dictionary)
|
|
|
|
def try_convert_to_phonemes(self, grapheme_sequence: str) -> ParsedSequence:
|
|
"""
|
|
Attempt to enrich a grapheme sequence with phonemes where word lookup succeeds.
|
|
Grapheme symbols will be left in place.
|
|
The output list will need to be space-separated before inference.
|
|
"""
|
|
words = self._split_grapheme_sentence_to_words(grapheme_sequence)
|
|
converted_words = []
|
|
|
|
for word in words:
|
|
maybe_phonemes = self.phoneme_dictionary.lookup(word)
|
|
if maybe_phonemes:
|
|
# NB: Dictionary returns a list of possible matches.
|
|
# We'll just use the first.
|
|
converted_words.append(ArpabetSequence(maybe_phonemes[0]))
|
|
else:
|
|
# TODO: Use g2p prediction to predict the phonemes.
|
|
converted_words.append(GraphemeSequence(word))
|
|
|
|
return converted_words
|