From f162688ffa154bc1e606f43e4eedbba33058b1c6 Mon Sep 17 00:00:00 2001 From: yamachu Date: Thu, 10 Aug 2023 20:15:05 +0900 Subject: [PATCH 1/6] =?UTF-8?q?C-API=E3=81=AEnew=5Fwith=5Finitialize?= =?UTF-8?q?=E7=B5=8C=E7=94=B1=E3=81=A7=E5=88=9D=E6=9C=9F=E5=8C=96=E3=81=97?= =?UTF-8?q?=E3=81=9FSynthesizer=E3=82=82metas=20json=E3=82=92=E5=87=BA?= =?UTF-8?q?=E5=8A=9B=E3=81=99=E3=82=8B=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/src/c_impls.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/voicevox_core_c_api/src/c_impls.rs b/crates/voicevox_core_c_api/src/c_impls.rs index f4c58bcc4..4d0ad4432 100644 --- a/crates/voicevox_core_c_api/src/c_impls.rs +++ b/crates/voicevox_core_c_api/src/c_impls.rs @@ -55,3 +55,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() { + 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); + } +} From b04ac8377e13b57e442438e105d8c959a9e6985b Mon Sep 17 00:00:00 2001 From: yamachu Date: Thu, 10 Aug 2023 20:15:28 +0900 Subject: [PATCH 2/6] =?UTF-8?q?new=5Fwith=5Finitialize=E6=99=82=E7=82=B9?= =?UTF-8?q?=E3=81=A7metas=5Fcstring=E3=81=ABCString=E3=82=92=E5=87=BA?= =?UTF-8?q?=E5=8A=9B=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/src/c_impls.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/voicevox_core_c_api/src/c_impls.rs b/crates/voicevox_core_c_api/src/c_impls.rs index 4d0ad4432..dbd880ba0 100644 --- a/crates/voicevox_core_c_api/src/c_impls.rs +++ b/crates/voicevox_core_c_api/src/c_impls.rs @@ -21,10 +21,13 @@ impl VoicevoxSynthesizer { open_jtalk: &OpenJtalkRc, options: &InitializeOptions, ) -> Result { + 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, }) } From adb9368139db9b91a0e26ecfe162bf0246209eed Mon Sep 17 00:00:00 2001 From: yamachu Date: Thu, 10 Aug 2023 21:27:20 +0900 Subject: [PATCH 3/6] =?UTF-8?q?C-API=E3=81=AEe2e=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=92=E6=9B=B8=E3=81=8F=E5=A0=B4=E6=89=80=E3=81=8C?= =?UTF-8?q?=E3=81=82=E3=81=A3=E3=81=9F=E3=81=AE=E3=81=A7=E3=80=81=E3=81=9D?= =?UTF-8?q?=E3=81=A3=E3=81=A1=E3=81=AB=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E7=A7=BB=E6=A4=8D=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/src/c_impls.rs | 21 ---- .../tests/e2e/snapshots.toml | 43 ++++++++ .../tests/e2e/testcases.rs | 1 + ...hesizer_new_with_initialize_output_json.rs | 97 +++++++++++++++++++ 4 files changed, 141 insertions(+), 21 deletions(-) create mode 100644 crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs diff --git a/crates/voicevox_core_c_api/src/c_impls.rs b/crates/voicevox_core_c_api/src/c_impls.rs index dbd880ba0..f90db2337 100644 --- a/crates/voicevox_core_c_api/src/c_impls.rs +++ b/crates/voicevox_core_c_api/src/c_impls.rs @@ -58,24 +58,3 @@ 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() { - 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); - } -} diff --git a/crates/voicevox_core_c_api/tests/e2e/snapshots.toml b/crates/voicevox_core_c_api/tests/e2e/snapshots.toml index be4aabe9d..ea2a8a9b9 100644 --- a/crates/voicevox_core_c_api/tests/e2e/snapshots.toml +++ b/crates/voicevox_core_c_api/tests/e2e/snapshots.toml @@ -58,6 +58,49 @@ stderr.windows = ''' ''' stderr.unix = "" +[synthesizer_new_with_initialize_output_json] +metas = ''' +[ + { + "name": "dummy1", + "styles": [ + { + "id": 0, + "name": "style1" + } + ], + "version": "0.0.1", + "speaker_uuid": "574bc678-8370-44be-b941-08e46e7b47d7" + }, + { + "name": "dummy2", + "styles": [ + { + "id": 1, + "name": "style2" + } + ], + "version": "0.0.1", + "speaker_uuid": "dd9ccd75-75f6-40ce-a3db-960cbed2e905" + }, + { + "name": "dummy3", + "styles": [ + { + "id": 302, + "name": "style3-1" + }, + { + "id": 303, + "name": "style3-2" + } + ], + "version": "0.0.1", + "speaker_uuid": "5d3d9aa9-88e5-4a96-8ef7-f13a3cad1cb3" + } +]''' +stderr = "" + [tts_via_audio_query] output."こんにちは、音声合成の世界へようこそ".wav_length = 176172 stderr.windows = ''' diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases.rs b/crates/voicevox_core_c_api/tests/e2e/testcases.rs index f4d2920c7..96dfde11e 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases.rs @@ -5,3 +5,4 @@ mod simple_tts; mod tts_via_audio_query; mod user_dict_load; mod user_dict_manipulate; +mod synthesizer_new_with_initialize_output_json; diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs b/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs new file mode 100644 index 000000000..5e73b5d75 --- /dev/null +++ b/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs @@ -0,0 +1,97 @@ +use std::{ + ffi::{CStr, CString}, + mem::MaybeUninit, +}; + +use assert_cmd::assert::AssertResult; +use libloading::Library; +use once_cell::sync::Lazy; +use serde::{Deserialize, Serialize}; + +use test_util::OPEN_JTALK_DIC_DIR; +use voicevox_core::result_code::VoicevoxResultCode; + +use crate::{ + assert_cdylib::{self, case, Utf8Output}, + snapshots, + symbols::{Symbols, VoicevoxAccelerationMode, VoicevoxInitializeOptions}, +}; + +case!(TestCase); + +#[derive(Serialize, Deserialize)] +struct TestCase; + +#[typetag::serde(name = "synthesizer_new_with_initialize_output_json")] +impl assert_cdylib::TestCase for TestCase { + unsafe fn exec(&self, lib: &Library) -> anyhow::Result<()> { + let Symbols { + voicevox_default_initialize_options, + voicevox_open_jtalk_rc_new, + voicevox_open_jtalk_rc_delete, + voicevox_synthesizer_new_with_initialize, + voicevox_synthesizer_delete, + voicevox_synthesizer_get_metas_json, + .. + } = Symbols::new(lib)?; + + let openjtalk = { + let mut openjtalk = MaybeUninit::uninit(); + let open_jtalk_dic_dir = CString::new(OPEN_JTALK_DIC_DIR).unwrap(); + assert_ok(voicevox_open_jtalk_rc_new( + open_jtalk_dic_dir.as_ptr(), + openjtalk.as_mut_ptr(), + )); + openjtalk.assume_init() + }; + + let synthesizer = { + let mut synthesizer = MaybeUninit::uninit(); + assert_ok(voicevox_synthesizer_new_with_initialize( + openjtalk, + VoicevoxInitializeOptions { + acceleration_mode: VoicevoxAccelerationMode::VOICEVOX_ACCELERATION_MODE_CPU, + _load_all_models: true, + ..**voicevox_default_initialize_options + }, + synthesizer.as_mut_ptr(), + )); + synthesizer.assume_init() + }; + + let metas_json = { + let metas_json = + CStr::from_ptr(voicevox_synthesizer_get_metas_json(synthesizer)).to_str()?; + serde_json::to_string_pretty(&metas_json.parse::()?).unwrap() + }; + + std::assert_eq!(SNAPSHOTS.metas, metas_json); + + voicevox_open_jtalk_rc_delete(openjtalk); + voicevox_synthesizer_delete(synthesizer); + + return Ok(()); + + fn assert_ok(result_code: VoicevoxResultCode) { + std::assert_eq!(VoicevoxResultCode::VOICEVOX_RESULT_OK, result_code); + } + } + + fn assert_output(&self, output: Utf8Output) -> AssertResult { + output + .mask_timestamps() + .mask_windows_video_cards() + .assert() + .try_success()? + .try_stdout("")? + .try_stderr(&*SNAPSHOTS.stderr) + } +} + +static SNAPSHOTS: Lazy = snapshots::section!(synthesizer_new_with_initialize_output_json); + +#[derive(Deserialize)] +struct Snapshots { + metas: String, + stderr: String, +} From a5564d5ccaf908a7f0a6547057a70b4245fea872 Mon Sep 17 00:00:00 2001 From: yamachu Date: Thu, 10 Aug 2023 21:31:48 +0900 Subject: [PATCH 4/6] cargo fmt --- crates/voicevox_core_c_api/tests/e2e/testcases.rs | 2 +- .../testcases/synthesizer_new_with_initialize_output_json.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases.rs b/crates/voicevox_core_c_api/tests/e2e/testcases.rs index 96dfde11e..476f222c9 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases.rs @@ -2,7 +2,7 @@ mod compatible_engine; mod compatible_engine_load_model_before_initialize; mod global_info; mod simple_tts; +mod synthesizer_new_with_initialize_output_json; mod tts_via_audio_query; mod user_dict_load; mod user_dict_manipulate; -mod synthesizer_new_with_initialize_output_json; diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs b/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs index 5e73b5d75..c974f4994 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs @@ -88,7 +88,8 @@ impl assert_cdylib::TestCase for TestCase { } } -static SNAPSHOTS: Lazy = snapshots::section!(synthesizer_new_with_initialize_output_json); +static SNAPSHOTS: Lazy = + snapshots::section!(synthesizer_new_with_initialize_output_json); #[derive(Deserialize)] struct Snapshots { From 1bcb83c7be7c21baa54ccd1acfb96be22fa6e8fc Mon Sep 17 00:00:00 2001 From: yamachu Date: Thu, 10 Aug 2023 21:43:36 +0900 Subject: [PATCH 5/6] =?UTF-8?q?Windows=E7=92=B0=E5=A2=83=E3=81=A7stderr?= =?UTF-8?q?=E3=81=AB=E3=81=AA=E3=81=AB=E3=81=8B=E5=87=BA=E3=82=8B=E3=82=89?= =?UTF-8?q?=E3=81=97=E3=81=84=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/tests/e2e/snapshots.toml | 5 ++++- .../testcases/synthesizer_new_with_initialize_output_json.rs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/voicevox_core_c_api/tests/e2e/snapshots.toml b/crates/voicevox_core_c_api/tests/e2e/snapshots.toml index ea2a8a9b9..7ba0e0188 100644 --- a/crates/voicevox_core_c_api/tests/e2e/snapshots.toml +++ b/crates/voicevox_core_c_api/tests/e2e/snapshots.toml @@ -99,7 +99,10 @@ metas = ''' "speaker_uuid": "5d3d9aa9-88e5-4a96-8ef7-f13a3cad1cb3" } ]''' -stderr = "" +stderr.windows = ''' +{windows-video-cards} +''' +stderr.unix = "" [tts_via_audio_query] output."こんにちは、音声合成の世界へようこそ".wav_length = 176172 diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs b/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs index c974f4994..9a892fc3a 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs @@ -94,5 +94,6 @@ static SNAPSHOTS: Lazy = #[derive(Deserialize)] struct Snapshots { metas: String, + #[serde(deserialize_with = "snapshots::deserialize_platform_specific_snapshot")] stderr: String, } From 0bcb13a63a38be233e291be506f78b58f33e980d Mon Sep 17 00:00:00 2001 From: yamachu Date: Fri, 11 Aug 2023 01:09:39 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=5F=20prefix=20=E3=82=92=E5=89=8A=E9=99=A4?= =?UTF-8?q?=E3=81=97=E3=80=81=E5=A4=89=E6=9B=B4=E5=AF=BE=E8=B1=A1=E3=81=A7?= =?UTF-8?q?=E3=81=82=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E8=A6=8B=E3=81=9B?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/tests/e2e/symbols.rs | 2 +- .../testcases/synthesizer_new_with_initialize_output_json.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/voicevox_core_c_api/tests/e2e/symbols.rs b/crates/voicevox_core_c_api/tests/e2e/symbols.rs index 810fbf91b..a14e425f7 100644 --- a/crates/voicevox_core_c_api/tests/e2e/symbols.rs +++ b/crates/voicevox_core_c_api/tests/e2e/symbols.rs @@ -250,7 +250,7 @@ pub(crate) enum VoicevoxAccelerationMode { pub(crate) struct VoicevoxInitializeOptions { pub(crate) acceleration_mode: VoicevoxAccelerationMode, pub(crate) _cpu_num_threads: u16, - pub(crate) _load_all_models: bool, + pub(crate) load_all_models: bool, } #[derive(Clone, Copy)] diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs b/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs index 9a892fc3a..0edd73300 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases/synthesizer_new_with_initialize_output_json.rs @@ -51,7 +51,7 @@ impl assert_cdylib::TestCase for TestCase { openjtalk, VoicevoxInitializeOptions { acceleration_mode: VoicevoxAccelerationMode::VOICEVOX_ACCELERATION_MODE_CPU, - _load_all_models: true, + load_all_models: true, ..**voicevox_default_initialize_options }, synthesizer.as_mut_ptr(),