mirror of
https://github.com/storytold/storyteller-ml.git
synced 2026-10-22 08:16:08 +00:00
fix apostrophe, hyphen
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user