From bcfa63a2b722f6ccd08d1aa725b40669373bdf78 Mon Sep 17 00:00:00 2001 From: synodriver <624805065@qq.com> Date: Fri, 12 Aug 2022 09:19:29 +0000 Subject: [PATCH 1/7] fix macox build --- pyopenjtalk/htsengine.pyx | 4 ++-- pyopenjtalk/openjtalk.pyx | 2 +- setup.py | 27 +++++++++++++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/pyopenjtalk/htsengine.pyx b/pyopenjtalk/htsengine.pyx index 868c07a..cdc6018 100644 --- a/pyopenjtalk/htsengine.pyx +++ b/pyopenjtalk/htsengine.pyx @@ -117,9 +117,9 @@ cdef class HTSEngine: cdef size_t nsamples = HTS_Engine_get_nsamples(self.engine) cdef np.ndarray[np.float64_t, ndim=1] speech = np.zeros([nsamples], dtype=np.float64) cdef double[::1] speech_view = speech - cdef size_t index + cdef int index for index in prange(nsamples, nogil=True): - speech_view[index] = HTS_Engine_get_generated_speech(self.engine, index) + speech_view[index] = HTS_Engine_get_generated_speech(self.engine, index) return speech cpdef inline str get_fullcontext_label_format(self): diff --git a/pyopenjtalk/openjtalk.pyx b/pyopenjtalk/openjtalk.pyx index 1ef7923..4f37112 100644 --- a/pyopenjtalk/openjtalk.pyx +++ b/pyopenjtalk/openjtalk.pyx @@ -1,6 +1,6 @@ # coding: utf-8 # cython: language_level=3 -# cython: boundscheck=False, wraparound=False +# cython: boundscheck=False, wraparound=True # cython: c_string_type=unicode, c_string_encoding=ascii, cdivision=True from libc.stdint cimport uint8_t diff --git a/setup.py b/setup.py index 971a08b..6308e10 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ import os import subprocess import sys +import platform from distutils.errors import DistutilsExecError from distutils.spawn import spawn from distutils.version import LooseVersion @@ -70,6 +71,24 @@ def build_extensions(self): if not os.path.exists(join("pyopenjtalk", "openjtalk" + ext)): raise RuntimeError("Cython is required to generate C++ code") +# make openmp available +system = platform.system() +if system == "Windows": + extra_compile_args = [] + extra_link_args = ['/openmp'] +elif system == "Linux": + extra_compile_args = ['-fopenmp'] + extra_link_args = ['-fopenmp'] +elif system == "Darwin": + os.system("brew install llvm libomp") + os.system("brew install clang-omp") + # os.environ["CPP"] = "/usr/local/opt/llvm/bin/clang" + extra_compile_args = [] + extra_link_args = [] +else: + extra_compile_args = ['-fopenmp'] + extra_link_args = ['-fopenmp'] + # Workaround for `distutils.spawn` problem on Windows python < 3.9 # See details: [bpo-39763: distutils.spawn now uses subprocess (GH-18743)] @@ -180,8 +199,8 @@ def escape_macros(macros): name="pyopenjtalk.openjtalk", sources=[join("pyopenjtalk", "openjtalk" + ext)] + all_src, include_dirs=[np.get_include()] + include_dirs, - extra_compile_args=['-fopenmp'], - extra_link_args=['-fopenmp'], + extra_compile_args=extra_compile_args, + extra_link_args=extra_link_args, language="c++", define_macros=custom_define_macros( [ @@ -204,8 +223,8 @@ def escape_macros(macros): name="pyopenjtalk.htsengine", sources=[join("pyopenjtalk", "htsengine" + ext)] + all_htsengine_src, include_dirs=[np.get_include(), join(htsengine_src_top, "include")], - extra_compile_args=['-fopenmp'], - extra_link_args=['-fopenmp'], + extra_compile_args=extra_compile_args, + extra_link_args=extra_link_args, libraries=["winmm"] if platform_is_windows else [], language="c++", define_macros=custom_define_macros( From b3de8752bc13593b1a2c634c023c117cae6e6301 Mon Sep 17 00:00:00 2001 From: fumiama <41315874+fumiama@users.noreply.github.com> Date: Fri, 12 Aug 2022 21:02:58 +0800 Subject: [PATCH 2/7] fix args --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 3eaab0a..36fae85 100644 --- a/setup.py +++ b/setup.py @@ -93,8 +93,8 @@ def build_extensions(self): extra_compile_args = ['-fopenmp'] extra_link_args = ['-fopenmp'] elif system == "Darwin": - os.system("brew install libomp") - extra_compile_args = ['-Xpreprocessor -fopenmp'] + os.system('brew install libomp') + extra_compile_args = ['-Xpreprocessor', '-fopenmp'] extra_link_args = ['-lomp'] else: extra_compile_args = ['-fopenmp'] From acbebe5bb78107a0ded15a21a5933e7bf7974bf4 Mon Sep 17 00:00:00 2001 From: fumiama <41315874+fumiama@users.noreply.github.com> Date: Fri, 12 Aug 2022 21:03:48 +0800 Subject: [PATCH 3/7] add ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4d3b0cb..8b2bc54 100644 --- a/.gitignore +++ b/.gitignore @@ -194,3 +194,4 @@ Temporary Items # Linux trash folder which might appear on any partition or disk .Trash-* +dic.tar.gz From a342129e6e4c65718c0a210a04e479b05b012efb Mon Sep 17 00:00:00 2001 From: fumiama <41315874+fumiama@users.noreply.github.com> Date: Fri, 12 Aug 2022 21:07:22 +0800 Subject: [PATCH 4/7] add link arg --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 36fae85..ecb4117 100644 --- a/setup.py +++ b/setup.py @@ -95,7 +95,7 @@ def build_extensions(self): elif system == "Darwin": os.system('brew install libomp') extra_compile_args = ['-Xpreprocessor', '-fopenmp'] - extra_link_args = ['-lomp'] + extra_link_args = ['-L/usr/local/lib', '-lomp'] else: extra_compile_args = ['-fopenmp'] extra_link_args = ['-fopenmp'] @@ -176,7 +176,7 @@ def update_to(self, b=1, bsize=1, tsize=None): self.total = tsize return self.update(b * bsize - self.n) - +""" # extract dic filename = "dic.tar.gz" print('Downloading: "{}"'.format(_DICT_URL)) @@ -193,7 +193,7 @@ def update_to(self, b=1, bsize=1, tsize=None): with tarfile.open(filename, mode="r|gz") as f: f.extractall(path="./") os.remove(filename) - +""" # generate config.h for mecab # NOTE: need to run cmake to generate config.h @@ -329,7 +329,7 @@ def run(self): url="https://github.com/r9y9/pyopenjtalk", license="MIT", packages=find_packages(), - package_data={"": ["htsvoice/*", f"{_dict_folder_name}/*"]}, + package_data={"": ["htsvoice/*"]}, ext_modules=ext_modules, cmdclass=cmdclass, install_requires=[ From 13d1d4bbb5f5a7e34606bcebdb47ac349e377a07 Mon Sep 17 00:00:00 2001 From: fumiama <41315874+fumiama@users.noreply.github.com> Date: Fri, 12 Aug 2022 21:25:14 +0800 Subject: [PATCH 5/7] r --- setup.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.py b/setup.py index ecb4117..ec27e14 100644 --- a/setup.py +++ b/setup.py @@ -176,7 +176,6 @@ def update_to(self, b=1, bsize=1, tsize=None): self.total = tsize return self.update(b * bsize - self.n) -""" # extract dic filename = "dic.tar.gz" print('Downloading: "{}"'.format(_DICT_URL)) @@ -193,7 +192,6 @@ def update_to(self, b=1, bsize=1, tsize=None): with tarfile.open(filename, mode="r|gz") as f: f.extractall(path="./") os.remove(filename) -""" # generate config.h for mecab # NOTE: need to run cmake to generate config.h From 1fc6f63a40cb06ccf32ae6ee58ca5a43ad2f5fdd Mon Sep 17 00:00:00 2001 From: fumiama <41315874+fumiama@users.noreply.github.com> Date: Fri, 12 Aug 2022 21:26:08 +0800 Subject: [PATCH 6/7] eee --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ec27e14..3f26a8a 100644 --- a/setup.py +++ b/setup.py @@ -327,7 +327,7 @@ def run(self): url="https://github.com/r9y9/pyopenjtalk", license="MIT", packages=find_packages(), - package_data={"": ["htsvoice/*"]}, + package_data={"": ["htsvoice/*", f"{_dict_folder_name}/*"]}, ext_modules=ext_modules, cmdclass=cmdclass, install_requires=[ From 1c493f5ef4c56c7b93086f4a3153c72a143fdd91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Fri, 12 Aug 2022 21:27:26 +0800 Subject: [PATCH 7/7] Update setup.py --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index 3f26a8a..b7d109d 100644 --- a/setup.py +++ b/setup.py @@ -176,6 +176,7 @@ def update_to(self, b=1, bsize=1, tsize=None): self.total = tsize return self.update(b * bsize - self.n) + # extract dic filename = "dic.tar.gz" print('Downloading: "{}"'.format(_DICT_URL)) @@ -193,6 +194,7 @@ def update_to(self, b=1, bsize=1, tsize=None): f.extractall(path="./") os.remove(filename) + # generate config.h for mecab # NOTE: need to run cmake to generate config.h # we could do it on python side but it would be very tricky,