mirror of
https://github.com/storytold/storyteller-ml.git
synced 2026-10-17 00:23:14 +00:00
More work on legacy pipeline
This commit is contained in:
@@ -1,18 +1,26 @@
|
||||
import re
|
||||
from typing import List
|
||||
from tts.text.pipeline.base_pipeline import BasePipeline
|
||||
from tts.text.pipeline_components.normalization.common_cleaners import collapse_whitespace, convert_to_ascii, lowercase
|
||||
from tts.text.pipeline_components.normalization.english_cleaners import expand_abbreviations, expand_numbers
|
||||
from tts.text.pipeline_components.sequencing.english_symbols_v1 import arpabet_to_sequence, symbols_to_sequence
|
||||
|
||||
# Regular expression matching text enclosed in curly braces:
|
||||
_curly_re = re.compile(r'(.*?)\{(.+?)\}(.*)')
|
||||
|
||||
class LegacyFakeYouPipeline(BasePipeline):
|
||||
"""
|
||||
This pipeline was in use from June 2021 to July 2022.
|
||||
In contrast to legacy "vo.codes" (2020 - 2021), it does not
|
||||
leverage Arpabet even when models were trained with Arpabet support.
|
||||
leverage CMUDict to look up arpabet even when models were known to
|
||||
be trained with arpabet support. (It did support curly braces for
|
||||
manual arpabet inclusion.)
|
||||
"""
|
||||
|
||||
|
||||
def user_input_to_sequence(self, input_text: str) -> List[int]:
|
||||
"""Convert raw user input into a numerical sequence for ML inference."""
|
||||
pre_sequence = self._preprocess_text(input_text)
|
||||
return text_to_sequence(pre_sequence, ['english_cleaners'])
|
||||
return self._text_to_sequence(pre_sequence, ['english_cleaners'])
|
||||
|
||||
def _preprocess_text(self, input_text: str, is_raw_input: bool = True) -> str:
|
||||
pre_sequence = ""
|
||||
@@ -25,4 +33,42 @@ class LegacyFakeYouPipeline(BasePipeline):
|
||||
else:
|
||||
pass
|
||||
pre_sequence += line
|
||||
return pre_sequence
|
||||
return pre_sequence
|
||||
|
||||
|
||||
def _text_to_sequence(self, text, cleaner_names):
|
||||
'''Converts a string of text to a sequence of IDs corresponding to the symbols in the text.
|
||||
|
||||
The text can optionally have ARPAbet sequences enclosed in curly braces embedded
|
||||
in it. For example, "Turn left on {HH AW1 S S T AH0 N} Street."
|
||||
|
||||
Args:
|
||||
text: string to convert to a sequence
|
||||
cleaner_names: names of the cleaner functions to run the text through
|
||||
|
||||
Returns:
|
||||
List of integers corresponding to the symbols in the text
|
||||
'''
|
||||
sequence = []
|
||||
|
||||
# Check for curly braces and treat their contents as ARPAbet:
|
||||
while len(text):
|
||||
m = _curly_re.match(text)
|
||||
if not m:
|
||||
sequence += symbols_to_sequence(english_cleaners(text))
|
||||
break
|
||||
sequence += symbols_to_sequence(english_cleaners(m.group(1)))
|
||||
sequence += arpabet_to_sequence(m.group(2))
|
||||
text = m.group(3)
|
||||
|
||||
return sequence
|
||||
|
||||
|
||||
def english_cleaners(text):
|
||||
'''Pipeline for English text, including number and abbreviation expansion.'''
|
||||
text = convert_to_ascii(text)
|
||||
text = lowercase(text)
|
||||
text = expand_numbers(text)
|
||||
text = expand_abbreviations(text)
|
||||
text = collapse_whitespace(text)
|
||||
return text
|
||||
|
||||
Reference in New Issue
Block a user