Skip to content

Commit

Permalink
RustのブロッキングAPIを実装 (#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip authored Dec 4, 2023
1 parent cf4c6d3 commit 38b6ebd
Show file tree
Hide file tree
Showing 24 changed files with 678 additions and 301 deletions.
61 changes: 55 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fs-err = "2.9.0"
futures = "0.3.26"
futures-core = "0.3.25"
futures-util = "0.3.25"
heck = "0.4.0"
heck = "0.4.1"
humansize = "2.1.2"
indexmap = "2.0.0"
indicatif = "0.17.3"
Expand All @@ -49,6 +49,7 @@ ndarray = "0.15.6"
ndarray-stats = "0.5.1"
octocrab = { version = "0.19.0", default-features = false }
once_cell = "1.18.0"
ouroboros = "0.18.0"
parse-display = "0.8.2"
pretty_assertions = "1.3.0"
proc-macro2 = "1.0.69"
Expand Down
3 changes: 3 additions & 0 deletions crates/voicevox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ ndarray.workspace = true
once_cell.workspace = true
onnxruntime.workspace = true
open_jtalk.workspace = true
ouroboros.workspace = true
rayon.workspace = true
regex.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["preserve_order"] }
Expand All @@ -37,6 +39,7 @@ tokio = { workspace = true, features = ["rt"] }
tracing.workspace = true
uuid = { workspace = true, features = ["v4", "serde"] }
voicevox_core_macros = { path = "../voicevox_core_macros" }
zip.workspace = true

[dev-dependencies]
heck.workspace = true
Expand Down
10 changes: 5 additions & 5 deletions crates/voicevox_core/src/__internal/doctest_fixtures.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use std::path::Path;

use crate::{AccelerationMode, InitializeOptions, OpenJtalk, Synthesizer, VoiceModel};
use crate::{AccelerationMode, InitializeOptions};

pub async fn synthesizer_with_sample_voice_model(
open_jtalk_dic_dir: impl AsRef<Path>,
) -> anyhow::Result<Synthesizer<OpenJtalk>> {
let syntesizer = Synthesizer::new(
OpenJtalk::new(open_jtalk_dic_dir).await?,
) -> anyhow::Result<crate::tokio::Synthesizer<crate::tokio::OpenJtalk>> {
let syntesizer = crate::tokio::Synthesizer::new(
crate::tokio::OpenJtalk::new(open_jtalk_dic_dir).await?,
&InitializeOptions {
acceleration_mode: AccelerationMode::Cpu,
..Default::default()
},
)?;

let model = &VoiceModel::from_path(concat!(
let model = &crate::tokio::VoiceModel::from_path(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../model/sample.vvm",
))
Expand Down
6 changes: 6 additions & 0 deletions crates/voicevox_core/src/blocking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! ブロッキング版API。
pub use crate::{
engine::open_jtalk::blocking::OpenJtalk, synthesizer::blocking::Synthesizer,
user_dict::dict::blocking::UserDict, voice_model::blocking::VoiceModel,
};
22 changes: 11 additions & 11 deletions crates/voicevox_core/src/engine/full_context_label.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::collections::HashMap;

use super::*;
use crate::engine::open_jtalk::OpenjtalkFunctionError;
use crate::engine::open_jtalk::FullcontextExtractor;
use derive_getters::Getters;
use derive_new::new;
use once_cell::sync::Lazy;
use regex::Regex;

Expand All @@ -11,7 +12,7 @@ use regex::Regex;
pub(crate) struct FullContextLabelError {
context: ErrorKind,
#[source]
source: Option<OpenjtalkFunctionError>,
source: Option<anyhow::Error>,
}

#[derive(derive_more::Display, Debug)]
Expand Down Expand Up @@ -316,16 +317,15 @@ impl Utterance {
}

pub(crate) fn extract_full_context_label(
open_jtalk: &open_jtalk::OpenJtalk,
open_jtalk: &impl FullcontextExtractor,
text: impl AsRef<str>,
) -> Result<Self> {
let labels =
open_jtalk
.extract_fullcontext(text)
.map_err(|source| FullContextLabelError {
context: ErrorKind::OpenJtalk,
source: Some(source),
})?;
let labels = open_jtalk
.extract_fullcontext(text.as_ref())
.map_err(|source| FullContextLabelError {
context: ErrorKind::OpenJtalk,
source: Some(source),
})?;

labels
.into_iter()
Expand Down
6 changes: 2 additions & 4 deletions crates/voicevox_core/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ mod full_context_label;
mod kana_parser;
mod model;
mod mora_list;
mod open_jtalk;

use super::*;
pub(crate) mod open_jtalk;

pub use self::acoustic_feature_extractor::*;
pub use self::full_context_label::*;
pub use self::kana_parser::*;
pub use self::model::*;
pub(crate) use self::mora_list::mora2text;
pub use self::open_jtalk::OpenJtalk;
pub use self::open_jtalk::FullcontextExtractor;
Loading

0 comments on commit 38b6ebd

Please sign in to comment.