Skip to content

Commit

Permalink
話者情報が食い違うやつはwarning止まりにする
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Jan 27, 2024
1 parent 9d2b1a2 commit 25a918c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
14 changes: 5 additions & 9 deletions crates/voicevox_core/src/infer/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ impl<R: InferenceRuntime, D: InferenceDomain> LoadedModels<R, D> {
/// 次の場合にエラーを返す。
///
/// - 音声モデルIDかスタイルIDが`model_header`と重複するとき
/// - 同じ`speaker_uuid`で、スタイル以外でプロパティが異なっている話者があるとき
fn ensure_acceptable(&self, model_header: &VoiceModelHeader) -> LoadModelResult<()> {
let error = |context| LoadModelError {
path: model_header.path.clone(),
Expand All @@ -194,13 +193,10 @@ impl<R: InferenceRuntime, D: InferenceDomain> LoadedModels<R, D> {

let loaded = self.speakers();
let external = model_header.metas.iter();
if let Some((_loaded, _external)) =
iproduct!(loaded, external).find(|(loaded, external)| {
loaded.speaker_uuid() == external.speaker_uuid()
&& !loaded.eq_except_styles(external)
})
{
todo!("same `speaker_uuid` but different properties");
for (loaded, external) in iproduct!(loaded, external) {
if loaded.speaker_uuid() == external.speaker_uuid() {
loaded.warn_diff_except_styles(external);
}
}

let loaded = self.styles();
Expand Down Expand Up @@ -252,7 +248,7 @@ impl<R: InferenceRuntime, D: InferenceDomain> LoadedModels<R, D> {
Ok(())
}

fn speakers(&self) -> impl Iterator<Item = &SpeakerMeta> {
fn speakers(&self) -> impl Iterator<Item = &SpeakerMeta> + Clone {
self.0.values().flat_map(|LoadedModel { metas, .. }| metas)
}

Expand Down
34 changes: 30 additions & 4 deletions crates/voicevox_core/src/metas.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::fmt::Display;
use std::fmt::{Debug, Display};

use derive_getters::Getters;
use derive_new::new;
use indexmap::{IndexMap, IndexSet};
use itertools::Itertools as _;
use serde::{Deserialize, Serialize};
use tracing::warn;

/// [`speaker_uuid`]をキーとして複数の[`SpeakerMeta`]をマージする。
///
Expand Down Expand Up @@ -118,7 +119,10 @@ pub struct SpeakerMeta {
}

impl SpeakerMeta {
pub(crate) fn eq_except_styles(&self, other: &Self) -> bool {
/// # Panics
///
/// `speaker_uuid`が異なるときパニックする。
pub(crate) fn warn_diff_except_styles(&self, other: &Self) {
let Self {
name: name1,
styles: _,
Expand All @@ -137,8 +141,30 @@ impl SpeakerMeta {
style_order: style_order2,
} = other;

(name1, version1, speaker_uuid1, speaker_order1, style_order1)
== (name2, version2, speaker_uuid2, speaker_order2, style_order2)
if speaker_uuid1 != speaker_uuid2 {
panic!("must be equal: {speaker_uuid1} != {speaker_uuid2:?}");
}

warn_diff(speaker_uuid1, "name", name1, name2);
warn_diff(speaker_uuid1, "version", version1, version2);
warn_diff(
speaker_uuid1,
"speaker_order",
speaker_order1,
speaker_order2,
);
warn_diff(speaker_uuid1, "style_order", style_order1, style_order2);

fn warn_diff<T: PartialEq + Debug>(
speaker_uuid: &str,
field_name: &str,
left: &T,
right: &T,
) {
if left != right {
warn!("`{speaker_uuid}`: different `{field_name}` ({left:?} != {right:?})");
}
}
}
}

Expand Down

0 comments on commit 25a918c

Please sign in to comment.