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:
@@ -10,11 +10,8 @@ from config import config
|
|||||||
from style_bert_vits2.logging import logger
|
from style_bert_vits2.logging import logger
|
||||||
from style_bert_vits2.models import commons
|
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 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
|
from style_bert_vits2.utils.stdout_wrapper import SAFE_STDOUT
|
||||||
|
|
||||||
pyopenjtalk.initialize()
|
|
||||||
|
|
||||||
|
|
||||||
def process_line(x):
|
def process_line(x):
|
||||||
line, add_blank = x
|
line, add_blank = x
|
||||||
|
|||||||
@@ -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]]]:
|
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:
|
with open(CACHE_PATH, "rb") as pickle_file:
|
||||||
g2p_dict = pickle.load(pickle_file)
|
g2p_dict = pickle.load(pickle_file)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -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.japanese.normalizer import replace_punctuation
|
||||||
from style_bert_vits2.nlp.symbols import PUNCTUATIONS
|
from style_bert_vits2.nlp.symbols import PUNCTUATIONS
|
||||||
|
|
||||||
pyopenjtalk.initialize()
|
|
||||||
|
|
||||||
|
|
||||||
def g2p(
|
def g2p(
|
||||||
norm_text: str,
|
norm_text: str,
|
||||||
@@ -114,6 +112,9 @@ def text_to_sep_kata(
|
|||||||
tuple[list[str], list[str]]: 分割された単語リストと、その読み(カタカナ or 記号1文字)のリスト
|
tuple[list[str], list[str]]: 分割された単語リストと、その読み(カタカナ or 記号1文字)のリスト
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# pyopenjtalk_worker を初期化
|
||||||
|
pyopenjtalk.initialize()
|
||||||
|
|
||||||
# parsed: OpenJTalkの解析結果
|
# parsed: OpenJTalkの解析結果
|
||||||
parsed = pyopenjtalk.run_frontend(norm_text)
|
parsed = pyopenjtalk.run_frontend(norm_text)
|
||||||
sep_text: list[str] = []
|
sep_text: list[str] = []
|
||||||
|
|||||||
@@ -50,11 +50,11 @@ def unset_user_dict():
|
|||||||
|
|
||||||
|
|
||||||
def initialize(port: int = WORKER_PORT) -> None:
|
def initialize(port: int = WORKER_PORT) -> None:
|
||||||
import time
|
|
||||||
import socket
|
|
||||||
import sys
|
|
||||||
import atexit
|
import atexit
|
||||||
import signal
|
import signal
|
||||||
|
import socket
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
logger.debug("initialize")
|
logger.debug("initialize")
|
||||||
global WORKER_CLIENT
|
global WORKER_CLIENT
|
||||||
@@ -83,7 +83,7 @@ def initialize(port: int = WORKER_PORT) -> None:
|
|||||||
else:
|
else:
|
||||||
# align with Windows behavior
|
# align with Windows behavior
|
||||||
# start_new_session is same as specifying setsid in preexec_fn
|
# 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
|
# wait until server listening
|
||||||
count = 0
|
count = 0
|
||||||
@@ -92,10 +92,10 @@ def initialize(port: int = WORKER_PORT) -> None:
|
|||||||
client = WorkerClient(port)
|
client = WorkerClient(port)
|
||||||
break
|
break
|
||||||
except socket.error:
|
except socket.error:
|
||||||
time.sleep(1)
|
time.sleep(0.5)
|
||||||
count += 1
|
count += 1
|
||||||
# 10: max number of retries
|
# 20: max number of retries
|
||||||
if count == 10:
|
if count == 20:
|
||||||
raise TimeoutError("サーバーに接続できませんでした")
|
raise TimeoutError("サーバーに接続できませんでした")
|
||||||
|
|
||||||
WORKER_CLIENT = client
|
WORKER_CLIENT = client
|
||||||
|
|||||||
@@ -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.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
|
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()
|
# root_dir = engine_root()
|
||||||
# save_dir = get_save_dir()
|
# save_dir = get_save_dir()
|
||||||
|
|
||||||
@@ -81,6 +79,11 @@ def update_dict(
|
|||||||
compiled_dict_path : Path
|
compiled_dict_path : Path
|
||||||
コンパイル済み辞書ファイルのパス
|
コンパイル済み辞書ファイルのパス
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# pyopenjtalk_worker を初期化
|
||||||
|
# ファイルを開く前に実行する必要がある
|
||||||
|
pyopenjtalk.initialize()
|
||||||
|
|
||||||
random_string = uuid4()
|
random_string = uuid4()
|
||||||
tmp_csv_path = compiled_dict_path.with_suffix(
|
tmp_csv_path = compiled_dict_path.with_suffix(
|
||||||
f".dict_csv-{random_string}.tmp"
|
f".dict_csv-{random_string}.tmp"
|
||||||
|
|||||||
Reference in New Issue
Block a user