Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,16 @@ from cached_path import cached_path
|
|
| 8 |
|
| 9 |
from dp.phonemizer import Phonemizer
|
| 10 |
phonemizer = Phonemizer.from_checkpoint(str(cached_path('https://public-asai-dl-models.s3.eu-central-1.amazonaws.com/DeepPhonemizer/en_us_cmudict_ipa_forward.pt')))
|
|
|
|
|
|
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
nltk.download('punkt')
|
| 14 |
# Borrowed from https://github.com/sidharthrajaram/StyleTTS2/blob/main/src/styletts2/phoneme.py, MIT License
|
|
@@ -30,6 +39,7 @@ def phonemizerfunc(text):
|
|
| 30 |
ps = ' '.join(ps)
|
| 31 |
return ps
|
| 32 |
def dp(text):
|
|
|
|
| 33 |
return phonemizer(text, lang='en_us')
|
| 34 |
def run(t, r):
|
| 35 |
if r == 'phonemizer': return phonemizerfunc(t)
|
|
|
|
| 8 |
|
| 9 |
from dp.phonemizer import Phonemizer
|
| 10 |
phonemizer = Phonemizer.from_checkpoint(str(cached_path('https://public-asai-dl-models.s3.eu-central-1.amazonaws.com/DeepPhonemizer/en_us_cmudict_ipa_forward.pt')))
|
| 11 |
+
import re
|
| 12 |
+
from num2words import num2words
|
| 13 |
|
| 14 |
+
def replace_numbers_with_words(text):
|
| 15 |
+
pattern = r'\d+'
|
| 16 |
+
matches = re.findall(pattern, text)
|
| 17 |
+
for match in matches:
|
| 18 |
+
word_equivalent = num2words(int(match))
|
| 19 |
+
text = text.replace(match, word_equivalent)
|
| 20 |
+
return text
|
| 21 |
|
| 22 |
nltk.download('punkt')
|
| 23 |
# Borrowed from https://github.com/sidharthrajaram/StyleTTS2/blob/main/src/styletts2/phoneme.py, MIT License
|
|
|
|
| 39 |
ps = ' '.join(ps)
|
| 40 |
return ps
|
| 41 |
def dp(text):
|
| 42 |
+
text = replace_numbers_with_words(text)
|
| 43 |
return phonemizer(text, lang='en_us')
|
| 44 |
def run(t, r):
|
| 45 |
if r == 'phonemizer': return phonemizerfunc(t)
|