From 3122a44b8fc247194c2549754a4746f13d11cbf6 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sun, 1 Dec 2024 16:46:23 +0900 Subject: [PATCH] =?UTF-8?q?feat!:=20`Synthesizer::audio=5Fquery`=E3=82=92`?= =?UTF-8?q?create=5Faudio=5Fquery`=E3=81=AB=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core/src/synthesizer.rs | 48 +++++++++++-------- crates/voicevox_core_c_api/src/lib.rs | 4 +- .../voicevoxcore/blocking/Synthesizer.java | 9 ++-- .../voicevox_core_java_api/src/synthesizer.rs | 9 ++-- .../test/test_asyncio_user_dict_load.py | 4 +- .../test/test_blocking_user_dict_load.py | 4 +- .../python/voicevox_core/_rust/asyncio.pyi | 4 +- .../python/voicevox_core/_rust/blocking.pyi | 4 +- crates/voicevox_core_python_api/src/lib.rs | 16 +++---- example/python/run-asyncio.py | 2 +- example/python/run.py | 2 +- 11 files changed, 59 insertions(+), 47 deletions(-) diff --git a/crates/voicevox_core/src/synthesizer.rs b/crates/voicevox_core/src/synthesizer.rs index 1bec68d9f..31aec6b72 100644 --- a/crates/voicevox_core/src/synthesizer.rs +++ b/crates/voicevox_core/src/synthesizer.rs @@ -730,7 +730,7 @@ mod inner { } } - pub(super) async fn audio_query_from_kana( + pub(super) async fn create_audio_query_from_kana( &self, kana: &str, style_id: StyleId, @@ -745,7 +745,7 @@ mod inner { style_id: StyleId, options: &TtsOptions, ) -> Result> { - let audio_query = &self.audio_query_from_kana(kana, style_id).await?; + let audio_query = &self.create_audio_query_from_kana(kana, style_id).await?; self.synthesis(audio_query, style_id, &SynthesisOptions::from(options)) .await } @@ -761,7 +761,7 @@ mod inner { self.replace_mora_data(&accent_phrases, style_id).await } - pub(super) async fn audio_query( + pub(super) async fn create_audio_query( &self, text: &str, style_id: StyleId, @@ -776,7 +776,7 @@ mod inner { style_id: StyleId, options: &TtsOptions, ) -> Result> { - let audio_query = &self.audio_query(text, style_id).await?; + let audio_query = &self.create_audio_query(text, style_id).await?; self.synthesis(audio_query, style_id, &SynthesisOptions::from(options)) .await } @@ -1417,19 +1417,21 @@ pub(crate) mod blocking { /// # /// use voicevox_core::StyleId; /// - /// let audio_query = synthesizer.audio_query_from_kana("コンニチワ'", StyleId::new(302))?; + /// let audio_query = synthesizer.create_audio_query_from_kana("コンニチワ'", StyleId::new(302))?; /// # /// # Ok(()) /// # } /// ``` /// /// [AudioQuery]: crate::AudioQuery - pub fn audio_query_from_kana( + pub fn create_audio_query_from_kana( &self, kana: &str, style_id: StyleId, ) -> crate::Result { - self.0.audio_query_from_kana(kana, style_id).block_on() + self.0 + .create_audio_query_from_kana(kana, style_id) + .block_on() } /// AquesTalk風記法から音声合成を行う。 @@ -1497,15 +1499,19 @@ pub(crate) mod blocking { /// # /// use voicevox_core::StyleId; /// - /// let audio_query = synthesizer.audio_query("こんにちは", StyleId::new(302))?; + /// let audio_query = synthesizer.create_audio_query("こんにちは", StyleId::new(302))?; /// # /// # Ok(()) /// # } /// ``` /// /// [AudioQuery]: crate::AudioQuery - pub fn audio_query(&self, text: &str, style_id: StyleId) -> crate::Result { - self.0.audio_query(text, style_id).block_on() + pub fn create_audio_query( + &self, + text: &str, + style_id: StyleId, + ) -> crate::Result { + self.0.create_audio_query(text, style_id).block_on() } /// 日本語のテキストから音声合成を行う。 @@ -1784,7 +1790,7 @@ pub(crate) mod nonblocking { /// use voicevox_core::StyleId; /// /// let audio_query = synthesizer - /// .audio_query_from_kana("コンニチワ'", StyleId::new(302)) + /// .create_audio_query_from_kana("コンニチワ'", StyleId::new(302)) /// .await?; /// # /// # Ok(()) @@ -1792,12 +1798,12 @@ pub(crate) mod nonblocking { /// ``` /// /// [AudioQuery]: crate::AudioQuery - pub async fn audio_query_from_kana( + pub async fn create_audio_query_from_kana( &self, kana: &str, style_id: StyleId, ) -> Result { - self.0.audio_query_from_kana(kana, style_id).await + self.0.create_audio_query_from_kana(kana, style_id).await } /// AquesTalk風記法から音声合成を行う。 @@ -1862,7 +1868,7 @@ pub(crate) mod nonblocking { /// use voicevox_core::StyleId; /// /// let audio_query = synthesizer - /// .audio_query("こんにちは", StyleId::new(302)) + /// .create_audio_query("こんにちは", StyleId::new(302)) /// .await?; /// # /// # Ok(()) @@ -1870,8 +1876,12 @@ pub(crate) mod nonblocking { /// ``` /// /// [AudioQuery]: crate::AudioQuery - pub async fn audio_query(&self, text: &str, style_id: StyleId) -> Result { - self.0.audio_query(text, style_id).await + pub async fn create_audio_query( + &self, + text: &str, + style_id: StyleId, + ) -> Result { + self.0.create_audio_query(text, style_id).await } /// 日本語のテキストから音声合成を行う。 @@ -2151,7 +2161,7 @@ mod tests { "コ'レワ/テ_スト'デ_ス" )] #[tokio::test] - async fn audio_query_works( + async fn create_audio_query_works( #[case] input: Input, #[case] expected_text_consonant_vowel_data: &TextConsonantVowelData, #[case] expected_kana_text: &str, @@ -2176,10 +2186,10 @@ mod tests { let query = match input { Input::Kana(input) => { syntesizer - .audio_query_from_kana(input, StyleId::new(0)) + .create_audio_query_from_kana(input, StyleId::new(0)) .await } - Input::Japanese(input) => syntesizer.audio_query(input, StyleId::new(0)).await, + Input::Japanese(input) => syntesizer.create_audio_query(input, StyleId::new(0)).await, } .unwrap(); diff --git a/crates/voicevox_core_c_api/src/lib.rs b/crates/voicevox_core_c_api/src/lib.rs index 3f1ab4897..022ea1d52 100644 --- a/crates/voicevox_core_c_api/src/lib.rs +++ b/crates/voicevox_core_c_api/src/lib.rs @@ -757,7 +757,7 @@ pub unsafe extern "C" fn voicevox_synthesizer_create_audio_query_from_kana( let audio_query = synthesizer .body() - .audio_query_from_kana(kana, StyleId::new(style_id))?; + .create_audio_query_from_kana(kana, StyleId::new(style_id))?; let audio_query = CString::new(audio_query_model_to_json(&audio_query)) .expect("should not contain '\\0'"); output_audio_query_json @@ -806,7 +806,7 @@ pub unsafe extern "C" fn voicevox_synthesizer_create_audio_query( let audio_query = synthesizer .body() - .audio_query(text, StyleId::new(style_id))?; + .create_audio_query(text, StyleId::new(style_id))?; let audio_query = CString::new(audio_query_model_to_json(&audio_query)) .expect("should not contain '\\0'"); output_audio_query_json diff --git a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/Synthesizer.java b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/Synthesizer.java index 4b59529ee..43f5fd776 100644 --- a/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/Synthesizer.java +++ b/crates/voicevox_core_java_api/lib/src/main/java/jp/hiroshiba/voicevoxcore/blocking/Synthesizer.java @@ -115,7 +115,7 @@ public AudioQuery createAudioQueryFromKana(String kana, int styleId) throws RunM if (!Utils.isU32(styleId)) { throw new IllegalArgumentException("styleId"); } - String queryJson = rsAudioQueryFromKana(kana, styleId); + String queryJson = rsCreateAudioQueryFromKana(kana, styleId); Gson gson = new Gson(); AudioQuery audioQuery = gson.fromJson(queryJson, AudioQuery.class); @@ -138,7 +138,7 @@ public AudioQuery createAudioQuery(String text, int styleId) throws RunModelExce if (!Utils.isU32(styleId)) { throw new IllegalArgumentException("styleId"); } - String queryJson = rsAudioQuery(text, styleId); + String queryJson = rsCreateAudioQuery(text, styleId); Gson gson = new Gson(); AudioQuery audioQuery = gson.fromJson(queryJson, AudioQuery.class); @@ -300,10 +300,11 @@ public TtsConfigurator tts(String text, int styleId) { private native boolean rsIsLoadedVoiceModel(UUID voiceModelId); @Nonnull - private native String rsAudioQueryFromKana(String kana, int styleId) throws RunModelException; + private native String rsCreateAudioQueryFromKana(String kana, int styleId) + throws RunModelException; @Nonnull - private native String rsAudioQuery(String text, int styleId) throws RunModelException; + private native String rsCreateAudioQuery(String text, int styleId) throws RunModelException; @Nonnull private native String rsAccentPhrasesFromKana(String kana, int styleId) throws RunModelException; diff --git a/crates/voicevox_core_java_api/src/synthesizer.rs b/crates/voicevox_core_java_api/src/synthesizer.rs index 3487d3c50..0c60133da 100644 --- a/crates/voicevox_core_java_api/src/synthesizer.rs +++ b/crates/voicevox_core_java_api/src/synthesizer.rs @@ -183,7 +183,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rs // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsAudioQueryFromKana< +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsCreateAudioQueryFromKana< 'local, >( env: JNIEnv<'local>, @@ -202,7 +202,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rs .clone(); let audio_query = - internal.audio_query_from_kana(&kana, voicevox_core::StyleId::new(style_id))?; + internal.create_audio_query_from_kana(&kana, voicevox_core::StyleId::new(style_id))?; let query_json = serde_json::to_string(&audio_query).expect("should not fail"); @@ -214,7 +214,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rs // SAFETY: voicevox_core_java_apiを構成するライブラリの中に、これと同名のシンボルは存在しない #[unsafe(no_mangle)] -unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsAudioQuery< +unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rsCreateAudioQuery< 'local, >( env: JNIEnv<'local>, @@ -232,7 +232,8 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Synthesizer_rs )? .clone(); - let audio_query = internal.audio_query(&text, voicevox_core::StyleId::new(style_id))?; + let audio_query = + internal.create_audio_query(&text, voicevox_core::StyleId::new(style_id))?; let query_json = serde_json::to_string(&audio_query).expect("should not fail"); diff --git a/crates/voicevox_core_python_api/python/test/test_asyncio_user_dict_load.py b/crates/voicevox_core_python_api/python/test/test_asyncio_user_dict_load.py index b6fe50986..e433a7442 100644 --- a/crates/voicevox_core_python_api/python/test/test_asyncio_user_dict_load.py +++ b/crates/voicevox_core_python_api/python/test/test_asyncio_user_dict_load.py @@ -24,7 +24,7 @@ async def test_user_dict_load() -> None: await synthesizer.load_voice_model(model) - audio_query_without_dict = await synthesizer.audio_query( + audio_query_without_dict = await synthesizer.create_audio_query( "this_word_should_not_exist_in_default_dictionary", style_id=0 ) @@ -39,7 +39,7 @@ async def test_user_dict_load() -> None: await open_jtalk.use_user_dict(temp_dict) - audio_query_with_dict = await synthesizer.audio_query( + audio_query_with_dict = await synthesizer.create_audio_query( "this_word_should_not_exist_in_default_dictionary", style_id=0 ) assert audio_query_without_dict != audio_query_with_dict diff --git a/crates/voicevox_core_python_api/python/test/test_blocking_user_dict_load.py b/crates/voicevox_core_python_api/python/test/test_blocking_user_dict_load.py index e8a5bd350..9a51834f8 100644 --- a/crates/voicevox_core_python_api/python/test/test_blocking_user_dict_load.py +++ b/crates/voicevox_core_python_api/python/test/test_blocking_user_dict_load.py @@ -22,7 +22,7 @@ def test_user_dict_load() -> None: synthesizer.load_voice_model(model) - audio_query_without_dict = synthesizer.audio_query( + audio_query_without_dict = synthesizer.create_audio_query( "this_word_should_not_exist_in_default_dictionary", style_id=0 ) @@ -37,7 +37,7 @@ def test_user_dict_load() -> None: open_jtalk.use_user_dict(temp_dict) - audio_query_with_dict = synthesizer.audio_query( + audio_query_with_dict = synthesizer.create_audio_query( "this_word_should_not_exist_in_default_dictionary", style_id=0 ) assert audio_query_without_dict != audio_query_with_dict diff --git a/crates/voicevox_core_python_api/python/voicevox_core/_rust/asyncio.pyi b/crates/voicevox_core_python_api/python/voicevox_core/_rust/asyncio.pyi index d6359e038..4d665d1cc 100644 --- a/crates/voicevox_core_python_api/python/voicevox_core/_rust/asyncio.pyi +++ b/crates/voicevox_core_python_api/python/voicevox_core/_rust/asyncio.pyi @@ -218,7 +218,7 @@ class Synthesizer: モデルが読み込まれているかどうか。 """ ... - async def audio_query_from_kana( + async def create_audio_query_from_kana( self, kana: str, style_id: Union[StyleId, int], @@ -238,7 +238,7 @@ class Synthesizer: 話者とテキストから生成された :class:`AudioQuery` 。 """ ... - async def audio_query( + async def create_audio_query( self, text: str, style_id: Union[StyleId, int], diff --git a/crates/voicevox_core_python_api/python/voicevox_core/_rust/blocking.pyi b/crates/voicevox_core_python_api/python/voicevox_core/_rust/blocking.pyi index 63111acfe..2db76bc7a 100644 --- a/crates/voicevox_core_python_api/python/voicevox_core/_rust/blocking.pyi +++ b/crates/voicevox_core_python_api/python/voicevox_core/_rust/blocking.pyi @@ -219,7 +219,7 @@ class Synthesizer: モデルが読み込まれているかどうか。 """ ... - def audio_query_from_kana( + def create_audio_query_from_kana( self, kana: str, style_id: Union[StyleId, int], @@ -239,7 +239,7 @@ class Synthesizer: 話者とテキストから生成された :class:`AudioQuery` 。 """ ... - def audio_query( + def create_audio_query( self, text: str, style_id: Union[StyleId, int], diff --git a/crates/voicevox_core_python_api/src/lib.rs b/crates/voicevox_core_python_api/src/lib.rs index 9f2a9e7e1..778e9c39d 100644 --- a/crates/voicevox_core_python_api/src/lib.rs +++ b/crates/voicevox_core_python_api/src/lib.rs @@ -572,7 +572,7 @@ mod blocking { .is_loaded_voice_model(voice_model_id.into())) } - fn audio_query_from_kana<'py>( + fn create_audio_query_from_kana<'py>( &self, kana: &str, style_id: u32, @@ -581,14 +581,14 @@ mod blocking { let synthesizer = self.synthesizer.read()?; let audio_query = synthesizer - .audio_query_from_kana(kana, StyleId::new(style_id)) + .create_audio_query_from_kana(kana, StyleId::new(style_id)) .into_py_result(py)?; let class = py.import("voicevox_core")?.getattr("AudioQuery")?; crate::convert::to_pydantic_dataclass(audio_query, class) } - fn audio_query<'py>( + fn create_audio_query<'py>( &self, text: &str, style_id: u32, @@ -597,7 +597,7 @@ mod blocking { let synthesizesr = self.synthesizer.read()?; let audio_query = synthesizesr - .audio_query(text, StyleId::new(style_id)) + .create_audio_query(text, StyleId::new(style_id)) .into_py_result(py)?; let class = py.import("voicevox_core")?.getattr("AudioQuery")?; @@ -1190,7 +1190,7 @@ mod asyncio { .is_loaded_voice_model(voice_model_id.into())) } - fn audio_query_from_kana<'py>( + fn create_audio_query_from_kana<'py>( &self, kana: &str, style_id: u32, @@ -1204,7 +1204,7 @@ mod asyncio { async move { let audio_query = synthesizer .read()? - .audio_query_from_kana(&kana, StyleId::new(style_id)) + .create_audio_query_from_kana(&kana, StyleId::new(style_id)) .await; Python::with_gil(|py| { @@ -1219,7 +1219,7 @@ mod asyncio { ) } - fn audio_query<'py>( + fn create_audio_query<'py>( &self, text: &str, style_id: u32, @@ -1233,7 +1233,7 @@ mod asyncio { async move { let audio_query = synthesizer .read()? - .audio_query(&text, StyleId::new(style_id)) + .create_audio_query(&text, StyleId::new(style_id)) .await; Python::with_gil(|py| { diff --git a/example/python/run-asyncio.py b/example/python/run-asyncio.py index 176ac290f..1880f81ae 100644 --- a/example/python/run-asyncio.py +++ b/example/python/run-asyncio.py @@ -49,7 +49,7 @@ async def main() -> None: await synthesizer.load_voice_model(model) logger.info("%s", f"Creating an AudioQuery from {text!r}") - audio_query = await synthesizer.audio_query(text, style_id) + audio_query = await synthesizer.create_audio_query(text, style_id) logger.info("%s", f"Synthesizing with {display_as_json(audio_query)}") wav = await synthesizer.synthesis(audio_query, style_id) diff --git a/example/python/run.py b/example/python/run.py index caa2f36db..f5967daf7 100644 --- a/example/python/run.py +++ b/example/python/run.py @@ -47,7 +47,7 @@ def main() -> None: synthesizer.load_voice_model(model) logger.info("%s", f"Creating an AudioQuery from {text!r}") - audio_query = synthesizer.audio_query(text, style_id) + audio_query = synthesizer.create_audio_query(text, style_id) logger.info("%s", f"Synthesizing with {display_as_json(audio_query)}") if streaming: