Skip to content

Commit

Permalink
Fix: 空辞書を読めるように
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Nov 22, 2023
1 parent 1042543 commit 8983d9b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/icon_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl IconManager {
root
};

info!("{} root: {}", speaker.internal_name(), root);
info!("{} root: {:?}", speaker.internal_name(), root);

let mut portraits = StyleImages {
normal: Vec::new(),
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ async fn main_impl(args: Cli) -> Result<()> {
{
let open_jtalk = OPEN_JTALK.lock().await;
let user_dict = USER_DICT.lock().await;
info!("Loading OpenJTalk dictionary...");
open_jtalk.use_user_dict(&user_dict)?;
}
info!("Listening on port {}", port);
Expand Down
13 changes: 11 additions & 2 deletions src/voicevox/open_jtalk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ impl OpenJtalk {
.and_then(|dict_dir| dict_dir.to_str())
.ok_or_else(|| OpenJtalkError::UseUserDict("辞書が読み込まれていません".to_string()))?;

let Resources { mecab, .. } = &mut *self.resources.lock().unwrap();

if user_dict.words().is_empty() {
let result = mecab.load_with_userdic(Path::new(dict_dir), None);
if !result {
return Err(OpenJtalkError::UseUserDict(
"辞書の読み込みに失敗しました".to_string(),
));
}
return Ok(());
}
// ユーザー辞書用のcsvを作成
let mut temp_csv =
NamedTempFile::new().map_err(|e| OpenJtalkError::UseUserDict(e.to_string()))?;
Expand Down Expand Up @@ -97,8 +108,6 @@ impl OpenJtalk {
"-q",
]);

let Resources { mecab, .. } = &mut *self.resources.lock().unwrap();

let result = mecab.load_with_userdic(Path::new(dict_dir), Some(Path::new(&temp_dict_path)));

if !result {
Expand Down

0 comments on commit 8983d9b

Please sign in to comment.