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

improve: rework VoiceModel #830

Merged
merged 18 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
112 changes: 106 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 @@ -8,6 +8,7 @@ anstream = { version = "0.5.0", default-features = false }
anstyle-query = "1.0.0"
anyhow = "1.0.65"
assert_cmd = "2.0.8"
async-fs = "2.1.2"
async_zip = "=0.0.16"
bindgen = "0.69.4"
binstall-tar = "0.4.39"
Expand All @@ -33,10 +34,10 @@ enum-map = "3.0.0-beta.1"
eyre = "0.6.8"
flate2 = "1.0.25"
fs-err = "2.11.0"
futures = "0.3.26"
futures-core = "0.3.25"
futures-util = "0.3.25"
futures-lite = "2.2.0"
futures-io = "0.3.28"
heck = "0.4.1"
humansize = "2.1.2"
indexmap = "2.0.0"
Expand Down
7 changes: 4 additions & 3 deletions crates/voicevox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ link-onnxruntime = []

[dependencies]
anyhow.workspace = true
async-fs.workspace = true
async_zip = { workspace = true, features = ["deflate"] }
camino.workspace = true
const_format.workspace = true
Expand All @@ -27,14 +28,15 @@ easy-ext.workspace = true
educe.workspace = true
enum-map.workspace = true
fs-err = { workspace = true, features = ["tokio"] }
futures.workspace = true
futures-io.workspace = true
futures-lite.workspace = true
futures-util = { workspace = true, features = ["io"] }
indexmap = { workspace = true, features = ["serde"] }
itertools.workspace = true
jlabel.workspace = true
ndarray.workspace = true
open_jtalk.workspace = true
ouroboros.workspace = true
rayon.workspace = true
ref-cast.workspace = true
regex.workspace = true
serde = { workspace = true, features = ["derive", "rc"] }
Expand All @@ -49,7 +51,6 @@ tracing.workspace = true
uuid = { workspace = true, features = ["v4", "serde"] }
voicevox-ort = { workspace = true, features = ["download-binaries", "__init-for-voicevox"] }
voicevox_core_macros = { path = "../voicevox_core_macros" }
zip.workspace = true

[dev-dependencies]
heck.workspace = true
Expand Down
56 changes: 56 additions & 0 deletions crates/voicevox_core/src/infer/domains.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,70 @@
mod talk;

use std::future::Future;

use educe::Educe;
use serde::{Deserialize, Deserializer};

pub(crate) use self::talk::{
DecodeInput, DecodeOutput, PredictDurationInput, PredictDurationOutput, PredictIntonationInput,
PredictIntonationOutput, TalkDomain, TalkOperation,
};

#[derive(Educe)]
// TODO: `bounds`に`V: ?Sized`も入れようとすると、よくわからない理由で弾かれる。最新版のeduce
// でもそうなのか?また最新版でも駄目だとしたら、弾いている理由は何なのか?
#[educe(Clone(bound = "V: InferenceDomainMapValues, V::Talk: Clone"))]
pub(crate) struct InferenceDomainMap<V: InferenceDomainMapValues + ?Sized> {
pub(crate) talk: V::Talk,
}

impl<T> InferenceDomainMap<(T,)> {
pub(crate) fn each_ref(&self) -> InferenceDomainMap<(&T,)> {
InferenceDomainMap { talk: &self.talk }
}

pub(crate) fn map<T2, Ft: FnOnce(T) -> T2>(
self,
fs: InferenceDomainMap<(Ft,)>,
) -> InferenceDomainMap<(T2,)> {
InferenceDomainMap {
talk: (fs.talk)(self.talk),
}
}
}

impl<T, E> InferenceDomainMap<(Result<T, E>,)> {
pub(crate) fn collect(self) -> Result<InferenceDomainMap<(T,)>, E> {
let talk = self.talk?;
Ok(InferenceDomainMap { talk })
}
}

impl<T: Future> InferenceDomainMap<(T,)> {
pub(crate) async fn join(self) -> InferenceDomainMap<(T::Output,)> {
let talk = self.talk.await;
InferenceDomainMap { talk }
}
}
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved

impl<'de, V: InferenceDomainMapValues + ?Sized> Deserialize<'de> for InferenceDomainMap<V>
where
V::Talk: Deserialize<'de>,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let Repr { talk } = Repr::deserialize(deserializer)?;
return Ok(Self { talk });

#[derive(Deserialize)]
struct Repr<T> {
talk: T,
}
}
}

pub(crate) trait InferenceDomainMapValues {
type Talk;
}
Expand Down
31 changes: 20 additions & 11 deletions crates/voicevox_core/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ use std::{
use derive_getters::Getters;
use derive_more::Deref;
use derive_new::new;
use macros::IndexForFields;
use serde::{de, Deserialize, Deserializer, Serialize};
use serde_with::{serde_as, DisplayFromStr};

use crate::{StyleId, VoiceModelId};
use crate::{
infer::domains::{InferenceDomainMap, TalkOperation},
StyleId, VoiceModelId,
};

#[derive(Clone)]
struct FormatVersionV1;
Expand Down Expand Up @@ -65,26 +69,31 @@ impl Display for InnerVoiceId {
}
}

#[derive(Deserialize, Getters, Clone)]
#[derive(Deserialize, Getters)]
pub struct Manifest {
#[expect(dead_code, reason = "現状はバリデーションのためだけに存在")]
vvm_format_version: FormatVersionV1,
pub(crate) id: VoiceModelId,
metas_filename: String,
#[serde(flatten)]
domains: ManifestDomains,
domains: InferenceDomainMap<ManifestDomains>,
}

#[derive(Deserialize, Clone)]
pub(crate) struct ManifestDomains {
pub(crate) talk: Option<TalkManifest>,
}
pub(crate) type ManifestDomains = (Option<TalkManifest>,);

#[derive(Deserialize, Clone)]
#[derive(Deserialize, IndexForFields)]
#[cfg_attr(test, derive(Default))]
#[index_for_fields(TalkOperation)]
pub(crate) struct TalkManifest {
pub(crate) predict_duration_filename: String,
pub(crate) predict_intonation_filename: String,
pub(crate) decode_filename: String,
#[index_for_fields(TalkOperation::PredictDuration)]
pub(crate) predict_duration_filename: Arc<str>,

#[index_for_fields(TalkOperation::PredictIntonation)]
pub(crate) predict_intonation_filename: Arc<str>,

#[index_for_fields(TalkOperation::Decode)]
pub(crate) decode_filename: Arc<str>,

#[serde(default)]
pub(crate) style_id_to_inner_voice_id: StyleIdToInnerVoiceId,
}
Expand Down
Loading
Loading