diff --git a/inference.ipynb b/inference.ipynb index 12f5985..3d092a5 100644 --- a/inference.ipynb +++ b/inference.ipynb @@ -2,13 +2,14 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ + "[KO]안녕하세요.[KO][PREPROCESSED]ㅋㅗㄴㄴㅣㅊㅣㅇㅗㅏ.[PREPROCESSED]\n", "Mutli-stream iSTFT VITS\n" ] }, @@ -17,7 +18,7 @@ "text/html": [ "\n", " \n", " " @@ -43,22 +44,26 @@ "from text.j2k import japanese2korean\n", "\n", "\n", - "\n", - "text = \"\"\"\n", - "[JA]水をマレーシアから買わなくてはならないのです。[JA]\n", - "\"\"\"\n", "# 일본어로 학습한 경우 True, 한국어로 학습한 경우 False로 isJaModel 값을 바꿔주세요.\n", - "\n", - "model_name = 'ko'\n", + "isJaModel = False # True\n", + "model_name = 'ko' # ja\n", "config_file = f\"./configs/{model_name}.json\"\n", - "isJaModel = False\n", - "model_file = f\"./logs/{model_name}/G_80000.pth\"\n", + "model_file = f\"./logs/{model_name}/G_91000.pth\"\n", "device = 'cpu' # cuda:0\n", "\n", + "\n", + "text = \"\"\"\n", + "[KO]안녕하세요.[KO]\n", + "[JA]こんにちは.[JA]\n", + "\"\"\"\n", + "\n", + "text = re.sub('[\\n]', '', text).strip()\n", "if isJaModel:\n", - " text = re.sub(r'\\[KO\\](.*?)\\[KO\\]', lambda x: '[JA]'+korean2katakana(x.group(1))+'.[JA]', text)\n", + " text = re.sub(r'\\[KO\\](.*?)\\[KO\\]', lambda x: korean2katakana(x.group(1)), text)\n", "else:\n", - " text = re.sub(r'\\[JA\\](.*?)\\[JA\\]', lambda x: '[KO]'+japanese2korean(x.group(1))+'.[KO]', text)\n", + " text = re.sub(r'\\[JA\\](.*?)\\[JA\\]', lambda x: japanese2korean(x.group(1)), text)\n", + "\n", + "print(text)\n", "\n", "def get_text(text, hps):\n", " text_norm = text_to_sequence(text, hps.data.text_cleaners)\n", @@ -67,6 +72,7 @@ " text_norm = torch.LongTensor(text_norm)\n", " return text_norm\n", "\n", + "\n", "hps = utils.get_hparams_from_file(config_file)\n", "\n", "net_g = SynthesizerTrn(\n", @@ -78,8 +84,6 @@ "\n", "_ = utils.load_checkpoint(model_file, net_g, None)\n", "\n", - "text = re.sub('[\\n]', '', text).strip()\n", - "\n", "stn_tst = get_text(text, hps)\n", "with torch.no_grad():\n", " x_tst = stn_tst.to(device).unsqueeze(0)\n", @@ -87,13 +91,6 @@ " audio = net_g.infer(x_tst, x_tst_lengths, noise_scale=.667, noise_scale_w=0.8, length_scale=1)[0][0,0].data.cpu().float().numpy()\n", "ipd.display(ipd.Audio(audio, rate=hps.data.sampling_rate, normalize=True))" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/text/cleaners.py b/text/cleaners.py index 00bb292..926411b 100644 --- a/text/cleaners.py +++ b/text/cleaners.py @@ -23,5 +23,6 @@ def korean_cleaners(text): def jk_cleaners(text): text = re.sub(r'\[JA\](.*?)\[JA\]', lambda x: japanese_cleaners(x.group(1))+' ', text) text = re.sub(r'\[KO\](.*?)\[KO\]', lambda x: korean_cleaners(x.group(1))+' ', text) + text = re.sub(r'\[PREPROCESSED\](.*?)\[PREPROCESSED\]', lambda x: x.group(1)+' ', text) text = ''.join(_cleaner_cleans.findall(text)) return text \ No newline at end of file diff --git a/text/j2k.py b/text/j2k.py index 5b92f64..95e7f10 100644 --- a/text/j2k.py +++ b/text/j2k.py @@ -1,7 +1,6 @@ -from .cleaners import japanese_to_romaji_with_accent +from .cleaners import japanese_to_romaji_with_accent, korean_cleaners from .korean import join_jamos - repl_lst = { '.': '. ', '↓': '', @@ -14,10 +13,15 @@ 'Q': ' |Q ', 'N': ' |N ', 'U': 'u ', + 'I': 'i ', + 'A': 'a ', + 'E': 'e ', + 'O': 'o ', } repl_lst2 = { 'ʧu': '츠', + 'tsu': '츠', 'zu': '즈', 'su': '스', @@ -35,6 +39,7 @@ 's': 'ㅅ', 'j': 'ㅈ', 'ʧ': 'ㅊ', + 'ts': 'ㅊ', 'k': 'ㅋ', 't': 'ㅌ', 'p': 'ㅍ', @@ -80,12 +85,13 @@ '|Nㅇ': 'ㅇㅇ', '|Nㅎ': 'ㅇㅎ', - '|Q': 'ㅅ' + '|Q': 'ㅅ', + '|N': 'ㄴ', } def japanese2korean(text): - text = japanese_to_romaji_with_accent(text).strip() + text = japanese_to_romaji_with_accent(text).strip().replace('^', '').replace(' ', '^ ') for k, v in repl_lst.items(): text = text.replace(k, v) @@ -93,7 +99,11 @@ def japanese2korean(text): text = text.replace(k, v) text = ' '.join([i.replace('*', 'ㅇ') if i.startswith('*') else i.replace('*', '') for i in text.strip().split(' ')]) + for k, v in repl_lst3.items(): text = text.replace(k, v) - return join_jamos(text.replace(' ', '_').replace(' ', '')) + text = join_jamos(text.replace(' ', ' ')).replace(' ', '').replace('^', ' ') + return f"[PREPROCESSED]{korean_cleaners(text)}[PREPROCESSED]" + + diff --git a/text/k2j.py b/text/k2j.py index 94c83eb..58d1987 100644 --- a/text/k2j.py +++ b/text/k2j.py @@ -5,6 +5,7 @@ number_to_hangul, g2pk, ) +from .cleaners import japanese_cleaners import re import jaconv @@ -47,7 +48,8 @@ def get_word_list(text): def korean2katakana(text): word_lst = get_word_list(text) - text = '/' + text.replace('/', ' ').replace('|', ' ').replace('^', ' ').replace(' ', ' ').replace(' ', '^') + text = '/' + text.replace('/', ' ').replace('|', ' ').replace('^', ' ').replace(' ', ' ') + print(text) new_lst = [] for i, s in enumerate(word_lst): @@ -70,17 +72,12 @@ def korean2katakana(text): 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 - -# print(korean2katakana("안녕하세요.")) -> アンニョンーハセヨ \ No newline at end of file + result = jaconv.alphabet2kata(kr2ro).replace('|', 'ー').replace('/', '').replace('^', '') + result = result if result[-1] == '.' else result + '.' + return f'[PREPROCESSED]{japanese_cleaners(result).replace(" ", "")}[PREPROCESSED]' \ No newline at end of file