mirror of
https://github.com/storytold/storyteller-ml.git
synced 2026-11-02 18:09:20 +00:00
fix tests
This commit is contained in:
@@ -8,7 +8,7 @@ Inspired by and including code from original Tacotron2 by Keith Ito.
|
|||||||
# pyright: strict
|
# pyright: strict
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from typing import List, Union
|
from typing import List, Union, Any
|
||||||
|
|
||||||
# Regular expression matching text enclosed in curly braces:
|
# Regular expression matching text enclosed in curly braces:
|
||||||
_curly_re = re.compile(r'(.*?)\{(.+?)\}(.*)')
|
_curly_re = re.compile(r'(.*?)\{(.+?)\}(.*)')
|
||||||
@@ -16,10 +16,14 @@ _curly_re = re.compile(r'(.*?)\{(.+?)\}(.*)')
|
|||||||
class ArpabetSequence:
|
class ArpabetSequence:
|
||||||
def __init__(self, sequence: str):
|
def __init__(self, sequence: str):
|
||||||
self.sequence = sequence
|
self.sequence = sequence
|
||||||
|
def __eq__(self, other: Any) -> bool:
|
||||||
|
return isinstance(other, ArpabetSequence) and self.sequence == other.sequence
|
||||||
|
|
||||||
class GraphemeSequence:
|
class GraphemeSequence:
|
||||||
def __init__(self, sequence: str):
|
def __init__(self, sequence: str):
|
||||||
self.sequence = sequence
|
self.sequence = sequence
|
||||||
|
def __eq__(self, other: Any) -> bool:
|
||||||
|
return isinstance(other, GraphemeSequence) and self.sequence == other.sequence
|
||||||
|
|
||||||
ParsedSequence = List[Union[ArpabetSequence, GraphemeSequence]]
|
ParsedSequence = List[Union[ArpabetSequence, GraphemeSequence]]
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
from tts.text.phonetization.cmudict import DEFAULT_CMUDICT_PATH, CMUDict
|
from tts.text.phonetization.cmudict import DEFAULT_CMUDICT_PATH, CMUDict
|
||||||
from tts.text.phonetization.english_phonetization import EnglishPhonetization
|
from tts.text.phonetization.english_phonetization import EnglishPhonetization
|
||||||
|
from tts.text.input_parsing.parser import ArpabetSequence
|
||||||
|
from tts.text.input_parsing.parser import GraphemeSequence
|
||||||
|
|
||||||
class TestEnglishPhonetization:
|
class TestEnglishPhonetization:
|
||||||
|
|
||||||
@@ -13,20 +15,59 @@ class TestEnglishPhonetization:
|
|||||||
phoneme_dictionary = CMUDict(DEFAULT_CMUDICT_PATH)
|
phoneme_dictionary = CMUDict(DEFAULT_CMUDICT_PATH)
|
||||||
phonetization = EnglishPhonetization(phoneme_dictionary)
|
phonetization = EnglishPhonetization(phoneme_dictionary)
|
||||||
output = phonetization.try_convert_to_phonemes("this is a test")
|
output = phonetization.try_convert_to_phonemes("this is a test")
|
||||||
assert output == ["DH IH1 S", "IH1 Z", "AH0", "T EH1 S T"]
|
assert output == [
|
||||||
|
ArpabetSequence("DH IH1 S"),
|
||||||
|
ArpabetSequence("IH1 Z"),
|
||||||
|
ArpabetSequence("AH0"),
|
||||||
|
ArpabetSequence("T EH1 S T"),
|
||||||
|
]
|
||||||
|
|
||||||
def test_most_words_in_dictionary(self):
|
def test_most_words_in_dictionary(self):
|
||||||
phoneme_dictionary = CMUDict(DEFAULT_CMUDICT_PATH)
|
phoneme_dictionary = CMUDict(DEFAULT_CMUDICT_PATH)
|
||||||
phonetization = EnglishPhonetization(phoneme_dictionary)
|
phonetization = EnglishPhonetization(phoneme_dictionary)
|
||||||
output = phonetization.try_convert_to_phonemes("nonword is a test")
|
output = phonetization.try_convert_to_phonemes("nonword is a test")
|
||||||
assert output == ["nonword", "IH1 Z", "AH0", "T EH1 S T"]
|
assert output == [
|
||||||
|
GraphemeSequence("nonword"),
|
||||||
|
ArpabetSequence("IH1 Z"),
|
||||||
|
ArpabetSequence("AH0"),
|
||||||
|
ArpabetSequence("T EH1 S T"),
|
||||||
|
]
|
||||||
|
|
||||||
def test_punctuation(self):
|
def test_punctuation(self):
|
||||||
phoneme_dictionary = CMUDict(DEFAULT_CMUDICT_PATH)
|
phoneme_dictionary = CMUDict(DEFAULT_CMUDICT_PATH)
|
||||||
phonetization = EnglishPhonetization(phoneme_dictionary)
|
phonetization = EnglishPhonetization(phoneme_dictionary)
|
||||||
output = phonetization.try_convert_to_phonemes("this...")
|
output = phonetization.try_convert_to_phonemes("this...")
|
||||||
assert output == ["DH IH1 S", "..."]
|
assert output == [
|
||||||
|
ArpabetSequence("DH IH1 S"),
|
||||||
|
GraphemeSequence("..."),
|
||||||
|
]
|
||||||
output = phonetization.try_convert_to_phonemes("this!")
|
output = phonetization.try_convert_to_phonemes("this!")
|
||||||
assert output == ["DH IH1 S", "!"]
|
assert output == [
|
||||||
|
ArpabetSequence("DH IH1 S"),
|
||||||
|
GraphemeSequence("!"),
|
||||||
|
]
|
||||||
output = phonetization.try_convert_to_phonemes("this?")
|
output = phonetization.try_convert_to_phonemes("this?")
|
||||||
assert output == ["DH IH1 S", "?"]
|
assert output == [
|
||||||
|
ArpabetSequence("DH IH1 S"),
|
||||||
|
GraphemeSequence("?"),
|
||||||
|
]
|
||||||
|
|
||||||
|
def test_extra_spaces(self):
|
||||||
|
phoneme_dictionary = CMUDict(DEFAULT_CMUDICT_PATH)
|
||||||
|
phonetization = EnglishPhonetization(phoneme_dictionary)
|
||||||
|
output = phonetization.try_convert_to_phonemes(" this is a test ")
|
||||||
|
assert output == [
|
||||||
|
ArpabetSequence("DH IH1 S"),
|
||||||
|
ArpabetSequence("IH1 Z"),
|
||||||
|
ArpabetSequence("AH0"),
|
||||||
|
ArpabetSequence("T EH1 S T"),
|
||||||
|
]
|
||||||
|
|
||||||
|
def test_multi_non_word_extra_spaces(self):
|
||||||
|
phoneme_dictionary = CMUDict(DEFAULT_CMUDICT_PATH)
|
||||||
|
phonetization = EnglishPhonetization(phoneme_dictionary)
|
||||||
|
output = phonetization.try_convert_to_phonemes(" nonword anothernonword ")
|
||||||
|
assert output == [
|
||||||
|
GraphemeSequence("nonword"),
|
||||||
|
GraphemeSequence("anothernonword"),
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user