Fix: import error

pyopenjtalk_worker.initialize() has the side effect of starting another process and should not be executed automatically on import.
This commit is contained in:
tsukumi
2024-03-08 07:31:33 +00:00
parent 75467936d9
commit 5de4884075
5 changed files with 16 additions and 15 deletions

View File

@@ -10,11 +10,8 @@ from config import config
from style_bert_vits2.logging import logger
from style_bert_vits2.models import commons
from style_bert_vits2.nlp import cleaned_text_to_sequence, extract_bert_feature
from style_bert_vits2.nlp.japanese import pyopenjtalk_worker as pyopenjtalk
from style_bert_vits2.utils.stdout_wrapper import SAFE_STDOUT
pyopenjtalk.initialize()
def process_line(x):
line, add_blank = x

View File

@@ -273,7 +273,7 @@ def __cache_dict(g2p_dict: dict[str, list[list[str]]], file_path: Path) -> None:
def __get_dict() -> dict[str, list[list[str]]]:
if os.path.exists(CACHE_PATH):
if CACHE_PATH.exists():
with open(CACHE_PATH, "rb") as pickle_file:
g2p_dict = pickle.load(pickle_file)
else:

View File

@@ -8,8 +8,6 @@ from style_bert_vits2.nlp.japanese.mora_list import MORA_KATA_TO_MORA_PHONEMES
from style_bert_vits2.nlp.japanese.normalizer import replace_punctuation
from style_bert_vits2.nlp.symbols import PUNCTUATIONS
pyopenjtalk.initialize()
def g2p(
norm_text: str,
@@ -114,6 +112,9 @@ def text_to_sep_kata(
tuple[list[str], list[str]]: 分割された単語リストと、その読み(カタカナ or 記号1文字のリスト
"""
# pyopenjtalk_worker を初期化
pyopenjtalk.initialize()
# parsed: OpenJTalkの解析結果
parsed = pyopenjtalk.run_frontend(norm_text)
sep_text: list[str] = []

View File

@@ -50,11 +50,11 @@ def unset_user_dict():
def initialize(port: int = WORKER_PORT) -> None:
import time
import socket
import sys
import atexit
import signal
import socket
import sys
import time
logger.debug("initialize")
global WORKER_CLIENT
@@ -83,7 +83,7 @@ def initialize(port: int = WORKER_PORT) -> None:
else:
# align with Windows behavior
# start_new_session is same as specifying setsid in preexec_fn
subprocess.Popen(args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True) # type: ignore
subprocess.Popen(args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True)
# wait until server listening
count = 0
@@ -92,10 +92,10 @@ def initialize(port: int = WORKER_PORT) -> None:
client = WorkerClient(port)
break
except socket.error:
time.sleep(1)
time.sleep(0.5)
count += 1
# 10: max number of retries
if count == 10:
# 20: max number of retries
if count == 20:
raise TimeoutError("サーバーに接続できませんでした")
WORKER_CLIENT = client

View File

@@ -20,8 +20,6 @@ from style_bert_vits2.nlp.japanese import pyopenjtalk_worker as pyopenjtalk
from style_bert_vits2.nlp.japanese.user_dict.word_model import UserDictWord, WordTypes
from style_bert_vits2.nlp.japanese.user_dict.part_of_speech_data import MAX_PRIORITY, MIN_PRIORITY, part_of_speech_data
pyopenjtalk.initialize()
# root_dir = engine_root()
# save_dir = get_save_dir()
@@ -81,6 +79,11 @@ def update_dict(
compiled_dict_path : Path
コンパイル済み辞書ファイルのパス
"""
# pyopenjtalk_worker を初期化
# ファイルを開く前に実行する必要がある
pyopenjtalk.initialize()
random_string = uuid4()
tmp_csv_path = compiled_dict_path.with_suffix(
f".dict_csv-{random_string}.tmp"