Skip to content

Commit

Permalink
Merge pull request #4 from Kor-SVS/dev
Browse files Browse the repository at this point in the history
초기 릴리즈 준비 v0.1.0
  • Loading branch information
Cardroid committed Aug 31, 2022
2 parents 76c2165 + dfdd83a commit bd92c6b
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 77 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pyBuild.bat
dist/
*.spec

Expand Down
25 changes: 13 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# from glob import glob
# from posixpath import basename, splitext
from importlib.machinery import SourceFileLoader
import setuptools

version = SourceFileLoader("enunu_kor_tool.version", "src/enunu_kor_tool/version.py").load_module()

required_packages = [
"colorlog",
"tqdm",
Expand All @@ -22,11 +23,11 @@
# ustx2lab_required_packages = [
# ]

ust2lab4model_required_packages = [
"colored_traceback",
"nnsvs",
"torch==1.11.0", # pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113
]
# ust2lab4model_required_packages = [
# "colored_traceback",
# "nnsvs",
# "torch==1.11.0", # pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113
# ]

analysis4vb_required_packages = [
"matplotlib==3.5.3",
Expand All @@ -38,14 +39,14 @@
total_required_packages += g2p4utau_required_packages
total_required_packages += utaupyk_required_packages
# total_required_packages += ustx2lab_required_packages
total_required_packages += ust2lab4model_required_packages
# total_required_packages += ust2lab4model_required_packages
total_required_packages += analysis4vb_required_packages

total_required_packages = list(set(total_required_packages))

setuptools.setup(
name="enunu_kor_tool",
version="0.1.0",
name=version.package_name,
version=version.version,
author="cardroid",
author_email="carbonsindh@gmail.com",
description="enunu Korean language support script collection",
Expand All @@ -58,7 +59,7 @@
"utaupyk": g2p4utau_required_packages + utaupyk_required_packages,
"ustx2lab": g2p4utau_required_packages + utaupyk_required_packages, # + ustx2lab_required_packages,
"analysis4vb": analysis4vb_required_packages,
"ust2lab4model": ust2lab4model_required_packages,
# "ust2lab4model": ust2lab4model_required_packages,
},
package_dir={"": "src"},
python_requires=">=3.8",
Expand All @@ -70,7 +71,7 @@
"lab2ntlab=enunu_kor_tool.entry.lab2ntlab:main",
"analysis4vb=enunu_kor_tool.analysis4vb.analysis:main",
"exe_test=enunu_kor_tool.entry.exe_entry:main",
"ust2lab4model=enunu_kor_tool.entry.ust2lab4model:main",
# "ust2lab4model=enunu_kor_tool.entry.ust2lab4model:main",
]
},
)
32 changes: 13 additions & 19 deletions src/enunu_kor_tool/analysis4vb/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
def cli_ui_main():
import cli_ui

print("> 설명: 해당 모듈은 ENUNU 데이터 베이스 통계를 볼 수 있습니다.")
print("* TIP: 파일이나 폴더의 경로를 입력할 때, 드래그 & 드롭으로 쉽게 입력할 수 있습니다.")

args = {}

args["config"] = cli_ui.ask_string("Config 파일의 경로를 입력해주세요 (생략 가능): ")
args["input"] = cli_ui.ask_string("DB 경로를 입력해주세요 (폴더만 가능): ")
args["input"] = cli_ui.ask_string("DB 폴더의 경로를 입력해주세요.")

main(args)

Expand All @@ -29,40 +29,34 @@ def main(args=None):

parser = argparse.ArgumentParser(description="ENUNU 데이터 셋의 통계를 생성합니다.")

parser.add_argument("-p", dest="config", help="Config 파일 경로")
parser.add_argument("-i", dest="input", required=True, help="데이터 셋의 경로")
# parser.add_argument("-o", dest="output", required=True, help="출력 디렉토리 경로")

args = vars(parser.parse_args())

args["input"] = args["input"].rstrip("\\")

assert os.path.isdir(args["input"]), "입력한 경로에서 DB를 찾을 수 없습니다."

log.DIR_PATH = os.path.join(args["input"], "logs")
log.DIR_PATH = os.path.join(args["input"], "analysis", "logs")
config_path = os.path.join(args["input"], "analysis", "analysis_config.yaml")

def get_root_module_logger():
loglevel = options.get("log_level", "info") if (options := config.get("options")) != None else "info"
return log.get_logger("analysis4vb", loglevel)

if not isinstance(args.get("config"), str) or not os.path.isfile(args["config"]):
args["config"] = os.path.join(args["input"], "analysis_config.yaml")
if not os.path.isfile(config_path):
config = DEFAULT_CONFIG

if os.path.isfile(args["config"]):
config = utils.load_yaml(args["config"])
logger = get_root_module_logger()
with open(config_path, "w", encoding="utf-8") as f:
f.write(DEFAULT_YAML_CONFIG)

logger.debug("DB 내부의 Config를 읽었습니다.")
else:
config = DEFAULT_CONFIG

with open(args["config"], "w", encoding="utf-8") as f:
f.write(DEFAULT_YAML_CONFIG)
logger = get_root_module_logger()
logger.warning(f"Config 파일이 존재하지 않습니다. (DB 내부에 기본 Config 파일을 생성합니다)\nPath=[{config_path}]")

logger = get_root_module_logger()
logger.warning(f"Config 파일이 존재하지 않습니다. Path=[{args['config']}]\n[{args['input']}] 내부에 기본값 Config 파일을 생성합니다.")
input("Config 파일을 DB에 맞게 수정하고, 엔터를 눌러주세요...")
config = utils.load_yaml(config_path)
else:
config = utils.load_yaml(args["config"])
config = utils.load_yaml(config_path)
logger = get_root_module_logger()
logger.debug("성공적으로 Config를 읽었습니다.")

Expand Down
50 changes: 26 additions & 24 deletions src/enunu_kor_tool/analysis4vb/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

DEFAULT_CONFIG = {
"output": {
"stats": "%(db_path)s/stats",
"graph": "%(db_path)s/stats/graph",
"temp": "%(db_path)s/temp",
"stats": "%(db_path)s/analysis/stats",
"graph": "%(db_path)s/analysis/stats/graph",
"temp": "%(db_path)s/analysis/temp",
},
"options": {
"log_level": "info",
"encoding": "utf-8",
"graph_save": True,
"graph_show": True,
"graph_show": False,
"graph_darkmode": True,
"graph_show_dpi": 100,
},
Expand All @@ -27,26 +27,28 @@


def __config2yaml(config):
config_yaml = str(yaml.dump(config, indent=2, sort_keys=False, allow_unicode=True)).split("\n")

result = []
count = 0
is_funcs = False
for line in config_yaml:
if is_funcs:
count += 1
if count > 1:
if line.strip().startswith("-"):
line = "# " + line
else:
is_funcs = False
count -= 1
elif line == "funcs:":
is_funcs = True

result.append(line)

return "\n".join(result)
return str(yaml.dump(config, indent=2, sort_keys=False, allow_unicode=True))

# config_yaml = str(yaml.dump(config, indent=2, sort_keys=False, allow_unicode=True)).split("\n")

# result = []
# count = 0
# is_funcs = False
# for line in config_yaml:
# if is_funcs:
# count += 1
# if count > 1:
# if line.strip().startswith("-"):
# line = "#" + line
# else:
# is_funcs = False
# count -= 1
# elif line == "funcs:":
# is_funcs = True

# result.append(line)

# return "\n".join(result)


DEFAULT_YAML_CONFIG = __config2yaml(DEFAULT_CONFIG)
49 changes: 37 additions & 12 deletions src/enunu_kor_tool/entry/exe_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ def join_module_name(func_name: str):


MODULE_DICT = {
# "g2pk4utau": {"module": "enunu_kor_tool.g2pk4utau.g2pk4utau", "func": "cli_ui_main"},
# "ustx2lab": {"module": "enunu_kor_tool.entry.ustx2lab", "func": "cli_ui_main"},
# "lab2ntlab": {"module": "enunu_kor_tool.entry.lab2ntlab", "func": "cli_ui_main"},
"analysis4vb": {"module": "enunu_kor_tool.analysis4vb.analysis", "func": "cli_ui_main"},
"g2pk4utau": {"module": "enunu_kor_tool.g2pk4utau.g2pk4utau", "func": "cli_ui_main"},
"ustx2lab": {"module": "enunu_kor_tool.entry.ustx2lab", "func": "cli_ui_main"},
"lab2ntlab": {"module": "enunu_kor_tool.entry.lab2ntlab", "func": "cli_ui_main"},
}


MODULE_LIST = [
# "g2pk4utau",
# "ustx2lab",
# "lab2ntlab",
"analysis4vb",
"g2pk4utau",
"ustx2lab",
"lab2ntlab",
]


MODULE_DESC_LIST = {
# "g2pk4utau",
# "ustx2lab",
# "lab2ntlab",
"analysis4vb": "analysis4vb (ENUNU 통계 모듈)",
"analysis4vb": "analysis4vb (ENUNU 통계)",
"g2pk4utau": "g2pk4utau (한국어 자소 -> 음소 변환기)",
"ustx2lab": "ustx2lab (ustx, ust -> lab 변환기)",
"lab2ntlab": "lab2ntlab (lab 시간 표시 제거)",
}


def main():
def cli_ui_main():
global MODULE_LIST

selected_module = cli_ui.ask_choice("사용할 모듈을 선택하세요.", choices=MODULE_LIST, func_desc=lambda m: MODULE_DESC_LIST[m])
Expand All @@ -46,5 +46,30 @@ def main():
func()


def main():
import os, sys

if len(sys.argv) > 1 and sys.argv[1] == "--gen":
batch_file = (
"@echo off\n"
"\n"
"setlocal\n"
"set TMP=Temp\n"
"set TEMP=Temp\n"
"set MECAB_KO_DIC_PATH=.\enunu_kor_tool\mecab\mecab-ko-dic -r .\enunu_kor_tool\mecab\mecabrc\n"
"enunu_kor_tool\enunu_kor_tool.exe\n"
"endlocal\n"
"\n"
"pause"
)

with open(os.path.join("dist", "Start.bat"), "w", encoding="utf-8") as f:
f.write(batch_file)

return

cli_ui_main()


if __name__ == "__main__":
main()
cli_ui_main()
23 changes: 20 additions & 3 deletions src/enunu_kor_tool/entry/lab2ntlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
from glob import glob


def cli_ui_main():
import cli_ui

print("> 설명: 해당 모듈은 라벨 파일의 음소만 남기고, 시간은 지웁니다.")
print("* TIP: 파일이나 폴더의 경로를 입력할 때, 드래그 & 드롭으로 쉽게 입력할 수 있습니다.")

args = {}

args["input"] = cli_ui.ask_string("단일 lab 파일, 또는 해당 파일이 모여있는 폴더 경로를 입력해주세요.")
args["output"] = cli_ui.ask_string("출력 폴더 경로를 입력해주세요.")

main(args)


def lab2ntlab(path: str, output_path: str):
os.makedirs(output_path, exist_ok=True)

Expand All @@ -26,12 +40,15 @@ def main(args=None):

parser = argparse.ArgumentParser(description="라벨 파일의 음소만 남기고, 시간은 지웁니다.")

parser.add_argument("-i", dest="input", required=True, help="단일 lab 파일, 또는 해당 파일이 모여있는 디렉토리 경로")
parser.add_argument("-o", dest="output", required=True, help="출력 디렉토리 경로")
parser.add_argument("-i", dest="input", required=True, help="단일 lab 파일, 또는 해당 파일이 모여있는 폴더 경로")
parser.add_argument("-o", dest="output", required=True, help="출력 폴더 경로")

args = vars(parser.parse_args())

input_files = glob(os.path.join(args["input"], "*.lab"))
if os.path.isfile(args["input"]):
input_files = [args["input"]]
else:
input_files = glob(os.path.join(args["input"], "*.lab"))

templist = []
for file_fullname in input_files:
Expand Down
27 changes: 22 additions & 5 deletions src/enunu_kor_tool/entry/ustx2lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,36 @@ def ustx2lab(table_filepath: str, input_filepath: str, output_dirpath: str):
f.write("\n".join(lab) + "\n")


def cli_ui_main():
import cli_ui

print("> 설명: 해당 모듈은 UTAU 프로젝트 파일에서 라벨을 자동 생성합니다.")
print("* TIP: 파일이나 폴더의 경로를 입력할 때, 드래그 & 드롭으로 쉽게 입력할 수 있습니다.")

args = {}

args["table"] = cli_ui.ask_string("table 파일 경로를 입력하세요.")
args["input"] = cli_ui.ask_string("단일 Ust 또는 Ustx 파일, 또는 해당 파일이 모여있는 폴더 경로를 입력하세요.")
args["output"] = cli_ui.ask_string("출력 폴더 경로를 입력하세요.")
args["notuse_timeline"] = cli_ui.ask_yes_no("lab 파일의 음소만 출력", default=False)
args["notuse_g2pk4utau"] = cli_ui.ask_yes_no("g2pk4utau 미사용", default=False)

main(args)


def main(args=None):
if not isinstance(args, dict):
import argparse

global USE_G2PK4UTAU, USE_TIMELINE

parser = argparse.ArgumentParser(description="UTAU 프로젝트 파일에서 라벨을 추론합니다.")
parser = argparse.ArgumentParser(description="UTAU 프로젝트 파일에서 라벨을 자동 생성합니다.")

parser.add_argument("-d", dest="table", required=True, help="table 파일 경로")
parser.add_argument("-i", dest="input", required=True, help="단일 Ust 또는 Ustx 파일, 또는 해당 파일이 모여있는 디렉토리 경로")
parser.add_argument("-o", dest="output", required=True, help="출력 디렉토리 경로")
parser.add_argument("--no-time", dest="notuse_timeline", action="store_true", help="시간을 출력하지 않습니다.")
parser.add_argument("--no-g2p", dest="notuse_g2pk4utau", action="store_true", help="g2pk4utau를 사용하지 않습니다.")
parser.add_argument("-i", dest="input", required=True, help="단일 Ust 또는 Ustx 파일, 또는 해당 파일이 모여있는 폴더 경로")
parser.add_argument("-o", dest="output", required=True, help="출력 폴더 경로")
parser.add_argument("--no-time", dest="notuse_timeline", action="store_false", help="시간을 출력하지 않습니다.")
parser.add_argument("--no-g2p", dest="notuse_g2pk4utau", action="store_false", help="g2pk4utau를 사용하지 않습니다.")

args = vars(parser.parse_args())

Expand Down
7 changes: 7 additions & 0 deletions src/enunu_kor_tool/g2pk4utau/g2pk4utau.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ def __call__(
return "\n".join([t[0] for t in text_list]), phn_list, token_phn_list, word_phn_list


def cli_ui_main():
print("> 설명: 해당 모듈은 한국어 자소를 음소로 변환합니다.")
print("* [Ctrl + C]로 종료할 수 있습니다.")

main()


def main():
converter = g2pk4utau()

Expand Down
4 changes: 3 additions & 1 deletion src/enunu_kor_tool/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import colorlog
import tqdm

from enunu_kor_tool import version


def unhandled_exception_hook(exc_type, exc_value, exc_traceback):
if issubclass(exc_type, KeyboardInterrupt):
Expand Down Expand Up @@ -59,7 +61,7 @@ def get_logger(name: Union[str, Callable], logLevel: Union[int, str] = logging.I
module_path = path.split(os.sep)
paths = []
for path_name in reversed(module_path):
if path_name == "enunu_kor_tool":
if path_name == version.package_name:
break
paths.append(path_name)
paths.append(name.__name__)
Expand Down
Loading

0 comments on commit bd92c6b

Please sign in to comment.