Skip to content

Commit

Permalink
feat!: Synthesizer::audio_querycreate_audio_queryに改名 (#882)
Browse files Browse the repository at this point in the history
Resolves #700.

現状のC APIとJava APIと合わせる形で名前を統一する。理由としては:

1. 推論している感を出せる
    * 保証していない性質、例えば冪等性などを期待されにくくできる
2. `create_accent_phrases`と`create_audio_query`の二つをセットで目立たせ
   ることができる
  • Loading branch information
qryxip authored Dec 2, 2024
1 parent c61d5db commit 4c1297a
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 52 deletions.
4 changes: 2 additions & 2 deletions crates/voicevox_core/src/engine/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ pub struct AudioQuery {
pub pause_length_scale: (),
/// \[読み取り専用\] AquesTalk風記法。
///
/// [`Synthesizer::audio_query`]が返すもののみ`Some`となる。入力としてのAudioQueryでは無視され
/// [`Synthesizer::create_audio_query`]が返すもののみ`Some`となる。入力としてのAudioQueryでは無視され
/// る。
///
/// [`Synthesizer::audio_query`]: crate::blocking::Synthesizer::audio_query
/// [`Synthesizer::create_audio_query`]: crate::blocking::Synthesizer::create_audio_query
pub kana: Option<String>,
}

Expand Down
48 changes: 29 additions & 19 deletions crates/voicevox_core/src/synthesizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -745,7 +745,7 @@ mod inner {
style_id: StyleId,
options: &TtsOptions,
) -> Result<Vec<u8>> {
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
}
Expand All @@ -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,
Expand All @@ -776,7 +776,7 @@ mod inner {
style_id: StyleId,
options: &TtsOptions,
) -> Result<Vec<u8>> {
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
}
Expand Down Expand Up @@ -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<AudioQuery> {
self.0.audio_query_from_kana(kana, style_id).block_on()
self.0
.create_audio_query_from_kana(kana, style_id)
.block_on()
}

/// AquesTalk風記法から音声合成を行う。
Expand Down Expand Up @@ -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<AudioQuery> {
self.0.audio_query(text, style_id).block_on()
pub fn create_audio_query(
&self,
text: &str,
style_id: StyleId,
) -> crate::Result<AudioQuery> {
self.0.create_audio_query(text, style_id).block_on()
}

/// 日本語のテキストから音声合成を行う。
Expand Down Expand Up @@ -1784,20 +1790,20 @@ 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(())
/// # }
/// ```
///
/// [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<AudioQuery> {
self.0.audio_query_from_kana(kana, style_id).await
self.0.create_audio_query_from_kana(kana, style_id).await
}

/// AquesTalk風記法から音声合成を行う。
Expand Down Expand Up @@ -1862,16 +1868,20 @@ 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(())
/// # }
/// ```
///
/// [AudioQuery]: crate::AudioQuery
pub async fn audio_query(&self, text: &str, style_id: StyleId) -> Result<AudioQuery> {
self.0.audio_query(text, style_id).await
pub async fn create_audio_query(
&self,
text: &str,
style_id: StyleId,
) -> Result<AudioQuery> {
self.0.create_audio_query(text, style_id).await
}

/// 日本語のテキストから音声合成を行う。
Expand Down Expand Up @@ -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,
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions crates/voicevox_core_c_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions crates/voicevox_core_java_api/src/synthesizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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");

Expand All @@ -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>,
Expand All @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ class AudioQuery:
"""
[読み取り専用] AquesTalk風記法。
:func:`Synthesizer.audio_query` が返すもののみ ``str`` となる。入力としてのAudioQueryでは無視さ
れる
:func:`Synthesizer.create_audio_query` が返すもののみ ``str`` となる。入力として
のAudioQueryでは無視される
"""


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -239,7 +239,7 @@ class Synthesizer:
話者とテキストから生成された :class:`AudioQuery` 。
"""
...
def audio_query(
def create_audio_query(
self,
text: str,
style_id: Union[StyleId, int],
Expand Down
Loading

0 comments on commit 4c1297a

Please sign in to comment.