Skip to content

Commit

Permalink
Merge branch 'master' of github.com:VOICEVOX/pyopenjtalk
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukumijima committed Jul 29, 2024
2 parents c1bd455 + b35fc89 commit a1f5693
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "lib/open_jtalk"]
path = lib/open_jtalk
url = https://github.com/r9y9/open_jtalk.git
url = https://github.com/tsukumijima/open_jtalk.git
[submodule "lib/hts_engine_API"]
path = lib/hts_engine_API
url = https://github.com/syoyo/hts_engine_API.git
12 changes: 10 additions & 2 deletions pyopenjtalk/openjtalk.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# cython: boundscheck=True, wraparound=True
# cython: c_string_type=unicode, c_string_encoding=ascii

import errno
import numpy as np

cimport numpy as np
Expand Down Expand Up @@ -192,10 +193,17 @@ cdef class OpenJTalk(object):
"""Run OpenJTalk's text processing frontend
"""
cdef char buff[8192]

if isinstance(text, str):
text = text.encode("utf-8")
text2mecab(buff, text)

cdef int result = text2mecab(buff, 8192, text)
if result != 0:
if result == errno.ERANGE:
raise RuntimeError("Text is too long")
if result == errno.EINVAL:
raise RuntimeError("Invalid input for text2mecab")
raise RuntimeError("Unknown error: " + str(result))

Mecab_analysis(self.mecab, buff)
mecab2njd(self.njd, Mecab_get_feature(self.mecab), Mecab_get_size(self.mecab))
_njd.njd_set_pronunciation(self.njd)
Expand Down
2 changes: 1 addition & 1 deletion pyopenjtalk/openjtalk/text2mecab.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# distutils: language = c++

cdef extern from "text2mecab.h":
void text2mecab(char *output, const char *input)
int text2mecab(char *output, size_t sizeOfOutput, const char *input)

0 comments on commit a1f5693

Please sign in to comment.