Skip to content

Commit 10e4ffc

Browse files
authored
refactor(rust): crate::engineの大半をcrate::engine::talkに (#1074)
Rust APIの`crate::engine`にあるアイテムを、`acoustic_feature_extractor` と`audio_file`を除いて`crate::engine::talk`に移動する。 `acoustic_feature_extractor`や`OjtPhoneme`という名前が微妙になりつつある が、考えるのは今後ということにする。 #1074 (comment) Refs: #1073 See-also: #1065
1 parent 5157f87 commit 10e4ffc

22 files changed

+46
-47
lines changed

crates/voicevox_core/src/__internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub mod doctest_fixtures;
22
pub mod interop;
33

4-
use crate::engine::user_dict;
4+
use crate::engine::talk::user_dict;
55

66
// VOICEVOX CORE内のラッパー向けの実装
77
// FIXME: 要議論: https://github.com/VOICEVOX/voicevox_core/issues/595

crates/voicevox_core/src/__internal/interop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub mod raii;
33
pub use crate::{
44
convert::ToJsonValue,
55
core::metas::merge as merge_metas,
6-
engine::user_dict::{DEFAULT_PRIORITY, DEFAULT_WORD_TYPE},
6+
engine::talk::user_dict::{DEFAULT_PRIORITY, DEFAULT_WORD_TYPE},
77
synthesizer::{
88
blocking::PerformInference, BlockingTextAnalyzerExt, NonblockingTextAnalyzerExt,
99
DEFAULT_CPU_NUM_THREADS, DEFAULT_ENABLE_INTERROGATIVE_UPSPEAK,

crates/voicevox_core/src/blocking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub use crate::{
44
core::{
55
infer::runtimes::onnxruntime::blocking::Onnxruntime, voice_model::blocking::VoiceModelFile,
66
},
7-
engine::{
7+
engine::talk::{
88
open_jtalk::blocking::OpenJtalk, text_analyzer::blocking::TextAnalyzer,
99
user_dict::dict::blocking::UserDict,
1010
},

crates/voicevox_core/src/engine.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,7 @@
22
33
mod acoustic_feature_extractor;
44
mod audio_file;
5-
mod full_context_label;
6-
mod interpret_query;
7-
mod kana_parser;
8-
mod model;
9-
mod mora_list;
10-
pub(crate) mod open_jtalk;
11-
pub(crate) mod text_analyzer;
12-
pub(crate) mod user_dict;
5+
pub(crate) mod talk;
136

14-
pub(crate) use self::acoustic_feature_extractor::OjtPhoneme;
15-
pub(crate) use self::audio_file::to_s16le_pcm;
167
pub use self::audio_file::wav_from_s16le;
17-
pub(crate) use self::full_context_label::extract_full_context_label;
18-
pub(crate) use self::interpret_query::{initial_process, split_mora, DecoderFeature};
19-
pub(crate) use self::kana_parser::{create_kana, parse_kana, KanaParseError};
20-
pub use self::model::{AccentPhrase, AudioQuery, Mora};
21-
pub(crate) use self::mora_list::mora2text;
8+
pub(crate) use self::{acoustic_feature_extractor::OjtPhoneme, audio_file::to_s16le_pcm};

crates/voicevox_core/src/engine/acoustic_feature_extractor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl OjtPhoneme {
8282
}
8383
}
8484

85-
pub(crate) fn convert(phonemes: &[OjtPhoneme]) -> Vec<OjtPhoneme> {
85+
pub(super) fn convert(phonemes: &[OjtPhoneme]) -> Vec<OjtPhoneme> {
8686
let mut phonemes = phonemes.to_owned();
8787
if let Some(first_phoneme) = phonemes.first_mut() {
8888
if first_phoneme.phoneme.contains("sil") {

crates/voicevox_core/src/engine/audio_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::io::{Cursor, Write as _};
22

3-
use super::AudioQuery;
3+
use super::talk::AudioQuery;
44

55
pub(crate) fn to_s16le_pcm<const BASE_SAMPLING_RATE: u32>(
66
wave: &[f32],
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
mod full_context_label;
2+
mod interpret_query;
3+
mod kana_parser;
4+
mod model;
5+
mod mora_list;
6+
pub(crate) mod open_jtalk;
7+
pub(crate) mod text_analyzer;
8+
pub(crate) mod user_dict;
9+
10+
pub(crate) use self::full_context_label::extract_full_context_label;
11+
pub(crate) use self::interpret_query::{initial_process, split_mora, DecoderFeature};
12+
pub(crate) use self::kana_parser::{create_kana, parse_kana, KanaParseError};
13+
pub use self::model::{AccentPhrase, AudioQuery, Mora};
14+
pub(crate) use self::mora_list::mora2text;

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::str::FromStr;
22

3-
use crate::{
4-
engine::{self, open_jtalk::FullcontextExtractor},
5-
AccentPhrase,
6-
};
73
use jlabel::Label;
84
use smallvec::SmallVec;
95

6+
use crate::AccentPhrase;
7+
8+
use super::open_jtalk::FullcontextExtractor;
9+
1010
#[derive(thiserror::Error, Debug)]
1111
#[error("入力テキストからのフルコンテキストラベル抽出に失敗しました: {context}")]
1212
pub(crate) struct FullContextLabelError {
@@ -173,27 +173,25 @@ pub fn mora_to_text(consonant: Option<&str>, vowel: &str) -> String {
173173
}
174174
);
175175
// もしカタカナに変換できなければ、引数で与えた文字列がそのまま返ってくる
176-
engine::mora2text(&mora_text).to_string()
176+
super::mora2text(&mora_text).to_string()
177177
}
178178

179179
#[cfg(test)]
180180
mod tests {
181-
use rstest_reuse::*;
181+
use std::str::FromStr;
182182

183183
use ::test_util::OPEN_JTALK_DIC_DIR;
184+
use jlabel::Label;
184185
use rstest::rstest;
186+
use rstest_reuse::*;
185187

186-
use std::str::FromStr;
188+
use crate::AccentPhrase;
187189

188-
use crate::{
189-
engine::{
190-
full_context_label::{extract_full_context_label, generate_accent_phrases},
191-
open_jtalk::FullcontextExtractor,
192-
Mora,
193-
},
194-
AccentPhrase,
190+
use super::super::{
191+
full_context_label::{extract_full_context_label, generate_accent_phrases},
192+
open_jtalk::FullcontextExtractor,
193+
Mora,
195194
};
196-
use jlabel::Label;
197195

198196
fn mora(text: &str, consonant: Option<&str>, vowel: &str) -> Mora {
199197
Mora {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! [`AudioQuery`]から特徴量を取り出す処理を集めたもの。
22
3-
use super::{full_context_label::mora_to_text, AccentPhrase, AudioQuery, Mora, OjtPhoneme};
3+
use super::{super::OjtPhoneme, full_context_label::mora_to_text, AccentPhrase, AudioQuery, Mora};
44

55
pub(crate) fn initial_process(accent_phrases: &[AccentPhrase]) -> (Vec<Mora>, Vec<OjtPhoneme>) {
66
let flatten_moras = to_flatten_moras(accent_phrases);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use std::collections::HashMap;
2-
use std::sync::LazyLock;
1+
use std::{collections::HashMap, sync::LazyLock};
32

4-
use crate::engine::{
3+
use super::{
54
model::{AccentPhrase, Mora},
65
mora_list::MORA_LIST_MINIMUM,
76
};
@@ -197,10 +196,11 @@ pub(crate) fn create_kana(accent_phrases: &[AccentPhrase]) -> String {
197196

198197
#[cfg(test)]
199198
mod tests {
200-
use crate::engine::mora_list::MORA_LIST_MINIMUM;
201199
use pretty_assertions::assert_eq;
202200
use rstest::rstest;
203201

202+
use super::super::mora_list::MORA_LIST_MINIMUM;
203+
204204
#[rstest]
205205
#[case(Some("da"), "ダ")]
206206
#[case(Some("N"), "ン")]

0 commit comments

Comments
 (0)