Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openjtalkのパスUTF化に追従する #14

Merged
merged 3 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/open_jtalk
24 changes: 9 additions & 15 deletions pyopenjtalk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,22 @@
except ImportError:
raise ImportError("BUG: version.py doesn't exist. Please file a bug report.")

import locale

from .htsengine import HTSEngine
from .openjtalk import CreateUserDict, OpenJTalk

path_encoding = locale.getpreferredencoding()

path_encoding = locale.getpreferredencoding()

# Dictionary directory
# defaults to the package directory where the dictionary will be automatically downloaded
OPEN_JTALK_DICT_DIR = os.environ.get(
"OPEN_JTALK_DICT_DIR",
pkg_resources.resource_filename(__name__, "open_jtalk_dic_utf_8-1.11"),
)
).encode("utf-8")
_dict_download_url = "https://github.com/r9y9/open_jtalk/releases/download/v1.11.1"
_DICT_URL = f"{_dict_download_url}/open_jtalk_dic_utf_8-1.11.tar.gz"

# Default mei_normal.voice for HMM-based TTS
DEFAULT_HTS_VOICE = pkg_resources.resource_filename(
__name__, "htsvoice/mei_normal.htsvoice"
)
).encode("utf-8")

# Global instance of OpenJTalk
_global_jtalk = None
Expand Down Expand Up @@ -73,7 +67,7 @@ def _extract_dic():
f.extractall(path=pkg_resources.resource_filename(__name__, ""))
OPEN_JTALK_DICT_DIR = pkg_resources.resource_filename(
__name__, "open_jtalk_dic_utf_8-1.11"
)
).encode("utf-8")
os.remove(filename)


Expand All @@ -100,7 +94,7 @@ def g2p(*args, **kwargs):
global _global_jtalk
if _global_jtalk is None:
_lazy_init()
_global_jtalk = OpenJTalk(dn_mecab=OPEN_JTALK_DICT_DIR.encode(path_encoding))
_global_jtalk = OpenJTalk(dn_mecab=OPEN_JTALK_DICT_DIR)
return _global_jtalk.g2p(*args, **kwargs)


Expand Down Expand Up @@ -135,7 +129,7 @@ def synthesize(labels, speed=1.0, half_tone=0.0):

global _global_htsengine
if _global_htsengine is None:
_global_htsengine = HTSEngine(DEFAULT_HTS_VOICE.encode(path_encoding))
_global_htsengine = HTSEngine(DEFAULT_HTS_VOICE)
sr = _global_htsengine.get_sampling_frequency()
_global_htsengine.set_speed(speed)
_global_htsengine.add_half_tone(half_tone)
Expand Down Expand Up @@ -171,7 +165,7 @@ def run_frontend(text, verbose=0):
global _global_jtalk
if _global_jtalk is None:
_lazy_init()
_global_jtalk = OpenJTalk(dn_mecab=OPEN_JTALK_DICT_DIR.encode(path_encoding))
_global_jtalk = OpenJTalk(dn_mecab=OPEN_JTALK_DICT_DIR)
return _global_jtalk.run_frontend(text, verbose)


Expand All @@ -187,7 +181,7 @@ def create_user_dict(path, out_path):
_lazy_init()
if not exists(path):
raise ValueError("no such file or directory: %s" % path)
CreateUserDict(OPEN_JTALK_DICT_DIR.encode(path_encoding), path.encode(path_encoding), out_path.encode(path_encoding))
CreateUserDict(OPEN_JTALK_DICT_DIR, path.encode("utf-8"), out_path.encode("utf-8"))


def set_user_dict(path):
Expand All @@ -202,7 +196,7 @@ def set_user_dict(path):
if not exists(path):
raise ValueError("no such file or directory: %s" % path)
_global_jtalk = OpenJTalk(
dn_mecab=OPEN_JTALK_DICT_DIR.encode(path_encoding), user_mecab=path.encode(path_encoding)
dn_mecab=OPEN_JTALK_DICT_DIR, user_mecab=path.encode("utf-8")
)


Expand All @@ -211,4 +205,4 @@ def unset_user_dict():
global _global_jtalk
if _global_jtalk is None:
_lazy_init()
_global_jtalk = OpenJTalk(dn_mecab=OPEN_JTALK_DICT_DIR.encode(path_encoding))
_global_jtalk = OpenJTalk(dn_mecab=OPEN_JTALK_DICT_DIR)