From ffbf36fd13b6f0446f0d91c51b7ce85baeae1844 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 5 Jul 2022 03:31:25 -0400 Subject: [PATCH] fix apostrophe, hyphen --- tts/text/pipeline/test_english_pipeline_v1.py | 5 +++++ .../input_parsing/parser.py | 4 ++++ .../phonetization/base_phonetization.py | 6 +++++- .../test_english_phonetization.py | 21 +++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/tts/text/pipeline/test_english_pipeline_v1.py b/tts/text/pipeline/test_english_pipeline_v1.py index 8cc92e7..de9b74f 100644 --- a/tts/text/pipeline/test_english_pipeline_v1.py +++ b/tts/text/pipeline/test_english_pipeline_v1.py @@ -58,3 +58,8 @@ class TestEnglishPipelineV1: 11, # Space 2, # Exclamation mark ] + + def test_apostrophe_word(self): + pipeline = self.build_pipeline_instance() + output = pipeline.user_input_to_sequence("you're") + assert output == [145, 137, 130] # YOU'RE Y UH1 R ~ 145 137 130 diff --git a/tts/text/pipeline_components/input_parsing/parser.py b/tts/text/pipeline_components/input_parsing/parser.py index 871b55f..76a6732 100644 --- a/tts/text/pipeline_components/input_parsing/parser.py +++ b/tts/text/pipeline_components/input_parsing/parser.py @@ -23,6 +23,8 @@ class ArpabetSequence: self.sequence = sequence def __eq__(self, other: Any) -> bool: return isinstance(other, ArpabetSequence) and self.sequence == other.sequence + def __repr__(self): + return f"" class GraphemeSequence: @@ -34,6 +36,8 @@ class GraphemeSequence: self.sequence = sequence def __eq__(self, other: Any) -> bool: return isinstance(other, GraphemeSequence) and self.sequence == other.sequence + def __repr__(self): + return f"" ParsedSequence = List[Union[ArpabetSequence, GraphemeSequence]] diff --git a/tts/text/pipeline_components/phonetization/base_phonetization.py b/tts/text/pipeline_components/phonetization/base_phonetization.py index add1611..9b18053 100644 --- a/tts/text/pipeline_components/phonetization/base_phonetization.py +++ b/tts/text/pipeline_components/phonetization/base_phonetization.py @@ -4,7 +4,11 @@ from typing import List from text.pipeline_components.phonetization.cmudict import CMUDict # Regex taken from open source tacotron2 extensions -_arpabet_split_re = re.compile(r'[^\s]*{.*?}[^\s]*|[\w]+|[^\w\s]+') +# NB: This was broken and couldn't handle apostrophes +#_arpabet_split_re = re.compile(r'[^\s]*{.*?}[^\s]*|[\w]+|[^\w\s]+') + +# Modified regex to not split apostrophe (eg. "you're", "I'm", etc.) or hyphenation (eg "avant-garde") +_arpabet_split_re = re.compile(r'[^\s]*{.*?}[^\s]*|[\w]+\'[\w]+|[\w]+\-[\w]+|[\w]+|[^\w\s]+') class BasePhonetization: def __init__(self, phoneme_dictionary: CMUDict): diff --git a/tts/text/pipeline_components/phonetization/test_english_phonetization.py b/tts/text/pipeline_components/phonetization/test_english_phonetization.py index c5a2926..dc06cb8 100644 --- a/tts/text/pipeline_components/phonetization/test_english_phonetization.py +++ b/tts/text/pipeline_components/phonetization/test_english_phonetization.py @@ -33,6 +33,27 @@ class TestEnglishPhonetization: ArpabetSequence("T EH1 S T"), ] + def test_words_with_apostrophe(self): + phoneme_dictionary = CMUDict(DEFAULT_CMUDICT_PATH) + phonetization = EnglishPhonetization(phoneme_dictionary) + output = phonetization.try_convert_to_phonemes("I'm can't you're we're ain't") + assert output == [ + ArpabetSequence("AY1 M"), + ArpabetSequence("K AE1 N T"), + ArpabetSequence("Y UH1 R"), + ArpabetSequence("W IY1 R"), + ArpabetSequence("EY1 N T"), + ] + + def test_words_with_hyphenation(self): + phoneme_dictionary = CMUDict(DEFAULT_CMUDICT_PATH) + phonetization = EnglishPhonetization(phoneme_dictionary) + output = phonetization.try_convert_to_phonemes("avant-garde bake-off") + assert output == [ + ArpabetSequence("AH0 V AA1 N T G AA1 R D"), + ArpabetSequence("B EY1 K AO1 F"), + ] + def test_punctuation(self): phoneme_dictionary = CMUDict(DEFAULT_CMUDICT_PATH) phonetization = EnglishPhonetization(phoneme_dictionary)