Skip to content

Commit

Permalink
change: VVMにUUIDを割り振り、それをVoiceModelIdとする (#796)
Browse files Browse the repository at this point in the history
* change: VVMにUUIDを割り振り、それを`VoiceModelId`とする

* 不要となったコメントを削除

* UUIDを分解する部分を修正し、テストも追加

以下のためuuidもアップデートする。
<uuid-rs/uuid#741>
  • Loading branch information
qryxip authored May 24, 2024
1 parent 9c3a94e commit 484bd62
Show file tree
Hide file tree
Showing 26 changed files with 209 additions and 153 deletions.
17 changes: 5 additions & 12 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ libc = "0.2.134"
libloading = "0.7.3"
libtest-mimic = "0.6.0"
log = "0.4.17"
nanoid = "0.4.0"
ndarray = "0.15.6"
ndarray-stats = "0.5.1"
octocrab = { version = "0.19.0", default-features = false }
Expand Down Expand Up @@ -81,7 +80,7 @@ tracing = "0.1.37"
tracing-subscriber = "0.3.16"
typetag = "0.2.5"
url = "2.3.0"
uuid = "1.4.0"
uuid = "1.6.1"
voicevox_core = { path = "crates/voicevox_core" }
windows = "0.43.0"
zip = "0.6.3"
Expand Down
1 change: 0 additions & 1 deletion crates/voicevox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ futures.workspace = true
indexmap = { workspace = true, features = ["serde"] }
itertools.workspace = true
jlabel.workspace = true
nanoid.workspace = true
ndarray.workspace = true
once_cell.workspace = true
open_jtalk.workspace = true
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
@@ -1 +1,4 @@
pub use crate::{metas::merge as merge_metas, synthesizer::blocking::PerformInference};
pub use crate::{
metas::merge as merge_metas, synthesizer::blocking::PerformInference,
voice_model::blocking::IdRef,
};
5 changes: 2 additions & 3 deletions crates/voicevox_core/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use derive_new::new;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr};

use crate::StyleId;
use crate::{StyleId, VoiceModelId};

pub type RawManifestVersion = String;
#[derive(Deserialize, Clone, Debug, PartialEq, new)]
Expand Down Expand Up @@ -38,10 +38,9 @@ impl Display for InnerVoiceId {

#[derive(Deserialize, Getters, Clone)]
pub struct Manifest {
// FIXME: UUIDにする
// https://github.com/VOICEVOX/voicevox_core/issues/581
#[allow(dead_code)]
manifest_version: ManifestVersion,
pub(crate) id: VoiceModelId,
metas_filename: String,
#[serde(flatten)]
domains: ManifestDomains,
Expand Down
35 changes: 16 additions & 19 deletions crates/voicevox_core/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl<R: InferenceRuntime> Status<R> {
Ok(())
}

pub(crate) fn unload_model(&self, voice_model_id: &VoiceModelId) -> Result<()> {
pub(crate) fn unload_model(&self, voice_model_id: VoiceModelId) -> Result<()> {
self.loaded_models.lock().unwrap().remove(voice_model_id)
}

Expand All @@ -77,7 +77,7 @@ impl<R: InferenceRuntime> Status<R> {
self.loaded_models.lock().unwrap().ids_for::<D>(style_id)
}

pub(crate) fn is_loaded_model(&self, voice_model_id: &VoiceModelId) -> bool {
pub(crate) fn is_loaded_model(&self, voice_model_id: VoiceModelId) -> bool {
self.loaded_models
.lock()
.unwrap()
Expand All @@ -101,7 +101,7 @@ impl<R: InferenceRuntime> Status<R> {
/// `self`が`model_id`を含んでいないとき、パニックする。
pub(crate) fn run_session<I>(
&self,
model_id: &VoiceModelId,
model_id: VoiceModelId,
input: I,
) -> Result<<I::Signature as InferenceSignature>::Output>
where
Expand Down Expand Up @@ -159,7 +159,7 @@ impl<R: InferenceRuntime> LoadedModels<R> {
.and_then(|(inner_voice_ids, _)| inner_voice_ids.get(&style_id).copied())
.unwrap_or_else(|| InnerVoiceId::new(style_id.raw_id()));

Ok((model_id.clone(), inner_voice_id))
Ok((*model_id, inner_voice_id))
}

/// # Panics
Expand All @@ -168,12 +168,12 @@ impl<R: InferenceRuntime> LoadedModels<R> {
///
/// - `self`が`model_id`を含んでいないとき
/// - 対応する`InferenceDomain`が欠けているとき
fn get<I>(&self, model_id: &VoiceModelId) -> InferenceSessionCell<R, I>
fn get<I>(&self, model_id: VoiceModelId) -> InferenceSessionCell<R, I>
where
I: InferenceInputSignature,
<I::Signature as InferenceSignature>::Domain: InferenceDomainExt,
{
let (_, session_set) = self.0[model_id]
let (_, session_set) = self.0[&model_id]
.session_sets_with_inner_ids
.get::<<I::Signature as InferenceSignature>::Domain>()
.as_ref()
Expand All @@ -190,8 +190,8 @@ impl<R: InferenceRuntime> LoadedModels<R> {
session_set.get()
}

fn contains_voice_model(&self, model_id: &VoiceModelId) -> bool {
self.0.contains_key(model_id)
fn contains_voice_model(&self, model_id: VoiceModelId) -> bool {
self.0.contains_key(&model_id)
}

fn contains_style(&self, style_id: StyleId) -> bool {
Expand All @@ -216,9 +216,9 @@ impl<R: InferenceRuntime> LoadedModels<R> {
source: None,
};

if self.0.contains_key(&model_header.id) {
if self.0.contains_key(&model_header.manifest.id) {
return Err(error(LoadModelErrorKind::ModelAlreadyLoaded {
id: model_header.id.clone(),
id: model_header.manifest.id,
}));
}

Expand Down Expand Up @@ -255,7 +255,7 @@ impl<R: InferenceRuntime> LoadedModels<R> {
self.ensure_acceptable(model_header)?;

let prev = self.0.insert(
model_header.id.clone(),
model_header.manifest.id,
LoadedModel {
metas: model_header.metas.clone(),
session_sets_with_inner_ids,
Expand All @@ -265,12 +265,9 @@ impl<R: InferenceRuntime> LoadedModels<R> {
Ok(())
}

fn remove(&mut self, model_id: &VoiceModelId) -> Result<()> {
if self.0.remove(model_id).is_none() {
return Err(ErrorRepr::ModelNotFound {
model_id: model_id.clone(),
}
.into());
fn remove(&mut self, model_id: VoiceModelId) -> Result<()> {
if self.0.remove(&model_id).is_none() {
return Err(ErrorRepr::ModelNotFound { model_id }.into());
}
Ok(())
}
Expand Down Expand Up @@ -415,13 +412,13 @@ mod tests {
let model_header = vvm.header();
let model_contents = &vvm.read_inference_models().await.unwrap();
assert!(
!status.is_loaded_model(&model_header.id),
!status.is_loaded_model(model_header.manifest.id),
"model should not be loaded"
);
let result = status.insert_model(model_header, model_contents);
assert_debug_fmt_eq!(Ok(()), result);
assert!(
status.is_loaded_model(&model_header.id),
status.is_loaded_model(model_header.manifest.id),
"model should be loaded",
);
}
Expand Down
14 changes: 7 additions & 7 deletions crates/voicevox_core/src/synthesizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ pub(crate) mod blocking {
}

/// 音声モデルの読み込みを解除する。
pub fn unload_voice_model(&self, voice_model_id: &VoiceModelId) -> Result<()> {
pub fn unload_voice_model(&self, voice_model_id: VoiceModelId) -> Result<()> {
self.status.unload_model(voice_model_id)
}

/// 指定したIDの音声モデルが読み込まれているか判定する。
pub fn is_loaded_voice_model(&self, voice_model_id: &VoiceModelId) -> bool {
pub fn is_loaded_voice_model(&self, voice_model_id: VoiceModelId) -> bool {
self.status.is_loaded_model(voice_model_id)
}

Expand Down Expand Up @@ -841,7 +841,7 @@ pub(crate) mod blocking {
let PredictDurationOutput {
phoneme_length: output,
} = self.status.run_session(
&model_id,
model_id,
PredictDurationInput {
phoneme_list: ndarray::arr1(phoneme_vector),
speaker_id: ndarray::arr1(&[inner_voice_id.raw_id().into()]),
Expand Down Expand Up @@ -874,7 +874,7 @@ pub(crate) mod blocking {
let (model_id, inner_voice_id) = self.status.ids_for::<TalkDomain>(style_id)?;

let PredictIntonationOutput { f0_list: output } = self.status.run_session(
&model_id,
model_id,
PredictIntonationInput {
length: ndarray::arr0(length as i64),
vowel_phoneme_list: ndarray::arr1(vowel_phoneme_vector),
Expand Down Expand Up @@ -917,7 +917,7 @@ pub(crate) mod blocking {
);

let DecodeOutput { wave: output } = self.status.run_session(
&model_id,
model_id,
DecodeInput {
f0: ndarray::arr1(&f0_with_padding)
.into_shape([length_with_padding, 1])
Expand Down Expand Up @@ -1150,11 +1150,11 @@ pub(crate) mod tokio {
self.0.status.insert_model(model.header(), model_bytes)
}

pub fn unload_voice_model(&self, voice_model_id: &VoiceModelId) -> Result<()> {
pub fn unload_voice_model(&self, voice_model_id: VoiceModelId) -> Result<()> {
self.0.unload_voice_model(voice_model_id)
}

pub fn is_loaded_voice_model(&self, voice_model_id: &VoiceModelId) -> bool {
pub fn is_loaded_voice_model(&self, voice_model_id: VoiceModelId) -> bool {
self.0.is_loaded_voice_model(voice_model_id)
}

Expand Down
Loading

0 comments on commit 484bd62

Please sign in to comment.