Skip to content

Commit

Permalink
feat!: Synthesizer::audio_querycreate_audio_queryに改名
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Dec 1, 2024
1 parent 32d7aeb commit 3122a44
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 47 deletions.
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,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
16 changes: 8 additions & 8 deletions crates/voicevox_core_python_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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")?;
Expand Down Expand Up @@ -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,
Expand All @@ -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| {
Expand All @@ -1219,7 +1219,7 @@ mod asyncio {
)
}

fn audio_query<'py>(
fn create_audio_query<'py>(
&self,
text: &str,
style_id: u32,
Expand All @@ -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| {
Expand Down
2 changes: 1 addition & 1 deletion example/python/run-asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 3122a44

Please sign in to comment.