Skip to content

Commit 2adba0f

Browse files
authored
refactor(rust): MORA_LIST_MINIMUMengine::talkから出す (#1076)
`mora_list`を`engine::talk`から`engine`直下に移し、`text2mora`だけ `full_context_label`の中に埋め込む。 Refs: #1073 See-also: #1074
1 parent 10e4ffc commit 2adba0f

File tree

5 files changed

+29
-35
lines changed

5 files changed

+29
-35
lines changed

crates/voicevox_core/src/engine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
mod acoustic_feature_extractor;
44
mod audio_file;
5+
mod mora_list;
56
pub(crate) mod talk;
67

78
pub use self::audio_file::wav_from_s16le;

crates/voicevox_core/src/engine/talk/mora_list.rs renamed to crates/voicevox_core/src/engine/mora_list.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -185,32 +185,3 @@ pub(super) const MORA_LIST_MINIMUM: &[[&str; 3]] = &[
185185
["イ", "", "i"],
186186
["ア", "", "a"],
187187
];
188-
189-
pub(crate) fn mora2text(mora: &str) -> &str {
190-
for &[text, consonant, vowel] in MORA_LIST_MINIMUM {
191-
if mora.len() >= consonant.len()
192-
&& &mora[..consonant.len()] == consonant
193-
&& &mora[consonant.len()..] == vowel
194-
{
195-
return text;
196-
}
197-
}
198-
mora
199-
}
200-
201-
#[cfg(test)]
202-
mod tests {
203-
use pretty_assertions::assert_eq;
204-
use rstest::rstest;
205-
206-
#[rstest]
207-
#[case("da", "ダ")]
208-
#[case("N", "ン")]
209-
#[case("cl", "ッ")]
210-
#[case("sho", "ショ")]
211-
#[case("u", "ウ")]
212-
#[case("fail", "fail")]
213-
fn test_mora2text(#[case] mora: &str, #[case] text: &str) {
214-
assert_eq!(super::mora2text(mora), text);
215-
}
216-
}

crates/voicevox_core/src/engine/talk.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ mod full_context_label;
22
mod interpret_query;
33
mod kana_parser;
44
mod model;
5-
mod mora_list;
65
pub(crate) mod open_jtalk;
76
pub(crate) mod text_analyzer;
87
pub(crate) mod user_dict;
@@ -11,4 +10,3 @@ pub(crate) use self::full_context_label::extract_full_context_label;
1110
pub(crate) use self::interpret_query::{initial_process, split_mora, DecoderFeature};
1211
pub(crate) use self::kana_parser::{create_kana, parse_kana, KanaParseError};
1312
pub use self::model::{AccentPhrase, AudioQuery, Mora};
14-
pub(crate) use self::mora_list::mora2text;

crates/voicevox_core/src/engine/talk/full_context_label.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use smallvec::SmallVec;
55

66
use crate::AccentPhrase;
77

8-
use super::open_jtalk::FullcontextExtractor;
8+
use super::{super::mora_list::MORA_LIST_MINIMUM, open_jtalk::FullcontextExtractor};
99

1010
#[derive(thiserror::Error, Debug)]
1111
#[error("入力テキストからのフルコンテキストラベル抽出に失敗しました: {context}")]
@@ -173,7 +173,19 @@ pub fn mora_to_text(consonant: Option<&str>, vowel: &str) -> String {
173173
}
174174
);
175175
// もしカタカナに変換できなければ、引数で与えた文字列がそのまま返ってくる
176-
super::mora2text(&mora_text).to_string()
176+
mora2text(&mora_text).to_string()
177+
}
178+
179+
fn mora2text(mora: &str) -> &str {
180+
for &[text, consonant, vowel] in MORA_LIST_MINIMUM {
181+
if mora.len() >= consonant.len()
182+
&& &mora[..consonant.len()] == consonant
183+
&& &mora[consonant.len()..] == vowel
184+
{
185+
return text;
186+
}
187+
}
188+
mora
177189
}
178190

179191
#[cfg(test)]
@@ -182,6 +194,7 @@ mod tests {
182194

183195
use ::test_util::OPEN_JTALK_DIC_DIR;
184196
use jlabel::Label;
197+
use pretty_assertions::assert_eq;
185198
use rstest::rstest;
186199
use rstest_reuse::*;
187200

@@ -452,4 +465,15 @@ mod tests {
452465
accent_phrase
453466
);
454467
}
468+
469+
#[rstest]
470+
#[case("da", "ダ")]
471+
#[case("N", "ン")]
472+
#[case("cl", "ッ")]
473+
#[case("sho", "ショ")]
474+
#[case("u", "ウ")]
475+
#[case("fail", "fail")]
476+
fn test_mora2text(#[case] mora: &str, #[case] text: &str) {
477+
assert_eq!(super::mora2text(mora), text);
478+
}
455479
}

crates/voicevox_core/src/engine/talk/kana_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::{collections::HashMap, sync::LazyLock};
22

33
use super::{
4+
super::mora_list::MORA_LIST_MINIMUM,
45
model::{AccentPhrase, Mora},
5-
mora_list::MORA_LIST_MINIMUM,
66
};
77

88
const UNVOICE_SYMBOL: char = '_';
@@ -199,7 +199,7 @@ mod tests {
199199
use pretty_assertions::assert_eq;
200200
use rstest::rstest;
201201

202-
use super::super::mora_list::MORA_LIST_MINIMUM;
202+
use super::super::super::mora_list::MORA_LIST_MINIMUM;
203203

204204
#[rstest]
205205
#[case(Some("da"), "ダ")]

0 commit comments

Comments
 (0)