diff --git a/pyopenjtalk/__init__.py b/pyopenjtalk/__init__.py index a266104..7b83da1 100644 --- a/pyopenjtalk/__init__.py +++ b/pyopenjtalk/__init__.py @@ -13,12 +13,12 @@ import tarfile try: - from .version import __version__ # NOQA + from pyopenjtalk.version import __version__ # NOQA except ImportError: raise ImportError("BUG: version.py doesn't exist. Please file a bug report.") -from .htsengine import HTSEngine -from .openjtalk import OpenJTalk +from pyopenjtalk.htsengine import HTSEngine +from pyopenjtalk.openjtalk import OpenJTalk # Dictionary directory # defaults to the package directory where the dictionary will be automatically downloaded diff --git a/pyopenjtalk/htsengine.pyx b/pyopenjtalk/htsengine.pyx index cdc6018..b30e813 100644 --- a/pyopenjtalk/htsengine.pyx +++ b/pyopenjtalk/htsengine.pyx @@ -6,21 +6,23 @@ import numpy as np cimport numpy as np + np.import_array() cimport cython +from cpython.mem cimport PyMem_Free, PyMem_Malloc from cython.parallel cimport prange -from cpython.mem cimport PyMem_Malloc, PyMem_Free from libc.stdint cimport uint8_t -from pyopenjtalk.htsengine cimport HTS_Engine -from pyopenjtalk.htsengine cimport ( - HTS_Engine_initialize, HTS_Engine_load, HTS_Engine_clear, HTS_Engine_refresh, - HTS_Engine_get_sampling_frequency, HTS_Engine_get_fperiod, - HTS_Engine_set_speed, HTS_Engine_add_half_tone, - HTS_Engine_synthesize_from_strings, - HTS_Engine_get_generated_speech, HTS_Engine_get_nsamples -) +from pyopenjtalk.htsengine cimport (HTS_Engine, HTS_Engine_add_half_tone, + HTS_Engine_clear, HTS_Engine_get_fperiod, + HTS_Engine_get_generated_speech, + HTS_Engine_get_nsamples, + HTS_Engine_get_sampling_frequency, + HTS_Engine_initialize, HTS_Engine_load, + HTS_Engine_refresh, HTS_Engine_set_speed, + HTS_Engine_synthesize_from_strings) + @cython.final @cython.no_gc diff --git a/pyopenjtalk/openjtalk.pyx b/pyopenjtalk/openjtalk.pyx index 4f37112..eda7ae1 100644 --- a/pyopenjtalk/openjtalk.pyx +++ b/pyopenjtalk/openjtalk.pyx @@ -4,25 +4,34 @@ # cython: c_string_type=unicode, c_string_encoding=ascii, cdivision=True from libc.stdint cimport uint8_t + import numpy as np cimport numpy as np + np.import_array() cimport cython from cpython.bytes cimport PyBytes_AS_STRING -from pyopenjtalk.openjtalk.mecab cimport Mecab, Mecab_initialize, Mecab_load, Mecab_analysis -from pyopenjtalk.openjtalk.mecab cimport Mecab_get_feature, Mecab_get_size, Mecab_refresh, Mecab_clear -from pyopenjtalk.openjtalk.njd cimport NJD, NJD_initialize, NJD_refresh, NJD_print, NJD_clear from pyopenjtalk.openjtalk cimport njd as _njd -from pyopenjtalk.openjtalk.jpcommon cimport JPCommon, JPCommon_initialize,JPCommon_make_label -from pyopenjtalk.openjtalk.jpcommon cimport JPCommon_get_label_size, JPCommon_get_label_feature -from pyopenjtalk.openjtalk.jpcommon cimport JPCommon_refresh, JPCommon_clear from pyopenjtalk.openjtalk cimport njd2jpcommon -from pyopenjtalk.openjtalk.text2mecab cimport text2mecab +from pyopenjtalk.openjtalk.jpcommon cimport (JPCommon, JPCommon_clear, + JPCommon_get_label_feature, + JPCommon_get_label_size, + JPCommon_initialize, + JPCommon_make_label, + JPCommon_refresh) +from pyopenjtalk.openjtalk.mecab cimport (Mecab, Mecab_analysis, Mecab_clear, + Mecab_get_feature, Mecab_get_size, + Mecab_initialize, Mecab_load, + Mecab_refresh) from pyopenjtalk.openjtalk.mecab2njd cimport mecab2njd +from pyopenjtalk.openjtalk.njd cimport (NJD, NJD_clear, NJD_initialize, + NJD_print, NJD_refresh) from pyopenjtalk.openjtalk.njd2jpcommon cimport njd2jpcommon +from pyopenjtalk.openjtalk.text2mecab cimport text2mecab + cdef inline str njd_node_get_string(_njd.NJDNode* node): return ((_njd.NJDNode_get_string(node))).decode("utf-8") diff --git a/pyopenjtalk/openjtalk/jpcommon.pxd b/pyopenjtalk/openjtalk/jpcommon.pxd index 2dd450a..3667d1e 100644 --- a/pyopenjtalk/openjtalk/jpcommon.pxd +++ b/pyopenjtalk/openjtalk/jpcommon.pxd @@ -3,6 +3,7 @@ from libc.stdio cimport FILE + cdef extern from "jpcommon.h" nogil: cdef cppclass JPCommonNode: char *pron diff --git a/pyopenjtalk/openjtalk/mecab2njd.pxd b/pyopenjtalk/openjtalk/mecab2njd.pxd index d8fb8c4..f42d3ec 100644 --- a/pyopenjtalk/openjtalk/mecab2njd.pxd +++ b/pyopenjtalk/openjtalk/mecab2njd.pxd @@ -1,7 +1,8 @@ # distutils: language = c++ # cython: language_level=3 -from .njd cimport NJD +from pyopenjtalk.openjtalk.njd cimport NJD + cdef extern from "mecab2njd.h" nogil: void mecab2njd(NJD * njd, char **feature, int size); diff --git a/pyopenjtalk/openjtalk/njd.pxd b/pyopenjtalk/openjtalk/njd.pxd index abc1f2d..ef2b8b3 100644 --- a/pyopenjtalk/openjtalk/njd.pxd +++ b/pyopenjtalk/openjtalk/njd.pxd @@ -3,6 +3,7 @@ from libc.stdio cimport FILE + cdef extern from "njd.h" nogil: cdef cppclass NJDNode: char *string diff --git a/pyopenjtalk/openjtalk/njd2jpcommon.pxd b/pyopenjtalk/openjtalk/njd2jpcommon.pxd index 680aadf..a803032 100644 --- a/pyopenjtalk/openjtalk/njd2jpcommon.pxd +++ b/pyopenjtalk/openjtalk/njd2jpcommon.pxd @@ -1,8 +1,9 @@ # distutils: language = c++ # cython: language_level=3 -from .jpcommon cimport JPCommon -from .njd cimport NJD +from pyopenjtalk.openjtalk.jpcommon cimport JPCommon +from pyopenjtalk.openjtalk.njd cimport NJD + cdef extern from "njd2jpcommon.h" nogil: void njd2jpcommon(JPCommon * jpcommon, NJD * njd) diff --git a/setup.py b/setup.py index f6c51ff..700e4b8 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,8 @@ import os -import subprocess -import sys import platform import shutil +import subprocess +import sys from distutils.errors import DistutilsExecError from distutils.spawn import spawn from distutils.version import LooseVersion @@ -14,15 +14,15 @@ import numpy as np import setuptools.command.build_py import setuptools.command.develop +import six from setuptools import Extension, find_packages, setup -import six if six.PY2: from urllib import urlretrieve else: from urllib.request import urlretrieve -import tarfile +import tarfile platform_is_windows = sys.platform == "win32" @@ -88,10 +88,10 @@ def build_extensions(self): system = platform.system() if system == "Windows": extra_compile_args = [] - extra_link_args = ['/openmp'] + extra_link_args = ["/openmp"] elif system == "Linux": - extra_compile_args = ['-fopenmp'] - extra_link_args = ['-fopenmp'] + extra_compile_args = ["-fopenmp"] + extra_link_args = ["-fopenmp"] elif system == "Darwin": os.system("brew install llvm libomp") os.system("brew install clang-omp") @@ -99,8 +99,8 @@ def build_extensions(self): extra_compile_args = ["-Xpreprocessor", "-fopenmp"] extra_link_args = ["-Xpreprocessor", "-fopenmp"] else: - extra_compile_args = ['-fopenmp'] - extra_link_args = ['-fopenmp'] + extra_compile_args = ["-fopenmp"] + extra_link_args = ["-fopenmp"] # Workaround for `distutils.spawn` problem on Windows python < 3.9 @@ -171,7 +171,6 @@ def escape_macros(macros): src_top = join("lib", "open_jtalk", "src") - # extract dic filename = "dic.tar.gz" print(f"Downloading: {_DICT_URL}")