Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: ビルダーパターンの締めの"exec"/"execute"を"perform"に #911

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/voicevox_core/src/__internal/doctest_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub async fn synthesizer_with_sample_voice_model(
#[cfg(feature = "load-onnxruntime")]
crate::nonblocking::Onnxruntime::load_once()
.filename(onnxruntime_dylib_path)
.exec()
.perform()
.await?,
#[cfg(feature = "link-onnxruntime")]
crate::nonblocking::Onnxruntime::init_once().await?,
Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core/src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn test_gpu(
/// # } else {
/// # voicevox_core::blocking::Onnxruntime::LIB_VERSIONED_FILENAME
/// # })
/// # .exec()?;
/// # .perform()?;
/// #
/// let onnxruntime = Onnxruntime::get().unwrap();
/// dbg!(SupportedDevices::THIS & onnxruntime.supported_devices()?);
Expand Down
20 changes: 10 additions & 10 deletions crates/voicevox_core/src/infer/runtimes/onnxruntime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ pub(crate) mod blocking {
/// # // Windows\System32\onnxruntime.dllを回避
/// # voicevox_core::blocking::Onnxruntime::load_once()
/// # .filename(test_util::ONNXRUNTIME_DYLIB_PATH)
/// # .exec()?;
/// # .perform()?;
/// # }
/// use std::ptr;
///
/// let ort1 = voicevox_core::blocking::Onnxruntime::load_once().exec()?;
/// let ort1 = voicevox_core::blocking::Onnxruntime::load_once().perform()?;
/// let ort2 = another_lib::nonblocking::Onnxruntime::get().expect("`ort1`と同一のはず");
/// assert!(ptr::addr_eq(ort1, ort2));
/// # Ok(())
Expand Down Expand Up @@ -405,7 +405,7 @@ pub(crate) mod blocking {
{
Self::load_once()
.filename(test_util::ONNXRUNTIME_DYLIB_PATH)
.exec()
.perform()
.map_err(Into::into)
}

Expand All @@ -423,7 +423,7 @@ pub(crate) mod blocking {

/// [`Onnxruntime::load_once`]のビルダー。
#[cfg(feature = "load-onnxruntime")]
#[must_use = "this is a builder. it does nothing until `exec`uted"]
#[must_use = "this is a builder. it does nothing until `perform`ed"]
pub struct LoadOnce {
filename: std::ffi::OsString,
}
Expand Down Expand Up @@ -451,7 +451,7 @@ pub(crate) mod blocking {
}

/// 実行する。
pub fn exec(self) -> crate::Result<&'static Onnxruntime> {
pub fn perform(self) -> crate::Result<&'static Onnxruntime> {
Onnxruntime::once(|| ort::try_init_from(&self.filename, None))
}
}
Expand Down Expand Up @@ -481,10 +481,10 @@ pub(crate) mod nonblocking {
/// # // Windows\System32\onnxruntime.dllを回避
/// # voicevox_core::blocking::Onnxruntime::load_once()
/// # .filename(test_util::ONNXRUNTIME_DYLIB_PATH)
/// # .exec()?;
/// # .perform()?;
/// # }
/// let ort1 = voicevox_core::nonblocking::Onnxruntime::load_once()
/// .exec()
/// .perform()
/// .await?;
/// let ort2 = another_lib::blocking::Onnxruntime::get().expect("`ort1`と同一のはず");
/// assert_eq!(ptr_addr(ort1), ptr_addr(ort2));
Expand Down Expand Up @@ -585,7 +585,7 @@ pub(crate) mod nonblocking {
/// [`Onnxruntime::load_once`]のビルダー。
#[cfg(feature = "load-onnxruntime")]
#[derive(Default)]
#[must_use = "this is a builder. it does nothing until `exec`uted"]
#[must_use = "this is a builder. it does nothing until `perform`ed"]
pub struct LoadOnce(super::blocking::LoadOnce);

#[cfg(feature = "load-onnxruntime")]
Expand All @@ -602,8 +602,8 @@ pub(crate) mod nonblocking {
}

/// 実行する。
pub async fn exec(self) -> crate::Result<&'static Onnxruntime> {
let inner = crate::task::asyncify(|| self.0.exec()).await?;
pub async fn perform(self) -> crate::Result<&'static Onnxruntime> {
let inner = crate::task::asyncify(|| self.0.perform()).await?;
Ok(Onnxruntime::from_blocking(inner))
}
}
Expand Down
36 changes: 18 additions & 18 deletions crates/voicevox_core/src/synthesizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,10 +1203,10 @@ pub(crate) mod blocking {
/// # // Windows\System32\onnxruntime.dllを回避
/// # voicevox_core::blocking::Onnxruntime::load_once()
/// # .filename(test_util::ONNXRUNTIME_DYLIB_PATH)
/// # .exec()?;
/// # .perform()?;
/// # }
/// // FIXME: `Synthesizer`には`&mut self`なメソッドはもう無いはず
/// let mut syntesizer = Synthesizer::builder(Onnxruntime::load_once().exec()?)
/// let mut syntesizer = Synthesizer::builder(Onnxruntime::load_once().perform()?)
/// .open_jtalk(Arc::new(OpenJtalk::new(OPEN_JTALK_DIC_DIR).unwrap())) // FIXME: `Arc`は要らないはず
/// .acceleration_mode(ACCELERATION_MODE)
/// .build()?;
Expand Down Expand Up @@ -1650,7 +1650,7 @@ pub(crate) mod blocking {
}
}

#[must_use = "this is a builder. it does nothing until `exec`uted"]
#[must_use = "this is a builder. it does nothing until `perform`ed"]
pub struct PrecomputeRender<'a> {
synthesizer: InnerRefWithoutOpenJtalk<'a, SingleTasked>,
audio_query: &'a AudioQuery,
Expand All @@ -1665,14 +1665,14 @@ pub(crate) mod blocking {
}

/// 実行する。
pub fn exec(self) -> crate::Result<AudioFeature> {
pub fn perform(self) -> crate::Result<AudioFeature> {
self.synthesizer
.precompute_render(self.audio_query, self.style_id, &self.options)
.block_on()
}
}

#[must_use = "this is a builder. it does nothing until `exec`uted"]
#[must_use = "this is a builder. it does nothing until `perform`ed"]
pub struct Synthesis<'a> {
synthesizer: InnerRefWithoutOpenJtalk<'a, SingleTasked>,
audio_query: &'a AudioQuery,
Expand All @@ -1687,14 +1687,14 @@ pub(crate) mod blocking {
}

/// 実行する。
pub fn exec(self) -> crate::Result<Vec<u8>> {
pub fn perform(self) -> crate::Result<Vec<u8>> {
self.synthesizer
.synthesis(self.audio_query, self.style_id, &self.options)
.block_on()
}
}

#[must_use = "this is a builder. it does nothing until `exec`uted"]
#[must_use = "this is a builder. it does nothing until `perform`ed"]
pub struct TtsFromKana<'a> {
synthesizer: InnerRefWithoutOpenJtalk<'a, SingleTasked>,
kana: &'a str,
Expand All @@ -1709,14 +1709,14 @@ pub(crate) mod blocking {
}

/// 実行する。
pub fn exec(self) -> crate::Result<Vec<u8>> {
pub fn perform(self) -> crate::Result<Vec<u8>> {
self.synthesizer
.tts_from_kana(self.kana, self.style_id, &self.options)
.block_on()
}
}

#[must_use = "this is a builder. it does nothing until `exec`uted"]
#[must_use = "this is a builder. it does nothing until `perform`ed"]
pub struct Tts<'a, O> {
synthesizer: &'a Inner<O, SingleTasked>,
text: &'a str,
Expand All @@ -1731,7 +1731,7 @@ pub(crate) mod blocking {
}

/// 実行する。
pub fn exec(self) -> crate::Result<Vec<u8>> {
pub fn perform(self) -> crate::Result<Vec<u8>> {
self.synthesizer
.tts(self.text, self.style_id, &self.options)
.block_on()
Expand Down Expand Up @@ -1787,10 +1787,10 @@ pub(crate) mod nonblocking {
/// # // Windows\System32\onnxruntime.dllを回避
/// # voicevox_core::blocking::Onnxruntime::load_once()
/// # .filename(test_util::ONNXRUNTIME_DYLIB_PATH)
/// # .exec()?;
/// # .perform()?;
/// # }
/// // FIXME: `Synthesizer`には`&mut self`なメソッドはもう無いはず
/// let mut syntesizer = Synthesizer::builder(Onnxruntime::load_once().exec().await?)
/// let mut syntesizer = Synthesizer::builder(Onnxruntime::load_once().perform().await?)
/// .open_jtalk(Arc::new(OpenJtalk::new(OPEN_JTALK_DIC_DIR).await.unwrap())) // FIXME: `Arc`は要らないはず
/// .acceleration_mode(ACCELERATION_MODE)
/// .build()?;
Expand Down Expand Up @@ -2090,7 +2090,7 @@ pub(crate) mod nonblocking {
}
}

#[must_use = "this is a builder. it does nothing until `exec`uted"]
#[must_use = "this is a builder. it does nothing until `perform`ed"]
pub struct Synthesis<'a> {
synthesizer: InnerRefWithoutOpenJtalk<'a, BlockingThreadPool>,
audio_query: &'a AudioQuery,
Expand All @@ -2105,14 +2105,14 @@ pub(crate) mod nonblocking {
}

/// 実行する。
pub async fn exec(self) -> crate::Result<Vec<u8>> {
pub async fn perform(self) -> crate::Result<Vec<u8>> {
self.synthesizer
.synthesis(self.audio_query, self.style_id, &self.options)
.await
}
}

#[must_use = "this is a builder. it does nothing until `exec`uted"]
#[must_use = "this is a builder. it does nothing until `perform`ed"]
pub struct TtsFromKana<'a> {
synthesizer: InnerRefWithoutOpenJtalk<'a, BlockingThreadPool>,
kana: &'a str,
Expand All @@ -2127,14 +2127,14 @@ pub(crate) mod nonblocking {
}

/// 実行する。
pub async fn exec(self) -> crate::Result<Vec<u8>> {
pub async fn perform(self) -> crate::Result<Vec<u8>> {
self.synthesizer
.tts_from_kana(self.kana, self.style_id, &self.options)
.await
}
}

#[must_use = "this is a builder. it does nothing until `exec`uted"]
#[must_use = "this is a builder. it does nothing until `perform`ed"]
pub struct Tts<'a, O> {
synthesizer: &'a Inner<O, BlockingThreadPool>,
text: &'a str,
Expand All @@ -2149,7 +2149,7 @@ pub(crate) mod nonblocking {
}

/// 実行する。
pub async fn exec(self) -> crate::Result<Vec<u8>> {
pub async fn perform(self) -> crate::Result<Vec<u8>> {
self.synthesizer
.tts(self.text, self.style_id, &self.options)
.await
Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core_c_api/src/c_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl VoicevoxOnnxruntime {

let inner = voicevox_core::blocking::Onnxruntime::load_once()
.filename(ensure_utf8(filename)?)
.exec()?;
.perform()?;
Ok(Self::new(inner))
}

Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core_c_api/src/compatible_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static ERROR_MESSAGE: LazyLock<Mutex<String>> = LazyLock::new(|| Mutex::new(Stri

static ONNXRUNTIME: LazyLock<&'static voicevox_core::blocking::Onnxruntime> = LazyLock::new(|| {
voicevox_core::blocking::Onnxruntime::load_once()
.exec()
.perform()
.unwrap_or_else(|err| {
display_error(&err);
panic!("ONNX Runtimeをロードもしくは初期化ができなかったため、クラッシュします");
Expand Down
6 changes: 3 additions & 3 deletions crates/voicevox_core_c_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ pub unsafe extern "C" fn voicevox_synthesizer_synthesis(
.body()
.synthesis(&audio_query, StyleId::new(style_id))
.enable_interrogative_upspeak(enable_interrogative_upspeak)
.exec()?;
.perform()?;
U8_SLICE_OWNER.own_and_lend(wav, output_wav, output_wav_length);
Ok(())
})())
Expand Down Expand Up @@ -1149,7 +1149,7 @@ pub unsafe extern "C" fn voicevox_synthesizer_tts_from_kana(
.body()
.tts_from_kana(kana, StyleId::new(style_id))
.enable_interrogative_upspeak(enable_interrogative_upspeak)
.exec()?;
.perform()?;
U8_SLICE_OWNER.own_and_lend(output, output_wav, output_wav_length);
Ok(())
})())
Expand Down Expand Up @@ -1194,7 +1194,7 @@ pub unsafe extern "C" fn voicevox_synthesizer_tts(
.body()
.tts(text, StyleId::new(style_id))
.enable_interrogative_upspeak(enable_interrogative_upspeak)
.exec()?;
.perform()?;
U8_SLICE_OWNER.own_and_lend(output, output_wav, output_wav_length);
Ok(())
})())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* <p>シングルトンであり、インスタンスは高々一つ。
*
* <pre>
* Onnxruntime ort1 = Onnxruntime.loadOnce().exec();
* Onnxruntime ort1 = Onnxruntime.loadOnce().perform();
* Onnxruntime ort2 = Onnxruntime.get().get();
* assert ort1 == ort2;
* </pre>
Expand Down Expand Up @@ -96,7 +96,7 @@ public LoadOnce filename(@Nonnull String filename) {
*
* @return {@link Onnxruntime}。
*/
public Onnxruntime exec() {
public Onnxruntime perform() {
synchronized (Onnxruntime.class) {
if (instance == null) {
instance = new Onnxruntime(filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public List<AccentPhrase> replaceMoraPitch(List<AccentPhrase> accentPhrases, int
* @param audioQuery {@link AudioQuery}。
* @param styleId スタイルID。
* @return {@link SynthesisConfigurator}。
* @see SynthesisConfigurator#execute
* @see SynthesisConfigurator#perform
*/
@Nonnull
public SynthesisConfigurator synthesis(AudioQuery audioQuery, int styleId) {
Expand All @@ -266,7 +266,7 @@ public SynthesisConfigurator synthesis(AudioQuery audioQuery, int styleId) {
* @param kana AquesTalk風記法。
* @param styleId スタイルID。
* @return {@link TtsFromKanaConfigurator}。
* @see TtsFromKanaConfigurator#execute
* @see TtsFromKanaConfigurator#perform
*/
@Nonnull
public TtsFromKanaConfigurator ttsFromKana(String kana, int styleId) {
Expand All @@ -279,7 +279,7 @@ public TtsFromKanaConfigurator ttsFromKana(String kana, int styleId) {
* @param text 日本語のテキスト。
* @param styleId スタイルID。
* @return {@link TtsConfigurator}。
* @see TtsConfigurator#execute
* @see TtsConfigurator#perform
*/
@Nonnull
public TtsConfigurator tts(String text, int styleId) {
Expand Down Expand Up @@ -434,7 +434,7 @@ public SynthesisConfigurator interrogativeUpspeak(boolean interrogativeUpspeak)
* @throws RunModelException 推論に失敗した場合。
*/
@Nonnull
public byte[] execute() throws RunModelException {
public byte[] perform() throws RunModelException {
if (!Utils.isU32(styleId)) {
throw new IllegalArgumentException("styleId");
}
Expand Down Expand Up @@ -479,7 +479,7 @@ public TtsFromKanaConfigurator interrogativeUpspeak(boolean interrogativeUpspeak
* @throws RunModelException 推論に失敗した場合。
*/
@Nonnull
public byte[] execute() throws RunModelException {
public byte[] perform() throws RunModelException {
if (!Utils.isU32(styleId)) {
throw new IllegalArgumentException("styleId");
}
Expand Down Expand Up @@ -522,7 +522,7 @@ public TtsConfigurator interrogativeUpspeak(boolean interrogativeUpspeak) {
* @throws RunModelException 推論に失敗した場合。
*/
@Nonnull
public byte[] execute() throws RunModelException {
public byte[] perform() throws RunModelException {
if (!Utils.isU32(styleId)) {
throw new IllegalArgumentException("styleId");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected Onnxruntime loadOnnxruntime() {
final String FILENAME = "../../test_util/data/lib/" + Onnxruntime.LIB_VERSIONED_FILENAME;

try {
return Onnxruntime.loadOnce().filename(FILENAME).exec();
return Onnxruntime.loadOnce().filename(FILENAME).perform();
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void checkAudioQuery() throws RunModelException, InvalidModelDataException {
}

AudioQuery query = synthesizer.createAudioQuery("こんにちは", synthesizer.metas()[0].styles[0].id);
synthesizer.synthesis(query, synthesizer.metas()[0].styles[0].id).execute();
synthesizer.synthesis(query, synthesizer.metas()[0].styles[0].id).perform();
}

@Test
Expand Down Expand Up @@ -124,6 +124,6 @@ void checkTts() throws RunModelException, InvalidModelDataException {
try (VoiceModelFile model = openModel()) {
synthesizer.loadVoiceModel(model);
}
synthesizer.tts("こんにちは", synthesizer.metas()[0].styles[0].id).execute();
synthesizer.tts("こんにちは", synthesizer.metas()[0].styles[0].id).perform();
}
}
2 changes: 1 addition & 1 deletion crates/voicevox_core_java_api/src/onnxruntime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ unsafe extern "system" fn Java_jp_hiroshiba_voicevoxcore_blocking_Onnxruntime_rs
let filename = String::from(env.get_string(&filename)?);
let internal = voicevox_core::blocking::Onnxruntime::load_once()
.filename(filename)
.exec()?;
.perform()?;
env.set_rust_field(&this, "handle", internal)?;
Ok(())
})
Expand Down
Loading
Loading