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() + } } }