From c509263f4c67cc7cf25f503d96e7970b7dbcaffc Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Fri, 26 Jan 2024 22:21:44 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=E7=A9=BA=E3=81=AE=E8=BE=9E=E6=9B=B8?= =?UTF-8?q?=E3=81=A7=E3=82=AF=E3=83=A9=E3=83=83=E3=82=B7=E3=83=A5=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core/src/engine/open_jtalk.rs | 11 ++++++++++- crates/voicevox_core/src/user_dict/dict.rs | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/voicevox_core/src/engine/open_jtalk.rs b/crates/voicevox_core/src/engine/open_jtalk.rs index ad1f8c19e..de3fd73dc 100644 --- a/crates/voicevox_core/src/engine/open_jtalk.rs +++ b/crates/voicevox_core/src/engine/open_jtalk.rs @@ -128,7 +128,13 @@ pub(crate) mod blocking { } impl Inner { - // FIXME: 中断可能にする + // TODO: 中断可能にする + pub(super) fn unload_user_dict(&self) -> crate::result::Result<()> { + let Resources { mecab, .. } = &mut *self.resources.lock().unwrap(); + mecab.load_with_userdic(&self.dict_dir, None) + } + + // TODO: 中断可能にする pub(super) fn use_user_dict(&self, words: &str) -> crate::result::Result<()> { let result = { // ユーザー辞書用のcsvを作成 @@ -210,6 +216,9 @@ pub(crate) mod tokio { user_dict: &crate::tokio::UserDict, ) -> crate::result::Result<()> { let inner = self.0 .0.clone(); + if user_dict.is_empty() { + return crate::task::asyncify(move || inner.unload_user_dict()).await; + } let words = user_dict.to_mecab_format(); crate::task::asyncify(move || inner.use_user_dict(&words)).await } diff --git a/crates/voicevox_core/src/user_dict/dict.rs b/crates/voicevox_core/src/user_dict/dict.rs index 6997620f0..3ac5c9a39 100644 --- a/crates/voicevox_core/src/user_dict/dict.rs +++ b/crates/voicevox_core/src/user_dict/dict.rs @@ -99,6 +99,11 @@ pub(crate) mod blocking { "\n", ) } + + /// ユーザー辞書が空かどうかを返す。 + pub(crate) fn is_empty(&self) -> bool { + self.words.lock().unwrap().is_empty() + } } } @@ -174,5 +179,10 @@ pub(crate) mod tokio { pub(crate) fn to_mecab_format(&self) -> String { self.0.to_mecab_format() } + + /// ユーザー辞書が空かどうかを返す。 + pub(crate) fn is_empty(&self) -> bool { + self.0.is_empty() + } } }