Skip to content

Commit 1864975

Browse files
authored
refactor(rust): モジュールを再編する (#1065)
- 「コアとしての領分」を`crate::core`、「エンジンとしての領分」を `crate::engine`とする - `devices`, `infer`, `manifest`, `metas`, `status`, `voice_model`は`crate::core`下に置く - `text_analyzer`, `user_dict`は`crate::engine`下に置く - Rust 2015スタイルのmod.rsをやめる
1 parent 560f4ff commit 1864975

30 files changed

+201
-152
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
pub mod doctest_fixtures;
22
pub mod interop;
33

4+
use crate::engine::user_dict;
5+
46
// VOICEVOX CORE内のラッパー向けの実装
57
// FIXME: 要議論: https://github.com/VOICEVOX/voicevox_core/issues/595
68

79
pub fn to_zenkaku(surface: &str) -> String {
8-
crate::user_dict::to_zenkaku(surface)
10+
user_dict::to_zenkaku(surface)
911
}
1012

1113
pub fn validate_pronunciation(pronunciation: &str) -> crate::Result<()> {
12-
crate::user_dict::validate_pronunciation(pronunciation).map_err(Into::into)
14+
user_dict::validate_pronunciation(pronunciation).map_err(Into::into)
1315
}

crates/voicevox_core/src/__internal/interop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ pub mod raii;
22

33
pub use crate::{
44
convert::ToJsonValue,
5-
metas::merge as merge_metas,
5+
core::metas::merge as merge_metas,
6+
engine::user_dict::{DEFAULT_PRIORITY, DEFAULT_WORD_TYPE},
67
synthesizer::{
78
blocking::PerformInference, BlockingTextAnalyzerExt, NonblockingTextAnalyzerExt,
89
DEFAULT_CPU_NUM_THREADS, DEFAULT_ENABLE_INTERROGATIVE_UPSPEAK,
910
DEFAULT_HEAVY_INFERENCE_CANCELLABLE, MARGIN,
1011
},
11-
user_dict::{DEFAULT_PRIORITY, DEFAULT_WORD_TYPE},
1212
};

crates/voicevox_core/src/blocking.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
//! ブロッキング版API。
22
33
pub use crate::{
4-
engine::open_jtalk::blocking::OpenJtalk, infer::runtimes::onnxruntime::blocking::Onnxruntime,
5-
synthesizer::blocking::Synthesizer, text_analyzer::blocking::TextAnalyzer,
6-
user_dict::dict::blocking::UserDict, voice_model::blocking::VoiceModelFile,
4+
core::{
5+
infer::runtimes::onnxruntime::blocking::Onnxruntime, voice_model::blocking::VoiceModelFile,
6+
},
7+
engine::{
8+
open_jtalk::blocking::OpenJtalk, text_analyzer::blocking::TextAnalyzer,
9+
user_dict::dict::blocking::UserDict,
10+
},
11+
synthesizer::blocking::Synthesizer,
712
};
813

914
// TODO: 後で復活させる
@@ -14,7 +19,7 @@ pub use crate::synthesizer::blocking::AudioFeature as __AudioFeature;
1419
pub mod onnxruntime {
1520
#[cfg(feature = "load-onnxruntime")]
1621
#[cfg_attr(docsrs, doc(cfg(feature = "load-onnxruntime")))]
17-
pub use crate::infer::runtimes::onnxruntime::blocking::LoadOnce;
22+
pub use crate::core::infer::runtimes::onnxruntime::blocking::LoadOnce;
1823
}
1924

2025
pub mod synthesizer {

crates/voicevox_core/src/core.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
mod adjust;
1+
//! 音声モデルの取り扱いと推論に関する「コア」の領域。
2+
3+
pub(crate) mod adjust;
4+
pub(crate) mod devices;
5+
pub(crate) mod infer;
6+
mod manifest;
7+
pub(crate) mod metas;
8+
pub(crate) mod status;
9+
pub(crate) mod voice_model;
210

311
pub(crate) use self::adjust::{ensure_minimum_phoneme_length, pad_decoder_feature};
File renamed without changes.

crates/voicevox_core/src/infer.rs renamed to crates/voicevox_core/src/core/infer.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ use thiserror::Error;
1212

1313
use crate::{
1414
asyncs::{Async, BlockingThreadPool, SingleTasked},
15+
StyleType, SupportedDevices,
16+
};
17+
18+
use super::{
1519
devices::{DeviceSpec, GpuSpec},
1620
voice_model::ModelBytes,
17-
StyleType, SupportedDevices,
1821
};
1922

2023
pub(crate) trait AsyncExt: Async {
@@ -150,7 +153,7 @@ pub(crate) trait InferenceInputSignature {
150153
) -> anyhow::Result<R::RunContext>;
151154
}
152155

153-
pub(crate) trait InputScalar: Sized {
156+
trait InputScalar: Sized {
154157
const KIND: InputScalarKind;
155158

156159
// TODO: `Array`ではなく`ArrayView`を取ることができるかもしれない
@@ -210,7 +213,7 @@ pub(crate) trait InferenceOutputSignature:
210213
const PARAM_INFOS: &'static [ParamInfo<OutputScalarKind>];
211214
}
212215

213-
pub(crate) trait OutputScalar: Sized {
216+
trait OutputScalar: Sized {
214217
const KIND: OutputScalarKind;
215218
fn extract(tensor: OutputTensor) -> std::result::Result<ArrayD<Self>, ExtractError>;
216219
}

crates/voicevox_core/src/infer/domains.rs renamed to crates/voicevox_core/src/core/infer/domains.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub(crate) struct InferenceDomainMap<V: InferenceDomainMapValues + ?Sized> {
3434
}
3535

3636
impl<T, X, S, F> InferenceDomainMap<(T, X, S, F)> {
37-
pub(crate) fn each_ref(&self) -> InferenceDomainMap<(&T, &X, &S, &F)> {
37+
pub(in super::super) fn each_ref(&self) -> InferenceDomainMap<(&T, &X, &S, &F)> {
3838
let talk = &self.talk;
3939
let experimental_talk = &self.experimental_talk;
4040
let singing_teacher = &self.singing_teacher;
@@ -47,7 +47,7 @@ impl<T, X, S, F> InferenceDomainMap<(T, X, S, F)> {
4747
}
4848
}
4949

50-
pub(crate) fn map<
50+
pub(in super::super) fn map<
5151
T2,
5252
X2,
5353
S2,
@@ -74,7 +74,7 @@ impl<T, X, S, F> InferenceDomainMap<(T, X, S, F)> {
7474
}
7575

7676
impl<T, X, S, F, E> InferenceDomainMap<(Result<T, E>, Result<X, E>, Result<S, E>, Result<F, E>)> {
77-
pub(crate) fn collect(self) -> Result<InferenceDomainMap<(T, X, S, F)>, E> {
77+
pub(in super::super) fn collect(self) -> Result<InferenceDomainMap<(T, X, S, F)>, E> {
7878
let talk = self.talk?;
7979
let experimental_talk = self.experimental_talk?;
8080
let singing_teacher = self.singing_teacher?;
@@ -141,19 +141,19 @@ macro_rules! inference_domain_map_values {
141141
(
142142
::macros::substitute_type!(
143143
$body
144-
where $arg = crate::infer::domains::TalkDomain as crate::infer::InferenceDomain
144+
where $arg = crate::core::infer::domains::TalkDomain as crate::core::infer::InferenceDomain
145145
),
146146
::macros::substitute_type!(
147147
$body
148-
where $arg = crate::infer::domains::ExperimentalTalkDomain as crate::infer::InferenceDomain
148+
where $arg = crate::core::infer::domains::ExperimentalTalkDomain as crate::core::infer::InferenceDomain
149149
),
150150
::macros::substitute_type!(
151151
$body
152-
where $arg = crate::infer::domains::SingingTeacherDomain as crate::infer::InferenceDomain
152+
where $arg = crate::core::infer::domains::SingingTeacherDomain as crate::core::infer::InferenceDomain
153153
),
154154
::macros::substitute_type!(
155155
$body
156-
where $arg = crate::infer::domains::FrameDecodeDomain as crate::infer::InferenceDomain
156+
where $arg = crate::core::infer::domains::FrameDecodeDomain as crate::core::infer::InferenceDomain
157157
),
158158
)
159159
};

crates/voicevox_core/src/infer/domains/experimental_talk.rs renamed to crates/voicevox_core/src/core/infer/domains/experimental_talk.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ use macros::{InferenceInputSignature, InferenceOperation, InferenceOutputSignatu
55
use ndarray::{Array0, Array1, Array2};
66
use serde::Deserialize;
77

8-
use crate::{manifest::ExperimentalTalkManifest, StyleType};
8+
use crate::StyleType;
99

1010
use super::super::{
11-
InferenceDomain, InferenceInputSignature as _, InferenceOutputSignature as _, OutputTensor,
11+
super::manifest::ExperimentalTalkManifest, InferenceDomain, InferenceInputSignature as _,
12+
InferenceOutputSignature as _, OutputTensor,
1213
};
1314

1415
pub(crate) enum ExperimentalTalkDomain {}

crates/voicevox_core/src/infer/domains/frame_decode.rs renamed to crates/voicevox_core/src/core/infer/domains/frame_decode.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ use macros::{InferenceInputSignature, InferenceOperation, InferenceOutputSignatu
55
use ndarray::{Array1, Array2};
66
use serde::Deserialize;
77

8-
use crate::{manifest::FrameDecodeManifest, StyleType};
8+
use crate::StyleType;
99

1010
use super::super::{
11-
InferenceDomain, InferenceInputSignature as _, InferenceOutputSignature as _, OutputTensor,
11+
super::manifest::FrameDecodeManifest, InferenceDomain, InferenceInputSignature as _,
12+
InferenceOutputSignature as _, OutputTensor,
1213
};
1314

1415
pub(crate) enum FrameDecodeDomain {}

crates/voicevox_core/src/infer/domains/singing_teacher.rs renamed to crates/voicevox_core/src/core/infer/domains/singing_teacher.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ use macros::{InferenceInputSignature, InferenceOperation, InferenceOutputSignatu
55
use ndarray::{Array1, Array2};
66
use serde::Deserialize;
77

8-
use crate::{manifest::SingingTeacherManifest, StyleType};
8+
use crate::StyleType;
99

1010
use super::super::{
11-
InferenceDomain, InferenceInputSignature as _, InferenceOutputSignature as _, OutputTensor,
11+
super::manifest::SingingTeacherManifest, InferenceDomain, InferenceInputSignature as _,
12+
InferenceOutputSignature as _, OutputTensor,
1213
};
1314

1415
pub(crate) enum SingingTeacherDomain {}

0 commit comments

Comments
 (0)