Skip to content

Commit

Permalink
refactor: Rust APIのSynthesizerのメソッドをビルダースタイルに
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Dec 26, 2024
1 parent babb3b7 commit 2f2cd05
Show file tree
Hide file tree
Showing 12 changed files with 574 additions and 403 deletions.
14 changes: 6 additions & 8 deletions crates/voicevox_core/src/__internal/doctest_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{ffi::OsString, path::Path};

use camino::Utf8Path;

use crate::{AccelerationMode, InitializeOptions};
use crate::AccelerationMode;

pub use crate::synthesizer::nonblocking::IntoBlocking;

Expand All @@ -13,20 +13,18 @@ pub async fn synthesizer_with_sample_voice_model(
>,
open_jtalk_dic_dir: impl AsRef<Utf8Path>,
) -> anyhow::Result<crate::nonblocking::Synthesizer<crate::nonblocking::OpenJtalk>> {
let syntesizer = crate::nonblocking::Synthesizer::new(
let syntesizer = crate::nonblocking::Synthesizer::builder(
#[cfg(feature = "load-onnxruntime")]
crate::nonblocking::Onnxruntime::load_once()
.filename(onnxruntime_dylib_path)
.exec()
.await?,
#[cfg(feature = "link-onnxruntime")]
crate::nonblocking::Onnxruntime::init_once().await?,
crate::nonblocking::OpenJtalk::new(open_jtalk_dic_dir).await?,
&InitializeOptions {
acceleration_mode: AccelerationMode::Cpu,
..Default::default()
},
)?;
)
.open_jtalk(crate::nonblocking::OpenJtalk::new(open_jtalk_dic_dir).await?)
.acceleration_mode(AccelerationMode::Cpu)
.build()?;

let model = &crate::nonblocking::VoiceModelFile::open(voice_model_path).await?;
syntesizer.load_voice_model(model).await?;
Expand Down
5 changes: 4 additions & 1 deletion crates/voicevox_core/src/__internal/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ pub mod raii;

pub use crate::{
metas::merge as merge_metas,
synthesizer::{blocking::PerformInference, MARGIN},
synthesizer::{
blocking::PerformInference, DEFAULT_CPU_NUM_THREADS, DEFAULT_ENABLE_INTERROGATIVE_UPSPEAK,
MARGIN,
},
};
7 changes: 7 additions & 0 deletions crates/voicevox_core/src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ pub mod onnxruntime {
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
pub use crate::infer::runtimes::onnxruntime::blocking::LoadOnce;
}

pub mod synthesizer {
pub use crate::synthesizer::blocking::{Builder, Synthesis, Tts, TtsFromKana};

// TODO: 後で封印する
pub use crate::synthesizer::blocking::PrecomputeRender;
}
2 changes: 1 addition & 1 deletion crates/voicevox_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub use self::{
VoiceModelMeta,
},
result::Result,
synthesizer::{AccelerationMode, InitializeOptions, SynthesisOptions, TtsOptions},
synthesizer::AccelerationMode,
user_dict::{UserDictWord, UserDictWordType},
version::VERSION,
voice_model::{RawVoiceModelId, VoiceModelId},
Expand Down
6 changes: 5 additions & 1 deletion crates/voicevox_core/src/nonblocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! [blocking]: https://docs.rs/crate/blocking
//! [pollster]: https://docs.rs/crate/pollster
//! [VOICEVOX/voicevox_core#902]: https://github.com/VOICEVOX/voicevox_core/issues/902
//! [`cpu_num_threads`]: crate::InitializeOptions::cpu_num_threads
//! [`cpu_num_threads`]: crate::nonblocking::synthesizer::Builder::cpu_num_threads
pub use crate::{
engine::open_jtalk::nonblocking::OpenJtalk,
Expand All @@ -28,3 +28,7 @@ pub mod onnxruntime {
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
pub use crate::infer::runtimes::onnxruntime::nonblocking::LoadOnce;
}

pub mod synthesizer {
pub use crate::synthesizer::nonblocking::{Builder, Synthesis, Tts, TtsFromKana};
}
Loading

0 comments on commit 2f2cd05

Please sign in to comment.