Skip to content

Conversation

Hiroshiba
Copy link

If the path contains Japanese in windows, mecab_load will give an error.

OPEN_JTALK_DICT_DIR='C:\Users\hihok\Downloads\日本語!\open_jtalk_dic_utf_8-1.11' \
python -c 'im port pyopenjtalk; pyopenjtalk.tts("ほげ")'
ERROR: Mecab_load() in mecab.cpp: Cannot open C:\Users\hihok\Downloads\譌・譛ャ隱橸シ―open_jtalk_dic_utf_8-1.11.

After a lot of testing, it seems that mecab_load is expecting a shift-jis binary sequence.
I'm guessing from the fact that it worked fine with .encode set to shift-jis.
I haven't been able to follow the code in detail, so I don't know the details.

I didn't know how to find out what charset the system path expects, but using locale.getpreferredencoding() seemed to be a good idea.
https://docs.python.org/ja/3/library/locale.html#locale.getpreferredencoding

I have confirmed that it works fine in windows.

@r9y9
Copy link
Owner

r9y9 commented Aug 15, 2021

If I understand correctly, mecab should use UTF-8 character encoding.

("CHARSET_UTF_8", None),

Perhaps you might have built mecab by yourself or added config.h without running cmake though setup.py?

@Hiroshiba
Copy link
Author

I see, it is set to be processed in UTF-8....

What I did was pip install with the commit ID of this pull request.
git+https://github.com/Hiroshiba/pyopenjtalk@69e5f354634f98098113f9cac5a6ea736443f9c9.

Possibly, the charset of the path and the one mecab uses for input/output are different...?
But it looks like the MSVC compiler is specifying UTF-8.

pyopenjtalk/setup.py

Lines 31 to 34 in 60ea4df

msvc_extra_compile_args_config = [
"/source-charset:utf-8",
"/execution-charset:utf-8",
]

I would like to ask another person to verify this because I am losing confidence.

@r9y9
Copy link
Owner

r9y9 commented Aug 15, 2021

Umm, maybe @oocytanb can help? I am afraid I don't have a windows machine to investigate the issue.

@oocytanb
Copy link
Contributor

Please excuse me for writing in Japanese

日本語で失礼します。

MSVC のコンパイラーオプションは、Windowsでビルドできるように、追加したものです。
もともと CHARSET_UTF_8 が指定されていたので、MSVC のコンパイラーオプションにも、
UTF8 を指定すればよいだろうと考え、それでビルドできたので、満足してしまっていました。
必要であれば是非、修正されてくださいませ。

@oocytanb
Copy link
Contributor

MeCab のコードを見たところ、ファイルを開くところでは、WPATH マクロを通していますね。
WPATH マクロの定義部分では、Windows では パス文字列を UTF8 から変換するコードが、
コメントで書いてありました。
もしかすると、これを使えば、MeCab に関しては、パス文字列を UTF8 固定で渡して、
うまく処理できるかもしれませんね。
ご参考までに。
https://github.com/oocytanb/open_jtalk/commit/2bb20a13ade8c98948adf1df8844f2ff1ca13d2c

@Hiroshiba
Copy link
Author

Ah, how about adding a test that reads the mecab dictionary in the Japanese directory?

@r9y9
Copy link
Owner

r9y9 commented Aug 17, 2021

僕は癖で、すべてのGithubレポジトリで英語で書いてますが、日本語関連のリポジトリでは日本語でもちろんかまいません。

日本語を含むディレクトリに関するテストは、追加していただくのが良いと思います。
現在の修正は、根本的な原因は不明瞭なままで、ひとまず動くworkaroundを見つけた、という修正のように思えるので、原因を特定した上で、妥当だと思える修正をしていただけると嬉しいです。僕はWindowsマシンがなく、原因追求の手助けをできないのは申し訳ありませんが…。検討よろしくお願いします。

@Hiroshiba
Copy link
Author

なるほどです。
自分がほしかったのはworkaroundだったのと、今回のプルリクエストの意図から外れそうなのでこのプルリクエストは閉じたいと思います。

せっかくの議論が探しづらくなるのは勿体ないので、ひとまずissueを立ててこのページを参照するのはどうでしょう。

@r9y9
Copy link
Owner

r9y9 commented Aug 18, 2021

はい、それで問題ないと思います。

@Hiroshiba
Copy link
Author

#18

@Hiroshiba Hiroshiba closed this Aug 18, 2021
@Hiroshiba Hiroshiba deleted the add-path-encoding branch August 18, 2021 16:25
@r9y9 r9y9 linked an issue Aug 19, 2021 that may be closed by this pull request
@Hiroshiba Hiroshiba restored the add-path-encoding branch August 20, 2021 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

If the path contains Japanese in windows, mecab_load will give an error.
3 participants