This commit is contained in:
Brandon Thomas
2022-07-04 02:10:46 -04:00
parent fdd5aa8734
commit c401cc5146
3 changed files with 45 additions and 5 deletions
+23 -3
View File
@@ -1,13 +1,14 @@
from typing import List
from tts.text.input_parsing.parser import ArpabetSequence, GraphemeSequence, ParsedSequence, parse_grapheme_and_arpabet_sequence
from tts.text.normalization.english_normalization import EnglishNormalization
from tts.text.phonetization.cmudict import CMUDict
from tts.text.phonetization.cmudict import DEFAULT_CMUDICT_PATH, CMUDict
from tts.text.phonetization.english_phonetization import EnglishPhonetization
from tts.text.pipeline.base_pipeline import BasePipeline
from tts.text.sequencing.english_symbols_v1 import SPACE_INTEGER_ENCODING, arpabet_to_sequence, symbols_to_sequence
_ENGLISH_NORMALIZER = EnglishNormalization()
_ENGLISH_DICTIONARY = CMUDict()
_ENGLISH_DICTIONARY = CMUDict(DEFAULT_CMUDICT_PATH)
_ENGLISH_PHONETIZER = EnglishPhonetization(_ENGLISH_DICTIONARY)
class EnglishPipelineV1(BasePipeline):
@@ -46,4 +47,23 @@ class EnglishPipelineV1(BasePipeline):
return updated_sequence
def _convert_to_integer_sequence(self, parsed_sequence: ParsedSequence) -> List[int]:
pass
integer_sequence = []
last_index = len(parsed_sequence) - 1
for i, subsequence in enumerate(parsed_sequence):
integer_subsequence = []
if isinstance(subsequence, ArpabetSequence):
integer_subsequence = arpabet_to_sequence(subsequence.sequence)
elif isinstance(subsequence, GraphemeSequence):
integer_subsequence = symbols_to_sequence(subsequence.sequence)
if integer_subsequence:
integer_sequence.extend(integer_subsequence)
if i < last_index and integer_sequence[-1] != SPACE_INTEGER_ENCODING:
# Separate words with single spaces if not already present.
integer_sequence.append(SPACE_INTEGER_ENCODING)
return integer_sequence
+19 -2
View File
@@ -21,6 +21,23 @@ class TestEnglishPipelineV1:
def test_two_words(self):
pipeline = EnglishPipelineV1()
output = pipeline.user_input_to_sequence("hello hello")
assert output == [106, 73, 117, 123, 11, 106, 73, 117, 123]
assert output == [
106, 73, 117, 123, # NB: Arpabet encoded
11, # Space
106, 73, 117, 123, # Arpabet encoded
]
def test_words_and_punctuation(self):
pipeline = EnglishPipelineV1()
output = pipeline.user_input_to_sequence("hello friends, welcome!")
assert output == [
106, 73, 117, 123, # NB: Arpabet encoded
11, # Space
104, 130, 94, 119, 90, 146,
11, # Space (TODO: Get rid of extraneous spaces with richer parsing)
6, # Comma
11, # Space
144, 94, 117, 116, 73, 118,
11, # Space
2, # Exclamation mark
]
@@ -34,6 +34,9 @@ symbols = [_pad] + list(_special) + list(_punctuation) + list(_letters) + _arpab
_symbol_to_id = {s: i for i, s in enumerate(symbols)}
_id_to_symbol = {i: s for i, s in enumerate(symbols)}
# Spaces can be injected when joining words.
SPACE_INTEGER_ENCODING = _symbol_to_id[' ']
def symbols_to_sequence(symbols: str) -> List[int]:
return [_symbol_to_id[s] for s in symbols if _should_keep_symbol(s)]