def test_convert_hundreds(self): self.assertEqual(pronounce_number(100), "one hundred") self.assertEqual(pronounce_number(666), "six hundred and sixty six") self.assertEqual(pronounce_number(1456), "fourteen fifty six") self.assertEqual(pronounce_number(103254654), "one hundred and three " "million, two hundred " "and fifty four " "thousand, six hundred " "and fifty four") self.assertEqual(pronounce_number(1512457), "one million, five hundred" " and twelve thousand, " "four hundred and fifty " "seven") self.assertEqual(pronounce_number(209996), "two hundred and nine " "thousand, nine hundred " "and ninety six") self.assertEqual(pronounce_number(95505896639631893), "ninety five quadrillion, five hundred and five " "trillion, eight hundred and ninety six billion, six " "hundred and thirty nine million, six hundred and " "thirty one thousand, eight hundred and ninety three") self.assertEqual(pronounce_number(95505896639631893, short_scale=False), "ninety five thousand five hundred and five billion, " "eight hundred and ninety six thousand six hundred " "and thirty nine million, six hundred and thirty one " "thousand, eight hundred and ninety three")
def test_convert_scientific_notation(self): self.assertEqual(pronounce_number(0, scientific=True), "zero") self.assertEqual(pronounce_number(33, scientific=True), "three point three times ten to the power of one") self.assertEqual(pronounce_number(299792458, scientific=True), "two point nine nine times ten to the power of eight") self.assertEqual(pronounce_number(299792458, places=6, scientific=True), "two point nine nine seven nine two five times " "ten to the power of eight") self.assertEqual(pronounce_number(1.672e-27, places=3, scientific=True), "one point six seven two times ten to the power of " "negative twenty seven")
def test_convert_int(self): self.assertEqual(pronounce_number(0), "zero") self.assertEqual(pronounce_number(1), "one") self.assertEqual(pronounce_number(10), "ten") self.assertEqual(pronounce_number(15), "fifteen") self.assertEqual(pronounce_number(20), "twenty") self.assertEqual(pronounce_number(27), "twenty seven") self.assertEqual(pronounce_number(30), "thirty") self.assertEqual(pronounce_number(33), "thirty three")
def test_convert_int(self): self.assertEqual(pronounce_number(0, lang="it"), "zero") self.assertEqual(pronounce_number(1, lang="it"), "uno") self.assertEqual(pronounce_number(10, lang="it"), "dieci") self.assertEqual(pronounce_number(15, lang="it"), "quindici") self.assertEqual(pronounce_number(21, lang="it"), "ventuno") self.assertEqual(pronounce_number(27, lang="it"), "ventisette") self.assertEqual(pronounce_number(30, lang="it"), "trenta") self.assertEqual(pronounce_number(83, lang="it"), "ottantatre")
def test_convert_negative_int(self): self.assertEqual(pronounce_number(-1), "negative one") self.assertEqual(pronounce_number(-10), "negative ten") self.assertEqual(pronounce_number(-15), "negative fifteen") self.assertEqual(pronounce_number(-20), "negative twenty") self.assertEqual(pronounce_number(-27), "negative twenty seven") self.assertEqual(pronounce_number(-30), "negative thirty") self.assertEqual(pronounce_number(-33), "negative thirty three")
def test_convert_negative_int(self): self.assertEqual(pronounce_number(-1, lang="it"), "meno uno") self.assertEqual(pronounce_number(-10, lang="it"), "meno dieci") self.assertEqual(pronounce_number(-15, lang="it"), "meno quindici") self.assertEqual(pronounce_number(-21, lang="it"), "meno ventuno") self.assertEqual(pronounce_number(-27, lang="it"), "meno ventisette") self.assertEqual(pronounce_number(-30, lang="it"), "meno trenta") self.assertEqual(pronounce_number(-83, lang="it"), "meno ottantatre")
def test_convert_negative_int_fr(self): self.assertEqual(pronounce_number(-1, lang="fr-fr"), "moins un") self.assertEqual(pronounce_number(-10, lang="fr-fr"), "moins dix") self.assertEqual(pronounce_number(-15, lang="fr-fr"), "moins quinze") self.assertEqual(pronounce_number(-20, lang="fr-fr"), "moins vingt") self.assertEqual(pronounce_number(-27, lang="fr-fr"), "moins vingt-sept") self.assertEqual(pronounce_number(-30, lang="fr-fr"), "moins trente") self.assertEqual(pronounce_number(-33, lang="fr-fr"), "moins trente-trois")
def test_convert_negative_int_de(self): self.assertEqual(pronounce_number(-1, lang="de-de"), "minus eins") self.assertEqual(pronounce_number(-10, lang="de-de"), "minus zehn") self.assertEqual(pronounce_number(-15, lang="de-de"), u"minus fünfzehn") self.assertEqual(pronounce_number(-20, lang="de-de"), "minus zwanzig") self.assertEqual(pronounce_number(-27, lang="de-de"), "minus siebenundzwanzig") self.assertEqual(pronounce_number(-30, lang="de-de"), u"minus dreißig") self.assertEqual(pronounce_number(-33, lang="de-de"), u"minus dreiunddreißig")
def _normalized_numbers(self, sentence): """normalized numbers to word equivalent. Args: sentence (str): setence to speak Returns: stf: normalized sentences to speak """ try: numbers = re.findall(r'\d+', sentence) normalized_num = [(num, pronounce_number(int(num))) for num in numbers] for num, norm_num in normalized_num: sentence = sentence.replace(num, norm_num, 1) except TypeError: LOG.exception("type error in mimic2_tts.py _normalized_numbers()") return sentence
def test_convert_decimals_de(self): self.assertEqual(pronounce_number(1.234, lang="de-de"), "eins Komma zwei drei") self.assertEqual(pronounce_number(21.234, lang="de-de"), "einundzwanzig Komma zwei drei") self.assertEqual(pronounce_number(21.234, lang="de-de", places=1), "einundzwanzig Komma zwei") self.assertEqual(pronounce_number(21.234, lang="de-de", places=0), "einundzwanzig") self.assertEqual(pronounce_number(21.234, lang="de-de", places=3), "einundzwanzig Komma zwei drei vier") self.assertEqual(pronounce_number(21.234, lang="de-de", places=4), "einundzwanzig Komma zwei drei vier null") self.assertEqual(pronounce_number(21.234, lang="de-de", places=5), "einundzwanzig Komma zwei drei vier null null") self.assertEqual(pronounce_number(-1.234, lang="de-de"), "minus eins Komma zwei drei") self.assertEqual(pronounce_number(-21.234, lang="de-de"), "minus einundzwanzig Komma zwei drei") self.assertEqual(pronounce_number(-21.234, lang="de-de", places=1), "minus einundzwanzig Komma zwei") self.assertEqual(pronounce_number(-21.234, lang="de-de", places=0), "minus einundzwanzig") self.assertEqual(pronounce_number(-21.234, lang="de-de", places=3), "minus einundzwanzig Komma zwei drei vier") self.assertEqual(pronounce_number(-21.234, lang="de-de", places=4), "minus einundzwanzig Komma zwei drei vier null") self.assertEqual(pronounce_number(-21.234, lang="de-de", places=5), "minus einundzwanzig Komma zwei drei vier null null")
def test_convert_int_de(self): self.assertEqual(pronounce_number(123456789123456789, lang="de-de"), "einhundertdreiundzwanzig Billiarden " "vierhundertsechsundfünfzig Billionen " "siebenhundertneunundachtzig Milliarden " "einhundertdreiundzwanzig Millionen " "vierhundertsechsundfünfzigtausendsiebenhundert" "neunundachtzig") self.assertEqual(pronounce_number(1, lang="de-de"), "eins") self.assertEqual(pronounce_number(10, lang="de-de"), "zehn") self.assertEqual(pronounce_number(15, lang="de-de"), u"fünfzehn") self.assertEqual(pronounce_number(20, lang="de-de"), "zwanzig") self.assertEqual(pronounce_number(27, lang="de-de"), "siebenundzwanzig") self.assertEqual(pronounce_number(30, lang="de-de"), u"dreißig") self.assertEqual(pronounce_number(33, lang="de-de"), u"dreiunddreißig") self.assertEqual(pronounce_number(71, lang="de-de"), "einundsiebzig") self.assertEqual(pronounce_number(80, lang="de-de"), "achtzig") self.assertEqual(pronounce_number(74, lang="de-de"), "vierundsiebzig") self.assertEqual(pronounce_number(79, lang="de-de"), "neunundsiebzig") self.assertEqual(pronounce_number(91, lang="de-de"), "einundneunzig") self.assertEqual(pronounce_number(97, lang="de-de"), "siebenundneunzig") self.assertEqual(pronounce_number(300, lang="de-de"), "dreihundert")
def test_convert_decimals(self): self.assertEqual(pronounce_number(1.234), "one point two three") self.assertEqual(pronounce_number(21.234), "twenty one point two three") self.assertEqual(pronounce_number(21.234, places=1), "twenty one point two") self.assertEqual(pronounce_number(21.234, places=0), "twenty one") self.assertEqual(pronounce_number(21.234, places=3), "twenty one point two three four") self.assertEqual(pronounce_number(21.234, places=4), "twenty one point two three four") self.assertEqual(pronounce_number(21.234, places=5), "twenty one point two three four") self.assertEqual(pronounce_number(-1.234), "negative one point two three") self.assertEqual(pronounce_number(-21.234), "negative twenty one point two three") self.assertEqual(pronounce_number(-21.234, places=1), "negative twenty one point two") self.assertEqual(pronounce_number(-21.234, places=0), "negative twenty one") self.assertEqual(pronounce_number(-21.234, places=3), "negative twenty one point two three four") self.assertEqual(pronounce_number(-21.234, places=4), "negative twenty one point two three four") self.assertEqual(pronounce_number(-21.234, places=5), "negative twenty one point two three four")
def test_convert_int_fr(self): self.assertEqual(pronounce_number(0, lang="fr-fr"), "zéro") self.assertEqual(pronounce_number(1, lang="fr-fr"), "un") self.assertEqual(pronounce_number(10, lang="fr-fr"), "dix") self.assertEqual(pronounce_number(15, lang="fr-fr"), "quinze") self.assertEqual(pronounce_number(20, lang="fr-fr"), "vingt") self.assertEqual(pronounce_number(27, lang="fr-fr"), "vingt-sept") self.assertEqual(pronounce_number(30, lang="fr-fr"), "trente") self.assertEqual(pronounce_number(33, lang="fr-fr"), "trente-trois") self.assertEqual(pronounce_number(71, lang="fr-fr"), "soixante-et-onze") self.assertEqual(pronounce_number(80, lang="fr-fr"), "quatre-vingts") self.assertEqual(pronounce_number(74, lang="fr-fr"), "soixante-quatorze") self.assertEqual(pronounce_number(79, lang="fr-fr"), "soixante-dix-neuf") self.assertEqual(pronounce_number(91, lang="fr-fr"), "quatre-vingt-onze") self.assertEqual(pronounce_number(97, lang="fr-fr"), "quatre-vingt-dix-sept") self.assertEqual(pronounce_number(300, lang="fr-fr"), "300")
def test_convert_decimals_fr(self): self.assertEqual(pronounce_number(1.234, lang="fr-fr"), "un virgule deux trois") self.assertEqual(pronounce_number(21.234, lang="fr-fr"), "vingt-et-un virgule deux trois") self.assertEqual(pronounce_number(21.234, lang="fr-fr", places=1), "vingt-et-un virgule deux") self.assertEqual(pronounce_number(21.234, lang="fr-fr", places=0), "vingt-et-un") self.assertEqual(pronounce_number(21.234, lang="fr-fr", places=3), "vingt-et-un virgule deux trois quatre") self.assertEqual(pronounce_number(21.234, lang="fr-fr", places=4), "vingt-et-un virgule deux trois quatre") self.assertEqual(pronounce_number(21.234, lang="fr-fr", places=5), "vingt-et-un virgule deux trois quatre") self.assertEqual(pronounce_number(-1.234, lang="fr-fr"), "moins un virgule deux trois") self.assertEqual(pronounce_number(-21.234, lang="fr-fr"), "moins vingt-et-un virgule deux trois") self.assertEqual(pronounce_number(-21.234, lang="fr-fr", places=1), "moins vingt-et-un virgule deux") self.assertEqual(pronounce_number(-21.234, lang="fr-fr", places=0), "moins vingt-et-un") self.assertEqual(pronounce_number(-21.234, lang="fr-fr", places=3), "moins vingt-et-un virgule deux trois quatre") self.assertEqual(pronounce_number(-21.234, lang="fr-fr", places=4), "moins vingt-et-un virgule deux trois quatre") self.assertEqual(pronounce_number(-21.234, lang="fr-fr", places=5), "moins vingt-et-un virgule deux trois quatre")
def test_convert_decimals(self): self.assertEqual(pronounce_number(1.234, lang="it"), "uno virgola due tre") self.assertEqual(pronounce_number(21.234, lang="it"), "ventuno virgola due tre") self.assertEqual(pronounce_number(21.234, lang="it", places=1), "ventuno virgola due") self.assertEqual(pronounce_number(21.234, lang="it", places=0), "ventuno") self.assertEqual(pronounce_number(21.234, lang="it", places=3), "ventuno virgola due tre quattro") self.assertEqual(pronounce_number(21.234, lang="it", places=4), "ventuno virgola due tre quattro") self.assertEqual(pronounce_number(21.234, lang="it", places=5), "ventuno virgola due tre quattro") self.assertEqual(pronounce_number(-21.234, lang="it"), "meno ventuno virgola due tre") self.assertEqual(pronounce_number(-21.234, lang="it", places=1), "meno ventuno virgola due") self.assertEqual(pronounce_number(-21.234, lang="it", places=0), "meno ventuno") self.assertEqual(pronounce_number(-21.234, lang="it", places=3), "meno ventuno virgola due tre quattro") self.assertEqual(pronounce_number(-21.234, lang="it", places=4), "meno ventuno virgola due tre quattro") self.assertEqual(pronounce_number(-21.234, lang="it", places=5), "meno ventuno virgola due tre quattro")