From 44716ce2994a2deeaf394d50c8bfc5053ec6ffd1 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sat, 27 May 2023 11:01:11 +0900 Subject: [PATCH 1/6] =?UTF-8?q?`voicevox=5Fget=5Fsupported=5Fdevices=5Fjso?= =?UTF-8?q?n`=E3=82=92fallible=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/voicevox_core.h | 9 +++++-- .../src/compatible_engine.rs | 9 ++++++- crates/voicevox_core_c_api/src/lib.rs | 27 +++++++++++-------- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/crates/voicevox_core_c_api/include/voicevox_core.h b/crates/voicevox_core_c_api/include/voicevox_core.h index 55c40aa2a..2fa0ea479 100644 --- a/crates/voicevox_core_c_api/include/voicevox_core.h +++ b/crates/voicevox_core_c_api/include/voicevox_core.h @@ -428,12 +428,17 @@ const char *voicevox_synthesizer_get_metas_json(const struct VoicevoxSynthesizer /** * サポートデバイス情報をjsonで取得する - * @return サポートデバイス情報のjson文字列 + * @param [out] output_supported_devices_json サポートデバイス情報のjson文字列 + * @return 結果コード #VoicevoxResultCode + * + * # Safety + * @param output_supported_devices_json 自動でheapメモリが割り当てられるので ::voicevox_json_free で解放する必要がある */ #ifdef _WIN32 __declspec(dllimport) #endif - const char *voicevox_get_supported_devices_json(void); + +VoicevoxResultCode voicevox_get_supported_devices_json(char **output_supported_devices_json); /** * デフォルトの AudioQuery のオプションを生成する diff --git a/crates/voicevox_core_c_api/src/compatible_engine.rs b/crates/voicevox_core_c_api/src/compatible_engine.rs index d944c0259..902ee4757 100644 --- a/crates/voicevox_core_c_api/src/compatible_engine.rs +++ b/crates/voicevox_core_c_api/src/compatible_engine.rs @@ -137,7 +137,14 @@ pub extern "C" fn last_error_message() -> *const c_char { #[no_mangle] pub extern "C" fn supported_devices() -> *const c_char { - voicevox_get_supported_devices_json() + return SUPPORTED_DEVICES.as_ptr(); + + static SUPPORTED_DEVICES: Lazy = Lazy::new(|| { + CString::new( + serde_json::to_string(&SupportedDevices::get_supported_devices().unwrap()).unwrap(), + ) + .unwrap() + }); } #[no_mangle] diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index b9ab4c664..03e43a160 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -346,19 +346,24 @@ pub unsafe extern "C" fn voicevox_synthesizer_get_metas_json( synthesizer.metas().as_ptr() } -static VOICEVOX_SUPPORTED_DEVICES_JSON: once_cell::sync::Lazy = - once_cell::sync::Lazy::new(|| { - CString::new( - serde_json::to_string(&SupportedDevices::get_supported_devices().unwrap()).unwrap(), - ) - .unwrap() - }); - /// サポートデバイス情報をjsonで取得する -/// @return サポートデバイス情報のjson文字列 +/// @param [out] output_supported_devices_json サポートデバイス情報のjson文字列 +/// @return 結果コード #VoicevoxResultCode +/// +/// # Safety +/// @param output_supported_devices_json 自動でheapメモリが割り当てられるので ::voicevox_json_free で解放する必要がある #[no_mangle] -pub extern "C" fn voicevox_get_supported_devices_json() -> *const c_char { - VOICEVOX_SUPPORTED_DEVICES_JSON.as_ptr() +pub unsafe extern "C" fn voicevox_get_supported_devices_json( + output_supported_devices_json: *mut *mut c_char, +) -> VoicevoxResultCode { + into_result_code_with_error((|| { + let supported_devices = CString::new( + serde_json::to_string(&SupportedDevices::get_supported_devices()?).unwrap(), + ) + .unwrap(); + output_supported_devices_json.write(supported_devices.into_raw()); + Ok(()) + })()) } /// Audio query のオプション From 617854e1736c28da5619a819e5a950fd06d797cf Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sat, 3 Jun 2023 16:12:37 +0900 Subject: [PATCH 2/6] =?UTF-8?q?`SupportedDevices::to=5Fjson`=E3=82=92?= =?UTF-8?q?=E4=BD=BF=E3=81=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core_c_api/src/compatible_engine.rs | 5 ++++- crates/voicevox_core_c_api/src/lib.rs | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/voicevox_core_c_api/src/compatible_engine.rs b/crates/voicevox_core_c_api/src/compatible_engine.rs index 902ee4757..e6e81d8d5 100644 --- a/crates/voicevox_core_c_api/src/compatible_engine.rs +++ b/crates/voicevox_core_c_api/src/compatible_engine.rs @@ -141,7 +141,10 @@ pub extern "C" fn supported_devices() -> *const c_char { static SUPPORTED_DEVICES: Lazy = Lazy::new(|| { CString::new( - serde_json::to_string(&SupportedDevices::get_supported_devices().unwrap()).unwrap(), + SupportedDevices::get_supported_devices() + .unwrap() + .to_json() + .to_string(), ) .unwrap() }); diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 03e43a160..a75ec50fa 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -358,7 +358,9 @@ pub unsafe extern "C" fn voicevox_get_supported_devices_json( ) -> VoicevoxResultCode { into_result_code_with_error((|| { let supported_devices = CString::new( - serde_json::to_string(&SupportedDevices::get_supported_devices()?).unwrap(), + SupportedDevices::get_supported_devices()? + .to_json() + .to_string(), ) .unwrap(); output_supported_devices_json.write(supported_devices.into_raw()); From f8f9380144f47455ef447ff5661692fb94cae09c Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sat, 3 Jun 2023 20:18:52 +0900 Subject: [PATCH 3/6] =?UTF-8?q?"create=5Fsupported=5Fdevices"=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core/src/devices.rs | 6 +++--- crates/voicevox_core/src/inference_core.rs | 2 +- crates/voicevox_core/src/voice_synthesizer.rs | 2 +- crates/voicevox_core_c_api/include/voicevox_core.h | 2 +- crates/voicevox_core_c_api/src/compatible_engine.rs | 8 +------- crates/voicevox_core_c_api/src/lib.rs | 10 +++------- crates/voicevox_core_c_api/tests/e2e/symbols.rs | 4 ++-- .../tests/e2e/testcases/compatible_engine.rs | 2 +- .../python/voicevox_core/__init__.py | 7 ++++++- .../python/voicevox_core/_rust.pyi | 2 +- crates/voicevox_core_python_api/src/lib.rs | 6 +++--- example/python/README.md | 4 ++-- example/python/run.py | 2 +- 13 files changed, 26 insertions(+), 31 deletions(-) diff --git a/crates/voicevox_core/src/devices.rs b/crates/voicevox_core/src/devices.rs index ceef4b9d3..d3141664c 100644 --- a/crates/voicevox_core/src/devices.rs +++ b/crates/voicevox_core/src/devices.rs @@ -11,7 +11,7 @@ pub struct SupportedDevices { impl SupportedDevices { /// サポートされているデバイス情報を取得する - pub fn get_supported_devices() -> Result { + pub fn create() -> Result { let mut cuda_support = false; let mut dml_support = false; for provider in onnxruntime::session::get_available_providers() @@ -41,8 +41,8 @@ impl SupportedDevices { mod tests { use super::*; #[rstest] - fn supported_devices_get_supported_devices_works() { - let result = SupportedDevices::get_supported_devices(); + fn supported_devices_create_works() { + let result = SupportedDevices::create(); // 環境によって結果が変わるので、関数呼び出しが成功するかどうかの確認のみ行う assert!(result.is_ok(), "{result:?}"); } diff --git a/crates/voicevox_core/src/inference_core.rs b/crates/voicevox_core/src/inference_core.rs index e22269486..578e57453 100644 --- a/crates/voicevox_core/src/inference_core.rs +++ b/crates/voicevox_core/src/inference_core.rs @@ -32,7 +32,7 @@ impl InferenceCore { } fn can_support_gpu_feature() -> Result { - let supported_devices = SupportedDevices::get_supported_devices()?; + let supported_devices = SupportedDevices::create()?; cfg_if! { if #[cfg(feature = "directml")]{ diff --git a/crates/voicevox_core/src/voice_synthesizer.rs b/crates/voicevox_core/src/voice_synthesizer.rs index 3557aa03d..174d3782e 100644 --- a/crates/voicevox_core/src/voice_synthesizer.rs +++ b/crates/voicevox_core/src/voice_synthesizer.rs @@ -89,7 +89,7 @@ impl Synthesizer { list_windows_video_cards(); let use_gpu = match options.acceleration_mode { AccelerationMode::Auto => { - let supported_devices = SupportedDevices::get_supported_devices()?; + let supported_devices = SupportedDevices::create()?; cfg_if! { if #[cfg(feature="directml")]{ diff --git a/crates/voicevox_core_c_api/include/voicevox_core.h b/crates/voicevox_core_c_api/include/voicevox_core.h index 2fa0ea479..eebbc2d41 100644 --- a/crates/voicevox_core_c_api/include/voicevox_core.h +++ b/crates/voicevox_core_c_api/include/voicevox_core.h @@ -438,7 +438,7 @@ const char *voicevox_synthesizer_get_metas_json(const struct VoicevoxSynthesizer __declspec(dllimport) #endif -VoicevoxResultCode voicevox_get_supported_devices_json(char **output_supported_devices_json); +VoicevoxResultCode voicevox_create_supported_devices_json(char **output_supported_devices_json); /** * デフォルトの AudioQuery のオプションを生成する diff --git a/crates/voicevox_core_c_api/src/compatible_engine.rs b/crates/voicevox_core_c_api/src/compatible_engine.rs index e6e81d8d5..e84040abc 100644 --- a/crates/voicevox_core_c_api/src/compatible_engine.rs +++ b/crates/voicevox_core_c_api/src/compatible_engine.rs @@ -140,13 +140,7 @@ pub extern "C" fn supported_devices() -> *const c_char { return SUPPORTED_DEVICES.as_ptr(); static SUPPORTED_DEVICES: Lazy = Lazy::new(|| { - CString::new( - SupportedDevices::get_supported_devices() - .unwrap() - .to_json() - .to_string(), - ) - .unwrap() + CString::new(SupportedDevices::create().unwrap().to_json().to_string()).unwrap() }); } diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index a75ec50fa..5419e0e10 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -353,16 +353,12 @@ pub unsafe extern "C" fn voicevox_synthesizer_get_metas_json( /// # Safety /// @param output_supported_devices_json 自動でheapメモリが割り当てられるので ::voicevox_json_free で解放する必要がある #[no_mangle] -pub unsafe extern "C" fn voicevox_get_supported_devices_json( +pub unsafe extern "C" fn voicevox_create_supported_devices_json( output_supported_devices_json: *mut *mut c_char, ) -> VoicevoxResultCode { into_result_code_with_error((|| { - let supported_devices = CString::new( - SupportedDevices::get_supported_devices()? - .to_json() - .to_string(), - ) - .unwrap(); + let supported_devices = + CString::new(SupportedDevices::create()?.to_json().to_string()).unwrap(); output_supported_devices_json.write(supported_devices.into_raw()); Ok(()) })()) diff --git a/crates/voicevox_core_c_api/tests/e2e/symbols.rs b/crates/voicevox_core_c_api/tests/e2e/symbols.rs index c26cb5e34..7c5e0b1b7 100644 --- a/crates/voicevox_core_c_api/tests/e2e/symbols.rs +++ b/crates/voicevox_core_c_api/tests/e2e/symbols.rs @@ -53,7 +53,7 @@ pub(crate) struct Symbols<'lib> { >, pub(crate) voicevox_synthesizer_get_metas_json: Symbol<'lib, unsafe extern "C" fn(*const VoicevoxSynthesizer) -> *const c_char>, - pub(crate) voicevox_get_supported_devices_json: + pub(crate) voicevox_create_supported_devices_json: Symbol<'lib, unsafe extern "C" fn() -> *const c_char>, pub(crate) voicevox_make_default_audio_query_options: Symbol<'lib, unsafe extern "C" fn() -> VoicevoxAudioQueryOptions>, @@ -153,7 +153,7 @@ impl<'lib> Symbols<'lib> { voicevox_synthesizer_is_gpu_mode, voicevox_is_loaded_voice_model, voicevox_synthesizer_get_metas_json, - voicevox_get_supported_devices_json, + voicevox_create_supported_devices_json, voicevox_make_default_audio_query_options, voicevox_synthesizer_audio_query, voicevox_make_default_synthesis_options, diff --git a/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine.rs b/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine.rs index df15173da..3682036ee 100644 --- a/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine.rs +++ b/crates/voicevox_core_c_api/tests/e2e/testcases/compatible_engine.rs @@ -121,7 +121,7 @@ impl assert_cdylib::TestCase for TestCase { std::assert_eq!(SNAPSHOTS.metas, metas_json); std::assert_eq!( - SupportedDevices::get_supported_devices().unwrap().to_json(), + SupportedDevices::create().unwrap().to_json(), supported_devices, ); diff --git a/crates/voicevox_core_python_api/python/voicevox_core/__init__.py b/crates/voicevox_core_python_api/python/voicevox_core/__init__.py index 7b1dce0c8..003be6e27 100644 --- a/crates/voicevox_core_python_api/python/voicevox_core/__init__.py +++ b/crates/voicevox_core_python_api/python/voicevox_core/__init__.py @@ -7,7 +7,12 @@ SpeakerMeta, SupportedDevices, ) -from ._rust import OpenJtalk, Synthesizer, VoiceModel, supported_devices # noqa: F401 +from ._rust import ( # noqa: F401 + OpenJtalk, + Synthesizer, + VoiceModel, + create_supported_devices, +) __all__ = [ "AccelerationMode", diff --git a/crates/voicevox_core_python_api/python/voicevox_core/_rust.pyi b/crates/voicevox_core_python_api/python/voicevox_core/_rust.pyi index 3ee503e88..c5f947704 100644 --- a/crates/voicevox_core_python_api/python/voicevox_core/_rust.pyi +++ b/crates/voicevox_core_python_api/python/voicevox_core/_rust.pyi @@ -14,7 +14,7 @@ from voicevox_core import ( __version__: str -def supported_devices() -> SupportedDevices: ... +def create_supported_devices() -> SupportedDevices: ... class VoiceModel: @staticmethod diff --git a/crates/voicevox_core_python_api/src/lib.rs b/crates/voicevox_core_python_api/src/lib.rs index b24862e1c..c636cbe4d 100644 --- a/crates/voicevox_core_python_api/src/lib.rs +++ b/crates/voicevox_core_python_api/src/lib.rs @@ -25,7 +25,7 @@ fn rust(_py: Python<'_>, module: &PyModule) -> PyResult<()> { pyo3_log::init(); module.add("__version__", voicevox_core::get_version())?; - module.add_wrapped(wrap_pyfunction!(supported_devices))?; + module.add_wrapped(wrap_pyfunction!(create_supported_devices))?; module.add_class::()?; module.add_class::()?; @@ -46,12 +46,12 @@ struct VoiceModel { } #[pyfunction] -fn supported_devices(py: Python) -> PyResult<&PyAny> { +fn create_supported_devices(py: Python) -> PyResult<&PyAny> { let class = py .import("voicevox_core")? .getattr("SupportedDevices")? .downcast()?; - let s = voicevox_core::SupportedDevices::get_supported_devices().into_py_result()?; + let s = voicevox_core::SupportedDevices::create().into_py_result()?; to_pydantic_dataclass(s, class) } diff --git a/example/python/README.md b/example/python/README.md index 191d41521..190aaba85 100644 --- a/example/python/README.md +++ b/example/python/README.md @@ -71,13 +71,13 @@ optional arguments: ```console ❯ python ./run.py ../../model/sample.vvm -[DEBUG] __main__: voicevox_core.supported_devices()=SupportedDevices(cpu=True, cuda=False, dml=False) +[DEBUG] __main__: voicevox_core.create_supported_devices()=SupportedDevices(cpu=True, cuda=False, dml=False) [INFO] __main__: Initializing (acceleration_mode=, open_jtalk_dict_dir=PosixPath('open_jtalk_dic_utf_8-1.11')) [DEBUG] __main__: synthesizer.metas=[] [DEBUG] __main__: synthesizer.is_gpu_mode=False [INFO] __main__: Loading `../../model/sample.vvm` [INFO] __main__: Creating an AudioQuery from 'この音声は、ボイスボックスを使用して、出力されています。' -[INFO] __main__: Synthesizing with {"accent_phrases": [{"moras": [{"text": "コ", "consonant": "k", "consonant_length": 0.0556899, "vowel": "o", "vowel_length": 0.075180575, "pitch": 5.542309}, {"text": "ノ", "consonant": "n", "consonant_length": 0.06551014, "vowel": "o", "vowel_length": 0.09984577, "pitch": 5.6173983}], "accent": 2, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "オ", "consonant": null, "consonant_length": null, "vowel": "o", "vowel_length": 0.116150305, "pitch": 5.7063766}, {"text": "ン", "consonant": null, "consonant_length": null, "vowel": "N", "vowel_length": 0.044380233, "pitch": 5.785717}, {"text": "セ", "consonant": "s", "consonant_length": 0.07719758, "vowel": "e", "vowel_length": 0.08653869, "pitch": 5.662092}, {"text": "エ", "consonant": null, "consonant_length": null, "vowel": "e", "vowel_length": 0.08311573, "pitch": 5.532917}, {"text": "ワ", "consonant": "w", "consonant_length": 0.06373148, "vowel": "a", "vowel_length": 0.16219379, "pitch": 5.293258}], "accent": 1, "pause_mora": {"text": "、", "consonant": null, "consonant_length": null, "vowel": "pau", "vowel_length": 0.35826492, "pitch": 0.0}, "is_interrogative": false}, {"moras": [{"text": "ボ", "consonant": "b", "consonant_length": 0.047082342, "vowel": "o", "vowel_length": 0.12611786, "pitch": 5.583892}, {"text": "イ", "consonant": null, "consonant_length": null, "vowel": "i", "vowel_length": 0.059451744, "pitch": 5.7947493}, {"text": "ス", "consonant": "s", "consonant_length": 0.089278996, "vowel": "u", "vowel_length": 0.11847979, "pitch": 5.818695}, {"text": "ボ", "consonant": "b", "consonant_length": 0.06535433, "vowel": "o", "vowel_length": 0.120458946, "pitch": 5.7965107}, {"text": "ッ", "consonant": null, "consonant_length": null, "vowel": "cl", "vowel_length": 0.06940381, "pitch": 0.0}, {"text": "ク", "consonant": "k", "consonant_length": 0.053739145, "vowel": "U", "vowel_length": 0.05395376, "pitch": 0.0}, {"text": "ス", "consonant": "s", "consonant_length": 0.10222931, "vowel": "u", "vowel_length": 0.071811065, "pitch": 5.8024883}, {"text": "オ", "consonant": null, "consonant_length": null, "vowel": "o", "vowel_length": 0.11092262, "pitch": 5.5036163}], "accent": 4, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "シ", "consonant": "sh", "consonant_length": 0.09327768, "vowel": "i", "vowel_length": 0.09126951, "pitch": 5.369444}, {"text": "ヨ", "consonant": "y", "consonant_length": 0.06251812, "vowel": "o", "vowel_length": 0.07805054, "pitch": 5.5021667}, {"text": "オ", "consonant": null, "consonant_length": null, "vowel": "o", "vowel_length": 0.09904325, "pitch": 5.5219536}], "accent": 3, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "シ", "consonant": "sh", "consonant_length": 0.04879771, "vowel": "I", "vowel_length": 0.06514315, "pitch": 0.0}, {"text": "テ", "consonant": "t", "consonant_length": 0.0840496, "vowel": "e", "vowel_length": 0.19438823, "pitch": 5.4875555}], "accent": 2, "pause_mora": {"text": "、", "consonant": null, "consonant_length": null, "vowel": "pau", "vowel_length": 0.35208154, "pitch": 0.0}, "is_interrogative": false}, {"moras": [{"text": "シュ", "consonant": "sh", "consonant_length": 0.05436731, "vowel": "U", "vowel_length": 0.06044446, "pitch": 0.0}, {"text": "ツ", "consonant": "ts", "consonant_length": 0.102865085, "vowel": "u", "vowel_length": 0.057028636, "pitch": 5.6402535}, {"text": "リョ", "consonant": "ry", "consonant_length": 0.058293864, "vowel": "o", "vowel_length": 0.080050275, "pitch": 5.6997967}, {"text": "ク", "consonant": "k", "consonant_length": 0.054767884, "vowel": "U", "vowel_length": 0.042932786, "pitch": 0.0}], "accent": 2, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "サ", "consonant": "s", "consonant_length": 0.08067487, "vowel": "a", "vowel_length": 0.07377973, "pitch": 5.652378}, {"text": "レ", "consonant": "r", "consonant_length": 0.040600352, "vowel": "e", "vowel_length": 0.079322875, "pitch": 5.6290326}, {"text": "テ", "consonant": "t", "consonant_length": 0.06773268, "vowel": "e", "vowel_length": 0.08347456, "pitch": 5.6427326}], "accent": 3, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "イ", "consonant": null, "consonant_length": null, "vowel": "i", "vowel_length": 0.07542324, "pitch": 5.641289}, {"text": "マ", "consonant": "m", "consonant_length": 0.066299975, "vowel": "a", "vowel_length": 0.107257664, "pitch": 5.6201453}, {"text": "ス", "consonant": "s", "consonant_length": 0.07186453, "vowel": "U", "vowel_length": 0.1163103, "pitch": 0.0}], "accent": 2, "pause_mora": null, "is_interrogative": false}], "speed_scale": 1.0, "pitch_scale": 0.0, "intonation_scale": 1.0, "volume_scale": 1.0, "pre_phoneme_length": 0.1, "post_phoneme_length": 0.1, "output_sampling_rate": 24000, "output_stereo": false, "kana": "コノ'/オ'ンセエワ、ボイスボ'ッ_クスオ/シヨオ'/_シテ'、_シュツ' リョ_ク/サレテ'/イマ'_ス"} +[INFO] __main__: Synthesizing with {"accent_phrases": [{"moras": [{"text": "コ", "consonant": "k", "consonant_length": 0.0556899, "vowel": "o", "vowel_length": 0.075180575, "pitch": 5.542309}, {"text": "ノ", "consonant": "n", "consonant_length": 0.06551014, "vowel": "o", "vowel_length": 0.09984577, "pitch": 5.6173983}], "accent": 2, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "オ", "consonant": null, "consonant_length": null, "vowel": "o", "vowel_length": 0.116150305, "pitch": 5.7063766}, {"text": "ン", "consonant": null, "consonant_length": null, "vowel": "N", "vowel_length": 0.044380233, "pitch": 5.785717}, {"text": "セ", "consonant": "s", "consonant_length": 0.07719758, "vowel": "e", "vowel_length": 0.08653869, "pitch": 5.662092}, {"text": "エ", "consonant": null, "consonant_length": null, "vowel": "e", "vowel_length": 0.08311573, "pitch": 5.532917}, {"text": "ワ", "consonant": "w", "consonant_length": 0.06373148, "vowel": "a", "vowel_length": 0.16219379, "pitch": 5.293258}], "accent": 1, "pause_mora": {"text": "、", "consonant": null, "consonant_length": null, "vowel": "pau", "vowel_length": 0.35826492, "pitch": 0.0}, "is_interrogative": false}, {"moras": [{"text": "ボ", "consonant": "b", "consonant_length": 0.047082342, "vowel": "o", "vowel_length": 0.12611786, "pitch": 5.583892}, {"text": "イ", "consonant": null, "consonant_length": null, "vowel": "i", "vowel_length": 0.059451744, "pitch": 5.7947493}, {"text": "ス", "consonant": "s", "consonant_length": 0.089278996, "vowel": "u", "vowel_length": 0.11847979, "pitch": 5.818695}, {"text": "ボ", "consonant": "b", "consonant_length": 0.06535433, "vowel": "o", "vowel_length": 0.120458946, "pitch": 5.7965107}, {"text": "ッ", "consonant": null, "consonant_length": null, "vowel": "cl", "vowel_length": 0.06940381, "pitch": 0.0}, {"text": "ク", "consonant": "k", "consonant_length": 0.053739145, "vowel": "U", "vowel_length": 0.05395376, "pitch": 0.0}, {"text": "ス", "consonant": "s", "consonant_length": 0.10222931, "vowel": "u", "vowel_length": 0.071811065, "pitch": 5.8024883}, {"text": "オ", "consonant": null, "consonant_length": null, "vowel": "o", "vowel_length": 0.11092262, "pitch": 5.5036163}], "accent": 4, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "シ", "consonant": "sh", "consonant_length": 0.09327768, "vowel": "i", "vowel_length": 0.09126951, "pitch": 5.369444}, {"text": "ヨ", "consonant": "y", "consonant_length": 0.06251812, "vowel": "o", "vowel_length": 0.07805054, "pitch": 5.5021667}, {"text": "オ", "consonant": null, "consonant_length": null, "vowel": "o", "vowel_length": 0.09904325, "pitch": 5.5219536}], "accent": 3, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "シ", "consonant": "sh", "consonant_length": 0.04879771, "vowel": "I", "vowel_length": 0.06514315, "pitch": 0.0}, {"text": "テ", "consonant": "t", "consonant_length": 0.0840496, "vowel": "e", "vowel_length": 0.19438823, "pitch": 5.4875555}], "accent": 2, "pause_mora": {"text": "、", "consonant": null, "consonant_length": null, "vowel": "pau", "vowel_length": 0.35208154, "pitch": 0.0}, "is_interrogative": false}, {"moras": [{"text": "シュ", "consonant": "sh", "consonant_length": 0.05436731, "vowel": "U", "vowel_length": 0.06044446, "pitch": 0.0}, {"text": "ツ", "consonant": "ts", "consonant_length": 0.102865085, "vowel": "u", "vowel_length": 0.057028636, "pitch": 5.6402535}, {"text": "リョ", "consonant": "ry", "consonant_length": 0.058293864, "vowel": "o", "vowel_length": 0.080050275, "pitch": 5.6997967}, {"text": "ク", "consonant": "k", "consonant_length": 0.054767884, "vowel": "U", "vowel_length": 0.042932786, "pitch": 0.0}], "accent": 2, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "サ", "consonant": "s", "consonant_length": 0.08067487, "vowel": "a", "vowel_length": 0.07377973, "pitch": 5.652378}, {"text": "レ", "consonant": "r", "consonant_length": 0.040600352, "vowel": "e", "vowel_length": 0.079322875, "pitch": 5.6290326}, {"text": "テ", "consonant": "t", "consonant_length": 0.06773268, "vowel": "e", "vowel_length": 0.08347456, "pitch": 5.6427326}], "accent": 3, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "イ", "consonant": null, "consonant_length": null, "vowel": "i", "vowel_length": 0.07542324, "pitch": 5.641289}, {"text": "マ", "consonant": "m", "consonant_length": 0.066299975, "vowel": "a", "vowel_length": 0.107257664, "pitch": 5.6201453}, {"text": "ス", "consonant": "s", "consonant_length": 0.07186453, "vowel": "U", "vowel_length": 0.1163103, "pitch": 0.0}], "accent": 2, "pause_mora": null, "is_interrogative": false}], "speed_scale": 1.0, "pitch_scale": 0.0, "intonation_scale": 1.0, "volume_scale": 1.0, "pre_phoneme_length": 0.1, "post_phoneme_length": 0.1, "output_sampling_rate": 24000, "output_stereo": false, "kana": "コノ'/オ'ンセエワ、ボイスボ'ッ_クスオ/シヨオ'/_シテ'、_シュツ'リョ_ク/サレテ'/イマ'_ス"} [INFO] __main__: Wrote `output.wav` [DEBUG] voicevox_core_python_api: Destructing a VoicevoxCore ``` diff --git a/example/python/run.py b/example/python/run.py index d0899b749..0371b0034 100644 --- a/example/python/run.py +++ b/example/python/run.py @@ -32,7 +32,7 @@ async def main() -> None: speaker_id, ) = parse_args() - logger.debug("%s", f"{voicevox_core.supported_devices()=}") + logger.debug("%s", f"{voicevox_core.create_supported_devices()=}") logger.info("%s", f"Initializing ({acceleration_mode=}, {open_jtalk_dict_dir=})") synthesizer = await Synthesizer.new_with_initialize( From fb2e8116af5561a608687821a12122dea9e544a5 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Mon, 5 Jun 2023 22:31:34 +0900 Subject: [PATCH 4/6] =?UTF-8?q?Python=20API=E3=81=AF=E5=85=83=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../python/voicevox_core/__init__.py | 7 +------ .../python/voicevox_core/_rust.pyi | 2 +- crates/voicevox_core_python_api/src/lib.rs | 4 ++-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/crates/voicevox_core_python_api/python/voicevox_core/__init__.py b/crates/voicevox_core_python_api/python/voicevox_core/__init__.py index 003be6e27..7b1dce0c8 100644 --- a/crates/voicevox_core_python_api/python/voicevox_core/__init__.py +++ b/crates/voicevox_core_python_api/python/voicevox_core/__init__.py @@ -7,12 +7,7 @@ SpeakerMeta, SupportedDevices, ) -from ._rust import ( # noqa: F401 - OpenJtalk, - Synthesizer, - VoiceModel, - create_supported_devices, -) +from ._rust import OpenJtalk, Synthesizer, VoiceModel, supported_devices # noqa: F401 __all__ = [ "AccelerationMode", diff --git a/crates/voicevox_core_python_api/python/voicevox_core/_rust.pyi b/crates/voicevox_core_python_api/python/voicevox_core/_rust.pyi index c5f947704..3ee503e88 100644 --- a/crates/voicevox_core_python_api/python/voicevox_core/_rust.pyi +++ b/crates/voicevox_core_python_api/python/voicevox_core/_rust.pyi @@ -14,7 +14,7 @@ from voicevox_core import ( __version__: str -def create_supported_devices() -> SupportedDevices: ... +def supported_devices() -> SupportedDevices: ... class VoiceModel: @staticmethod diff --git a/crates/voicevox_core_python_api/src/lib.rs b/crates/voicevox_core_python_api/src/lib.rs index d5109bbd0..e40294609 100644 --- a/crates/voicevox_core_python_api/src/lib.rs +++ b/crates/voicevox_core_python_api/src/lib.rs @@ -25,7 +25,7 @@ fn rust(_py: Python<'_>, module: &PyModule) -> PyResult<()> { pyo3_log::init(); module.add("__version__", env!("CARGO_PKG_VERSION"))?; - module.add_wrapped(wrap_pyfunction!(create_supported_devices))?; + module.add_wrapped(wrap_pyfunction!(supported_devices))?; module.add_class::()?; module.add_class::()?; @@ -46,7 +46,7 @@ struct VoiceModel { } #[pyfunction] -fn create_supported_devices(py: Python) -> PyResult<&PyAny> { +fn supported_devices(py: Python) -> PyResult<&PyAny> { let class = py .import("voicevox_core")? .getattr("SupportedDevices")? From f5ea56a3c991a11587b8d39dbaf2462f146ef304 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Mon, 5 Jun 2023 23:50:15 +0900 Subject: [PATCH 5/6] =?UTF-8?q?readme=E3=82=82=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/python/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/python/README.md b/example/python/README.md index 190aaba85..191d41521 100644 --- a/example/python/README.md +++ b/example/python/README.md @@ -71,13 +71,13 @@ optional arguments: ```console ❯ python ./run.py ../../model/sample.vvm -[DEBUG] __main__: voicevox_core.create_supported_devices()=SupportedDevices(cpu=True, cuda=False, dml=False) +[DEBUG] __main__: voicevox_core.supported_devices()=SupportedDevices(cpu=True, cuda=False, dml=False) [INFO] __main__: Initializing (acceleration_mode=, open_jtalk_dict_dir=PosixPath('open_jtalk_dic_utf_8-1.11')) [DEBUG] __main__: synthesizer.metas=[] [DEBUG] __main__: synthesizer.is_gpu_mode=False [INFO] __main__: Loading `../../model/sample.vvm` [INFO] __main__: Creating an AudioQuery from 'この音声は、ボイスボックスを使用して、出力されています。' -[INFO] __main__: Synthesizing with {"accent_phrases": [{"moras": [{"text": "コ", "consonant": "k", "consonant_length": 0.0556899, "vowel": "o", "vowel_length": 0.075180575, "pitch": 5.542309}, {"text": "ノ", "consonant": "n", "consonant_length": 0.06551014, "vowel": "o", "vowel_length": 0.09984577, "pitch": 5.6173983}], "accent": 2, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "オ", "consonant": null, "consonant_length": null, "vowel": "o", "vowel_length": 0.116150305, "pitch": 5.7063766}, {"text": "ン", "consonant": null, "consonant_length": null, "vowel": "N", "vowel_length": 0.044380233, "pitch": 5.785717}, {"text": "セ", "consonant": "s", "consonant_length": 0.07719758, "vowel": "e", "vowel_length": 0.08653869, "pitch": 5.662092}, {"text": "エ", "consonant": null, "consonant_length": null, "vowel": "e", "vowel_length": 0.08311573, "pitch": 5.532917}, {"text": "ワ", "consonant": "w", "consonant_length": 0.06373148, "vowel": "a", "vowel_length": 0.16219379, "pitch": 5.293258}], "accent": 1, "pause_mora": {"text": "、", "consonant": null, "consonant_length": null, "vowel": "pau", "vowel_length": 0.35826492, "pitch": 0.0}, "is_interrogative": false}, {"moras": [{"text": "ボ", "consonant": "b", "consonant_length": 0.047082342, "vowel": "o", "vowel_length": 0.12611786, "pitch": 5.583892}, {"text": "イ", "consonant": null, "consonant_length": null, "vowel": "i", "vowel_length": 0.059451744, "pitch": 5.7947493}, {"text": "ス", "consonant": "s", "consonant_length": 0.089278996, "vowel": "u", "vowel_length": 0.11847979, "pitch": 5.818695}, {"text": "ボ", "consonant": "b", "consonant_length": 0.06535433, "vowel": "o", "vowel_length": 0.120458946, "pitch": 5.7965107}, {"text": "ッ", "consonant": null, "consonant_length": null, "vowel": "cl", "vowel_length": 0.06940381, "pitch": 0.0}, {"text": "ク", "consonant": "k", "consonant_length": 0.053739145, "vowel": "U", "vowel_length": 0.05395376, "pitch": 0.0}, {"text": "ス", "consonant": "s", "consonant_length": 0.10222931, "vowel": "u", "vowel_length": 0.071811065, "pitch": 5.8024883}, {"text": "オ", "consonant": null, "consonant_length": null, "vowel": "o", "vowel_length": 0.11092262, "pitch": 5.5036163}], "accent": 4, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "シ", "consonant": "sh", "consonant_length": 0.09327768, "vowel": "i", "vowel_length": 0.09126951, "pitch": 5.369444}, {"text": "ヨ", "consonant": "y", "consonant_length": 0.06251812, "vowel": "o", "vowel_length": 0.07805054, "pitch": 5.5021667}, {"text": "オ", "consonant": null, "consonant_length": null, "vowel": "o", "vowel_length": 0.09904325, "pitch": 5.5219536}], "accent": 3, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "シ", "consonant": "sh", "consonant_length": 0.04879771, "vowel": "I", "vowel_length": 0.06514315, "pitch": 0.0}, {"text": "テ", "consonant": "t", "consonant_length": 0.0840496, "vowel": "e", "vowel_length": 0.19438823, "pitch": 5.4875555}], "accent": 2, "pause_mora": {"text": "、", "consonant": null, "consonant_length": null, "vowel": "pau", "vowel_length": 0.35208154, "pitch": 0.0}, "is_interrogative": false}, {"moras": [{"text": "シュ", "consonant": "sh", "consonant_length": 0.05436731, "vowel": "U", "vowel_length": 0.06044446, "pitch": 0.0}, {"text": "ツ", "consonant": "ts", "consonant_length": 0.102865085, "vowel": "u", "vowel_length": 0.057028636, "pitch": 5.6402535}, {"text": "リョ", "consonant": "ry", "consonant_length": 0.058293864, "vowel": "o", "vowel_length": 0.080050275, "pitch": 5.6997967}, {"text": "ク", "consonant": "k", "consonant_length": 0.054767884, "vowel": "U", "vowel_length": 0.042932786, "pitch": 0.0}], "accent": 2, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "サ", "consonant": "s", "consonant_length": 0.08067487, "vowel": "a", "vowel_length": 0.07377973, "pitch": 5.652378}, {"text": "レ", "consonant": "r", "consonant_length": 0.040600352, "vowel": "e", "vowel_length": 0.079322875, "pitch": 5.6290326}, {"text": "テ", "consonant": "t", "consonant_length": 0.06773268, "vowel": "e", "vowel_length": 0.08347456, "pitch": 5.6427326}], "accent": 3, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "イ", "consonant": null, "consonant_length": null, "vowel": "i", "vowel_length": 0.07542324, "pitch": 5.641289}, {"text": "マ", "consonant": "m", "consonant_length": 0.066299975, "vowel": "a", "vowel_length": 0.107257664, "pitch": 5.6201453}, {"text": "ス", "consonant": "s", "consonant_length": 0.07186453, "vowel": "U", "vowel_length": 0.1163103, "pitch": 0.0}], "accent": 2, "pause_mora": null, "is_interrogative": false}], "speed_scale": 1.0, "pitch_scale": 0.0, "intonation_scale": 1.0, "volume_scale": 1.0, "pre_phoneme_length": 0.1, "post_phoneme_length": 0.1, "output_sampling_rate": 24000, "output_stereo": false, "kana": "コノ'/オ'ンセエワ、ボイスボ'ッ_クスオ/シヨオ'/_シテ'、_シュツ'リョ_ク/サレテ'/イマ'_ス"} +[INFO] __main__: Synthesizing with {"accent_phrases": [{"moras": [{"text": "コ", "consonant": "k", "consonant_length": 0.0556899, "vowel": "o", "vowel_length": 0.075180575, "pitch": 5.542309}, {"text": "ノ", "consonant": "n", "consonant_length": 0.06551014, "vowel": "o", "vowel_length": 0.09984577, "pitch": 5.6173983}], "accent": 2, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "オ", "consonant": null, "consonant_length": null, "vowel": "o", "vowel_length": 0.116150305, "pitch": 5.7063766}, {"text": "ン", "consonant": null, "consonant_length": null, "vowel": "N", "vowel_length": 0.044380233, "pitch": 5.785717}, {"text": "セ", "consonant": "s", "consonant_length": 0.07719758, "vowel": "e", "vowel_length": 0.08653869, "pitch": 5.662092}, {"text": "エ", "consonant": null, "consonant_length": null, "vowel": "e", "vowel_length": 0.08311573, "pitch": 5.532917}, {"text": "ワ", "consonant": "w", "consonant_length": 0.06373148, "vowel": "a", "vowel_length": 0.16219379, "pitch": 5.293258}], "accent": 1, "pause_mora": {"text": "、", "consonant": null, "consonant_length": null, "vowel": "pau", "vowel_length": 0.35826492, "pitch": 0.0}, "is_interrogative": false}, {"moras": [{"text": "ボ", "consonant": "b", "consonant_length": 0.047082342, "vowel": "o", "vowel_length": 0.12611786, "pitch": 5.583892}, {"text": "イ", "consonant": null, "consonant_length": null, "vowel": "i", "vowel_length": 0.059451744, "pitch": 5.7947493}, {"text": "ス", "consonant": "s", "consonant_length": 0.089278996, "vowel": "u", "vowel_length": 0.11847979, "pitch": 5.818695}, {"text": "ボ", "consonant": "b", "consonant_length": 0.06535433, "vowel": "o", "vowel_length": 0.120458946, "pitch": 5.7965107}, {"text": "ッ", "consonant": null, "consonant_length": null, "vowel": "cl", "vowel_length": 0.06940381, "pitch": 0.0}, {"text": "ク", "consonant": "k", "consonant_length": 0.053739145, "vowel": "U", "vowel_length": 0.05395376, "pitch": 0.0}, {"text": "ス", "consonant": "s", "consonant_length": 0.10222931, "vowel": "u", "vowel_length": 0.071811065, "pitch": 5.8024883}, {"text": "オ", "consonant": null, "consonant_length": null, "vowel": "o", "vowel_length": 0.11092262, "pitch": 5.5036163}], "accent": 4, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "シ", "consonant": "sh", "consonant_length": 0.09327768, "vowel": "i", "vowel_length": 0.09126951, "pitch": 5.369444}, {"text": "ヨ", "consonant": "y", "consonant_length": 0.06251812, "vowel": "o", "vowel_length": 0.07805054, "pitch": 5.5021667}, {"text": "オ", "consonant": null, "consonant_length": null, "vowel": "o", "vowel_length": 0.09904325, "pitch": 5.5219536}], "accent": 3, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "シ", "consonant": "sh", "consonant_length": 0.04879771, "vowel": "I", "vowel_length": 0.06514315, "pitch": 0.0}, {"text": "テ", "consonant": "t", "consonant_length": 0.0840496, "vowel": "e", "vowel_length": 0.19438823, "pitch": 5.4875555}], "accent": 2, "pause_mora": {"text": "、", "consonant": null, "consonant_length": null, "vowel": "pau", "vowel_length": 0.35208154, "pitch": 0.0}, "is_interrogative": false}, {"moras": [{"text": "シュ", "consonant": "sh", "consonant_length": 0.05436731, "vowel": "U", "vowel_length": 0.06044446, "pitch": 0.0}, {"text": "ツ", "consonant": "ts", "consonant_length": 0.102865085, "vowel": "u", "vowel_length": 0.057028636, "pitch": 5.6402535}, {"text": "リョ", "consonant": "ry", "consonant_length": 0.058293864, "vowel": "o", "vowel_length": 0.080050275, "pitch": 5.6997967}, {"text": "ク", "consonant": "k", "consonant_length": 0.054767884, "vowel": "U", "vowel_length": 0.042932786, "pitch": 0.0}], "accent": 2, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "サ", "consonant": "s", "consonant_length": 0.08067487, "vowel": "a", "vowel_length": 0.07377973, "pitch": 5.652378}, {"text": "レ", "consonant": "r", "consonant_length": 0.040600352, "vowel": "e", "vowel_length": 0.079322875, "pitch": 5.6290326}, {"text": "テ", "consonant": "t", "consonant_length": 0.06773268, "vowel": "e", "vowel_length": 0.08347456, "pitch": 5.6427326}], "accent": 3, "pause_mora": null, "is_interrogative": false}, {"moras": [{"text": "イ", "consonant": null, "consonant_length": null, "vowel": "i", "vowel_length": 0.07542324, "pitch": 5.641289}, {"text": "マ", "consonant": "m", "consonant_length": 0.066299975, "vowel": "a", "vowel_length": 0.107257664, "pitch": 5.6201453}, {"text": "ス", "consonant": "s", "consonant_length": 0.07186453, "vowel": "U", "vowel_length": 0.1163103, "pitch": 0.0}], "accent": 2, "pause_mora": null, "is_interrogative": false}], "speed_scale": 1.0, "pitch_scale": 0.0, "intonation_scale": 1.0, "volume_scale": 1.0, "pre_phoneme_length": 0.1, "post_phoneme_length": 0.1, "output_sampling_rate": 24000, "output_stereo": false, "kana": "コノ'/オ'ンセエワ、ボイスボ'ッ_クスオ/シヨオ'/_シテ'、_シュツ' リョ_ク/サレテ'/イマ'_ス"} [INFO] __main__: Wrote `output.wav` [DEBUG] voicevox_core_python_api: Destructing a VoicevoxCore ``` From a43a6443a26dade44ab1141719bdaeba1677f850 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Tue, 6 Jun 2023 01:21:35 +0900 Subject: [PATCH 6/6] =?UTF-8?q?run.py=E3=82=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/python/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/python/run.py b/example/python/run.py index 0371b0034..d0899b749 100644 --- a/example/python/run.py +++ b/example/python/run.py @@ -32,7 +32,7 @@ async def main() -> None: speaker_id, ) = parse_args() - logger.debug("%s", f"{voicevox_core.create_supported_devices()=}") + logger.debug("%s", f"{voicevox_core.supported_devices()=}") logger.info("%s", f"Initializing ({acceleration_mode=}, {open_jtalk_dict_dir=})") synthesizer = await Synthesizer.new_with_initialize(