Skip to content

Commit

Permalink
openjtalkのパスUTF化に追従する (#14)
Browse files Browse the repository at this point in the history
* open_jtalkを最新コミットに追従

* Revert "windowsのパスシステムでも読み込めるように変更 (#1)"

This reverts commit 8b3d7a6.

* 変更漏れ修正
  • Loading branch information
takana-v authored Sep 11, 2022
1 parent 50b0296 commit f4ade29
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
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)

0 comments on commit f4ade29

Please sign in to comment.