Spaces:
Running
on
Zero
Running
on
Zero
Upload app.py
Browse files
app.py
CHANGED
@@ -50,19 +50,17 @@ def split_num(num):
|
|
50 |
if '.' in num:
|
51 |
a, b = num.split('.')
|
52 |
return ' point '.join([a, ' '.join(b)])
|
53 |
-
|
54 |
-
year = int(num)
|
55 |
if year < 1100 or year % 1000 < 10:
|
56 |
return num
|
57 |
-
|
58 |
-
|
59 |
-
second_half_int = int(second_half)
|
60 |
if 100 <= year % 1000 <= 999:
|
61 |
if second_half == '00':
|
62 |
-
return f'{first_half} hundred'
|
63 |
-
elif
|
64 |
-
return f'{first_half} oh {
|
65 |
-
return '
|
66 |
|
67 |
def normalize(text):
|
68 |
# TODO: Custom text normalization rules?
|
@@ -77,7 +75,7 @@ def normalize(text):
|
|
77 |
text = re.sub(r'[^\S \n]', ' ', text)
|
78 |
text = re.sub(r' +', ' ', text)
|
79 |
text = re.sub(r'(?<=\n) +(?=\n)', '', text)
|
80 |
-
text = re.sub(r'\d*\.\d+|\b\d{4}
|
81 |
text = re.sub(r'(?<=\d),(?=\d)', '', text)
|
82 |
text = re.sub(r'(?<=\d)-(?=\d)', ' to ', text) # TODO: could be minus
|
83 |
text = re.sub(r'(?<=\d):(?=\d)', ' ', text)
|
@@ -104,7 +102,8 @@ def phonemize(text, voice, norm=True):
|
|
104 |
ps = ps.replace('kəkˈoːɹoʊ', 'kˈoʊkəɹoʊ').replace('kəkˈɔːɹəʊ', 'kˈəʊkəɹəʊ')
|
105 |
ps = ps.replace('ʲ', 'j').replace('r', 'ɹ').replace('x', 'k')
|
106 |
ps = ps.replace(' z', 'z')
|
107 |
-
ps = re.sub(r'(
|
|
|
108 |
ps = ''.join(filter(lambda p: p in VOCAB, ps))
|
109 |
if lang == 'j' and any(p in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' for p in ps):
|
110 |
gr.Warning('Japanese tokenizer does not handle English letters.')
|
|
|
50 |
if '.' in num:
|
51 |
a, b = num.split('.')
|
52 |
return ' point '.join([a, ' '.join(b)])
|
53 |
+
year = int(num[:4])
|
|
|
54 |
if year < 1100 or year % 1000 < 10:
|
55 |
return num
|
56 |
+
left, right = num[:2], num[2:4],
|
57 |
+
s = 's' if num.endswith('s') else ''
|
|
|
58 |
if 100 <= year % 1000 <= 999:
|
59 |
if second_half == '00':
|
60 |
+
return f'{first_half} hundred{s}'
|
61 |
+
elif int(second_half) < 10:
|
62 |
+
return f'{first_half} oh {second_half}{s}'
|
63 |
+
return f'{first_half} {second_half}{s}'
|
64 |
|
65 |
def normalize(text):
|
66 |
# TODO: Custom text normalization rules?
|
|
|
75 |
text = re.sub(r'[^\S \n]', ' ', text)
|
76 |
text = re.sub(r' +', ' ', text)
|
77 |
text = re.sub(r'(?<=\n) +(?=\n)', '', text)
|
78 |
+
text = re.sub(r'\d*\.\d+|\b\d{4}s?\b', split_num, text)
|
79 |
text = re.sub(r'(?<=\d),(?=\d)', '', text)
|
80 |
text = re.sub(r'(?<=\d)-(?=\d)', ' to ', text) # TODO: could be minus
|
81 |
text = re.sub(r'(?<=\d):(?=\d)', ' ', text)
|
|
|
102 |
ps = ps.replace('kəkˈoːɹoʊ', 'kˈoʊkəɹoʊ').replace('kəkˈɔːɹəʊ', 'kˈəʊkəɹəʊ')
|
103 |
ps = ps.replace('ʲ', 'j').replace('r', 'ɹ').replace('x', 'k')
|
104 |
ps = ps.replace(' z', 'z')
|
105 |
+
ps = re.sub(r'(?<=[a-zɹː])(?=hˈʌndɹɪd)', ' ', ps)
|
106 |
+
ps = re.sub(r'(?<=nˈaɪn)t[iɪ]', ('d' if lang == 'a' else 't') + 'i', ps)
|
107 |
ps = ''.join(filter(lambda p: p in VOCAB, ps))
|
108 |
if lang == 'j' and any(p in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' for p in ps):
|
109 |
gr.Warning('Japanese tokenizer does not handle English letters.')
|