AronaTTS / text /k2j.py
kdrkdrkdr's picture
add features.
35b8bdf
raw
history blame
2.05 kB
from text.cleaners import japanese_to_romaji_with_accent
from text.korean import (
join_jamos, j2hcj, h2j,
latin_to_hangul,
number_to_hangul,
g2pk,
)
import re
import jaconv
repl_lst = {
'γ„²': 'γ…‹',
'γ„Έ': 'γ…Œ',
'γ…ƒ': 'ㅍ',
'γ…†': 'γ……',
'γ…‰': 'γ…Š',
'γ…™': 'γ…—/γ…”',
'γ…š': 'γ…—/γ…£',
'γ…˜': 'γ…œγ…',
'ㅝ': 'γ…œ/γ…“',
'γ…ž': 'γ…œ/γ…”',
'γ…Ÿ': 'γ…œγ…£',
'γ…’': 'γ…œγ…£',
'γ…’': 'γ…£γ…”',
'γ…•': 'γ…›',
'γ…–': 'γ…£γ…”',
'γ…“': 'γ…—',
'ㅐ': 'γ…”',
'γ…‘': 'γ…œ',
'||//γ…Ž': 'γ„Ή',
}
def get_word_list(text):
text = latin_to_hangul(text)
text = number_to_hangul(text)
text = g2pk(text)
text = j2hcj(h2j(text))
text = re.sub(r'([\u3131-\u3163])$', r'\1.', text)
return list(join_jamos(text.replace(' ', ' ')[:-1]))
def korean2katakana(text):
text = '/' + text.replace('/', ' ').replace('|', ' ').replace('^', ' ').replace(' ', ' ').replace(' ', '^')
word_lst = get_word_list(text)
new_lst = []
for i, s in enumerate(word_lst):
dh = list(j2hcj(h2j(s)))
if len(dh) == 3:
if dh[-1] == 'γ„΄':
dh[-1] = 'γ„΄'
elif dh[-1] == 'ㅁ' or dh[-1] == 'γ…‡':
dh[-1] = 'γ„΄|'
elif dh[-1] == 'γ„Ή':
dh[-1] = '||/'
else: # γ„± γ„· γ…‚
dh[-1] = dh[-1]
dh.append('/')
new_lst.extend(dh)
kr = ''.join(new_lst)
for k, v in repl_lst.items():
kr = kr.replace(k, v)
kr2ro = japanese_to_romaji_with_accent(kr).replace('si', 'shi').replace('c', 'ts') \
.replace('ti', 'ティー').replace('tu', 'γƒˆγ‚₯γƒΌ') \
.replace('di', 'ディー').replace('du', 'ドγ‚₯γƒΌ')
result = jaconv.alphabet2kata(kr2ro)
result = result.replace('/', '').replace('|', 'γƒΌ').replace('^', '')
print(result)
return result