Skip to content

Commit

Permalink
refactor: Rust APIにおけるgetterをパブリックAPIとして整える (#807)
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip authored Jul 11, 2024
1 parent e14f785 commit d66a8b0
Show file tree
Hide file tree
Showing 13 changed files with 437 additions and 409 deletions.
3 changes: 1 addition & 2 deletions crates/voicevox_core/src/devices.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use derive_getters::Getters;
use serde::{Deserialize, Serialize};

/// このライブラリで利用可能なデバイスの情報。
///
/// あくまで本ライブラリが対応しているデバイスの情報であることに注意。GPUが使える環境ではなかったと
/// しても`cuda`や`dml`は`true`を示しうる。
#[derive(Getters, Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
pub struct SupportedDevices {
/// CPUが利用可能。
///
Expand Down
188 changes: 94 additions & 94 deletions crates/voicevox_core/src/engine/full_context_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,27 @@ fn generate_accent_phrases(
let pause_mora = if ap_curr.accent_phrase_position_backward == 1
&& bg_curr.breath_group_position_backward != 1
{
Some(crate::Mora::new(
"、".into(),
None,
None,
"pau".into(),
0.,
0.,
))
Some(crate::Mora {
text: "、".into(),
consonant: None,
consonant_length: None,
vowel: "pau".into(),
vowel_length: 0.,
pitch: 0.,
})
} else {
None
};

// workaround for VOICEVOX/voicevox_engine#55
let accent = usize::from(ap_curr.accent_position).min(moras.len());

accent_phrases.push(AccentPhrase::new(
accent_phrases.push(AccentPhrase {
moras,
accent,
pause_mora,
ap_curr.is_interrogative,
))
is_interrogative: ap_curr.is_interrogative,
})
}
Ok(accent_phrases)
}
Expand Down Expand Up @@ -153,15 +153,15 @@ fn generate_moras(accent_phrase: &[Label]) -> std::result::Result<Vec<crate::Mor

fn generate_mora(consonant: Option<&Label>, vowel: &Label) -> crate::Mora {
let consonant_phoneme = consonant.and_then(|c| c.phoneme.c.to_owned());
let vowel_phoneme = vowel.phoneme.c.as_deref().unwrap();
crate::Mora::new(
mora_to_text(consonant_phoneme.as_deref(), vowel_phoneme),
consonant_phoneme,
consonant.and(Some(0.0)),
vowel_phoneme.to_string(),
0.0,
0.0,
)
let vowel = vowel.phoneme.c.clone().unwrap();
crate::Mora {
text: mora_to_text(consonant_phoneme.as_deref(), &vowel),
consonant: consonant_phoneme,
consonant_length: consonant.and(Some(0.0)),
vowel,
vowel_length: 0.0,
pitch: 0.0,
}
}

pub fn mora_to_text(consonant: Option<&str>, vowel: &str) -> String {
Expand Down Expand Up @@ -197,14 +197,14 @@ mod tests {
use jlabel::Label;

fn mora(text: &str, consonant: Option<&str>, vowel: &str) -> Mora {
Mora::new(
text.into(),
consonant.map(|c| c.into()),
consonant.and(Some(0.0)),
vowel.into(),
0.0,
0.0,
)
Mora {
text: text.into(),
consonant: consonant.map(|c| c.into()),
consonant_length: consonant.and(Some(0.0)),
vowel: vowel.into(),
vowel_length: 0.0,
pitch: 0.0,
}
}

#[template]
Expand All @@ -218,12 +218,12 @@ mod tests {
"y^e-sil+xx=xx/A:xx+xx+xx/B:xx-xx_xx/C:xx_xx+xx/D:xx+xx_xx/E:1_1!0_xx-xx/F:xx_xx#xx_xx@xx_xx|xx_xx/G:xx_xx%xx_xx_xx/H:1_1/I:xx-xx@xx+xx&xx-xx|xx+xx/J:xx_xx/K:1+1-1",
],
&[
AccentPhrase::new(
vec![mora("イェ", Some("y"), "e")],
1,
None,
false,
)
AccentPhrase {
moras: vec![mora("イェ", Some("y"), "e")],
accent: 1,
pause_mora: None,
is_interrogative: false,
}
]
)]
#[case(
Expand All @@ -236,16 +236,16 @@ mod tests {
"N^cl-sil+xx=xx/A:xx+xx+xx/B:09-xx_xx/C:xx_xx+xx/D:xx+xx_xx/E:3_3!0_xx-xx/F:xx_xx#xx_xx@xx_xx|xx_xx/G:xx_xx%xx_xx_xx/H:1_3/I:xx-xx@xx+xx&xx-xx|xx+xx/J:xx_xx/K:1+1-3",
],
&[
AccentPhrase::new(
vec![
AccentPhrase {
moras: vec![
mora("ン", None, "N"),
mora("ン", None, "N"),
mora("ッ", None, "cl"),
],
3,
None,
false,
),
accent: 3,
pause_mora: None,
is_interrogative: false,
},
]
)]
#[case(
Expand All @@ -271,28 +271,28 @@ mod tests {
"s^U-sil+xx=xx/A:xx+xx+xx/B:10-7_2/C:xx_xx+xx/D:xx+xx_xx/E:5_1!0_xx-xx/F:xx_xx#xx_xx@xx_xx|xx_xx/G:xx_xx%xx_xx_xx/H:2_8/I:xx-xx@xx+xx&xx-xx|xx+xx/J:xx_xx/K:1+2-8",
],
&[
AccentPhrase::new(
vec![
AccentPhrase {
moras: vec![
mora("コ", Some("k"), "o"),
mora("レ", Some("r"), "e"),
mora("ワ", Some("w"), "a"),
],
3,
None,
false,
),
AccentPhrase::new(
vec![
accent: 3,
pause_mora: None,
is_interrogative: false,
},
AccentPhrase {
moras: vec![
mora("テ", Some("t"), "e"),
mora("ス", Some("s"), "U"),
mora("ト", Some("t"), "o"),
mora("デ", Some("d"), "e"),
mora("ス", Some("s"), "U"),
],
1,
None,
false,
),
accent: 1,
pause_mora: None,
is_interrogative: false,
},
]
)]
#[case(
Expand Down Expand Up @@ -324,46 +324,46 @@ mod tests {
"k^u-sil+xx=xx/A:xx+xx+xx/B:05-xx_xx/C:xx_xx+xx/D:xx+xx_xx/E:4_2!1_xx-xx/F:xx_xx#xx_xx@xx_xx|xx_xx/G:xx_xx%xx_xx_xx/H:1_4/I:xx-xx@xx+xx&xx-xx|xx+xx/J:xx_xx/K:4+4-12",
],
&[
AccentPhrase::new(
vec![
AccentPhrase {
moras: vec![
mora("イ", None, "i"),
mora("チ", Some("ch"), "i"),
],
2,
Some(mora("、", None, "pau")),
false,
),
AccentPhrase::new(
vec![
accent: 2,
pause_mora: Some(mora("、", None, "pau")),
is_interrogative: false,
},
AccentPhrase {
moras: vec![
mora("セ", Some("s"), "e"),
mora("ン", None, "N"),
],
1,
Some(mora("、", None, "pau")),
false,
),
AccentPhrase::new(
vec![
accent: 1,
pause_mora: Some(mora("、", None, "pau")),
is_interrogative: false,
},
AccentPhrase {
moras: vec![
mora("ヒャ", Some("hy"), "a"),
mora("ク", Some("k"), "u"),
mora("マ", Some("m"), "a"),
mora("ン", None, "N"),
],
3,
Some(mora("、", None, "pau")),
false,
),
AccentPhrase::new(
vec![
accent: 3,
pause_mora: Some(mora("、", None, "pau")),
is_interrogative: false,
},
AccentPhrase {
moras: vec![
mora("イ", None, "i"),
mora("チ", Some("ch"), "i"),
mora("オ", None, "o"),
mora("ク", Some("k"), "u"),
],
2,
None,
true,
),
accent: 2,
pause_mora: None,
is_interrogative: true,
},
]
)]
#[case(
Expand All @@ -386,33 +386,33 @@ mod tests {
"a^a-sil+xx=xx/A:xx+xx+xx/B:09-xx_xx/C:xx_xx+xx/D:xx+xx_xx/E:1_1!0_xx-xx/F:xx_xx#xx_xx@xx_xx|xx_xx/G:xx_xx%xx_xx_xx/H:2_3/I:xx-xx@xx+xx&xx-xx|xx+xx/J:xx_xx/K:2+3-8",
],
&[
AccentPhrase::new(
vec![
AccentPhrase {
moras: vec![
mora("クヮ", Some("kw"), "a"),
mora("ル", Some("r"), "u"),
mora("テ", Some("t"), "e"),
mora("ッ", None, "cl"),
mora("ト", Some("t"), "o"),
],
3,
Some(mora("、", None, "pau")),
false,
),
AccentPhrase::new(
vec![
accent: 3,
pause_mora: Some(mora("、", None, "pau")),
is_interrogative: false,
},
AccentPhrase {
moras: vec![
mora("ア", None, "a"),
mora("ア", None, "a"),
],
1,
None,
false,
),
AccentPhrase::new(
vec![mora("ア", None, "a")],
1,
None,
false,
),
accent: 1,
pause_mora: None,
is_interrogative: false,
},
AccentPhrase {
moras: vec![mora("ア", None, "a")],
accent: 1,
pause_mora: None,
is_interrogative: false,
},
]
)]
fn label_cases(
Expand Down
Loading

0 comments on commit d66a8b0

Please sign in to comment.