Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C-APIのnew_with_initializeで初期化した場合、metas jsonが空になってしまうことの修正 #575

Merged
merged 6 commits into from
Aug 12, 2023
30 changes: 27 additions & 3 deletions crates/voicevox_core_c_api/src/c_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ impl VoicevoxSynthesizer {
open_jtalk: &OpenJtalkRc,
options: &InitializeOptions,
) -> Result<Self> {
let synthesizer =
Synthesizer::new_with_initialize(open_jtalk.open_jtalk.clone(), options).await?;
let metas = synthesizer.metas();
let metas_cstring = CString::new(serde_json::to_string(&metas).unwrap()).unwrap();
Ok(Self {
synthesizer: Synthesizer::new_with_initialize(open_jtalk.open_jtalk.clone(), options)
.await?,
metas_cstring: CString::default(),
synthesizer,
metas_cstring,
})
}

Expand Down Expand Up @@ -55,3 +58,24 @@ impl VoicevoxVoiceModel {
Ok(Self { model, id, metas })
}
}

#[cfg(test)]
mod tests {
use super::*;
use ::test_util::OPEN_JTALK_DIC_DIR;
use rstest::*;

#[rstest]
#[tokio::test]
async fn new_with_initialize_must_output_metas_json() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

動作させるためには ./target/debug/deps/modelsample.vvm を配置しないといけないので、どう初期化するかに悩んでいます…

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以前ではVV_MODELS_ROOT_DIRみたいな環境変数でmodelディレクトリの位置を制御してた記憶があります。それを入れるとか?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

おっ、そんなものが

let open_jtalk = OpenJtalkRc::new_with_initialize(OPEN_JTALK_DIC_DIR).unwrap();
let mut options = InitializeOptions::default();
options.load_all_models = true;
let synthesizer = VoicevoxSynthesizer::new_with_initialize(&open_jtalk, &options)
.await
.unwrap();

println!("{:?}", synthesizer.metas());
assert_eq!(CStr::is_empty(synthesizer.metas()), false);
}
}
Loading