-
Notifications
You must be signed in to change notification settings - Fork 121
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
metas
出力時に話者情報をマージする
#728
metas
出力時に話者情報をマージする
#728
Changes from 2 commits
7d0aa00
2b41763
178d5ac
e78dd4f
9d2b1a2
25a918c
d2f418d
4061678
75e55b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
pub use crate::synthesizer::blocking::PerformInference; | ||
pub use crate::{metas::merge as merge_metas, synthesizer::blocking::PerformInference}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,35 @@ use std::fmt::Display; | |
|
||
use derive_getters::Getters; | ||
use derive_new::new; | ||
use itertools::Itertools as _; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
pub fn merge<'a>(metas: impl IntoIterator<Item = &'a SpeakerMeta>) -> Vec<SpeakerMeta> { | ||
metas | ||
.into_iter() | ||
.into_grouping_map_by(|speaker| &speaker.speaker_uuid) | ||
.aggregate::<_, SpeakerMeta>(|acc, _, speaker| { | ||
Some( | ||
acc.map(|mut acc| { | ||
acc.styles.extend(speaker.styles.clone()); | ||
acc | ||
}) | ||
.unwrap_or_else(|| speaker.clone()), | ||
) | ||
}) | ||
.into_values() | ||
.map(|mut speaker| { | ||
speaker | ||
.styles | ||
.sort_unstable_by_key(|&StyleMeta { id, .. }| id); | ||
speaker | ||
}) | ||
.sorted_unstable_by_key(|SpeakerMeta { styles, .. }| { | ||
styles.first().map(|&StyleMeta { id, .. }| id) | ||
}) | ||
.collect() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 実装になんかコメントを付けようと考えましたが、別に要らないかも... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この関数の役割兼、何するかの1行ドキュメントくらいはあると道標になるかもとは思いました! (まぁ、多少知識があるとspeaker idで名寄せなのはすぐ想像できるので、なくても良いという方針でもあまり問題ないかなとも思います。) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 書きました。 |
||
|
||
/// [`StyleId`]の実体。 | ||
/// | ||
/// [`StyleId`]: StyleId | ||
|
@@ -67,6 +94,26 @@ pub struct SpeakerMeta { | |
speaker_uuid: String, | ||
} | ||
|
||
impl SpeakerMeta { | ||
pub(crate) fn eq_except_styles(&self, other: &Self) -> bool { | ||
let Self { | ||
name: name1, | ||
styles: _, | ||
version: version1, | ||
speaker_uuid: speaker_uuid1, | ||
} = self; | ||
|
||
let Self { | ||
name: name2, | ||
styles: _, | ||
version: version2, | ||
speaker_uuid: speaker_uuid2, | ||
} = other; | ||
|
||
(name1, version1, speaker_uuid1) == (name2, version2, speaker_uuid2) | ||
} | ||
} | ||
|
||
/// **スタイル**(_style_)のメタ情報。 | ||
#[derive(Deserialize, Serialize, Getters, Clone)] | ||
pub struct StyleMeta { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
エラーを一つ増設するか悩みます。別に検査しなくてもいいような気がしますし。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
どっちでもって感じかなと!
人為的なミスには気づきやすくなるので、実装があるならありがたいかもです。
todoが何するかわかってないのですが、エラー取り回し面倒という感じだと思うので、stderrにwarn吐くかpanicでも良いのかもとか思いました!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo!
はパニックを起こすものですが、これをやめてwarning止まりにするようにしました。25a918c
(#728)