From 25a918cdbb6ddb3c01f4b0a511195c81e5ad4902 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sun, 28 Jan 2024 00:56:31 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A9=B1=E8=80=85=E6=83=85=E5=A0=B1=E3=81=8C?= =?UTF-8?q?=E9=A3=9F=E3=81=84=E9=81=95=E3=81=86=E3=82=84=E3=81=A4=E3=81=AF?= =?UTF-8?q?warning=E6=AD=A2=E3=81=BE=E3=82=8A=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core/src/infer/status.rs | 14 ++++------ crates/voicevox_core/src/metas.rs | 34 +++++++++++++++++++++--- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/crates/voicevox_core/src/infer/status.rs b/crates/voicevox_core/src/infer/status.rs index bef8889d3..db529e2e5 100644 --- a/crates/voicevox_core/src/infer/status.rs +++ b/crates/voicevox_core/src/infer/status.rs @@ -184,7 +184,6 @@ impl LoadedModels { /// 次の場合にエラーを返す。 /// /// - 音声モデルIDかスタイルIDが`model_header`と重複するとき - /// - 同じ`speaker_uuid`で、スタイル以外でプロパティが異なっている話者があるとき fn ensure_acceptable(&self, model_header: &VoiceModelHeader) -> LoadModelResult<()> { let error = |context| LoadModelError { path: model_header.path.clone(), @@ -194,13 +193,10 @@ impl LoadedModels { 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(); @@ -252,7 +248,7 @@ impl LoadedModels { Ok(()) } - fn speakers(&self) -> impl Iterator { + fn speakers(&self) -> impl Iterator + Clone { self.0.values().flat_map(|LoadedModel { metas, .. }| metas) } diff --git a/crates/voicevox_core/src/metas.rs b/crates/voicevox_core/src/metas.rs index 8cd67c976..ae47e1803 100644 --- a/crates/voicevox_core/src/metas.rs +++ b/crates/voicevox_core/src/metas.rs @@ -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`]をマージする。 /// @@ -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: _, @@ -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( + speaker_uuid: &str, + field_name: &str, + left: &T, + right: &T, + ) { + if left != right { + warn!("`{speaker_uuid}`: different `{field_name}` ({left:?} != {right:?})"); + } + } } }