From ff4f70508593835d74b79863090f59ef37ab408d Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sat, 2 Mar 2024 22:45:50 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A2=E3=82=A4=E3=83=86=E3=83=A0=E3=81=AE?= =?UTF-8?q?=E5=8F=AF=E8=A6=96=E6=80=A7=E3=82=92=E5=BF=85=E8=A6=81=E6=9C=80?= =?UTF-8?q?=E4=BD=8E=E9=99=90=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/test_util/src/lib.rs | 2 +- .../src/engine/acoustic_feature_extractor.rs | 10 ++--- .../voicevox_core/src/engine/kana_parser.rs | 2 +- crates/voicevox_core/src/engine/mora_list.rs | 2 +- crates/voicevox_core/src/infer/status.rs | 14 +++---- crates/voicevox_core/src/lib.rs | 2 +- crates/voicevox_core/src/test_util.rs | 2 +- crates/voicevox_core/src/text_analyzer.rs | 8 ++-- .../src/user_dict/part_of_speech_data.rs | 37 +++++++++---------- crates/voicevox_core/src/user_dict/word.rs | 2 +- crates/voicevox_core_c_api/src/helpers.rs | 2 +- crates/voicevox_core_java_api/src/common.rs | 4 +- .../voicevox_core_python_api/src/convert.rs | 24 ++++++------ 13 files changed, 55 insertions(+), 56 deletions(-) diff --git a/crates/test_util/src/lib.rs b/crates/test_util/src/lib.rs index 7522c81f7..03e8309b8 100644 --- a/crates/test_util/src/lib.rs +++ b/crates/test_util/src/lib.rs @@ -22,7 +22,7 @@ pub const OPEN_JTALK_DIC_DIR: &str = concat!( "/data/open_jtalk_dic_utf_8-1.11" ); -pub const EXAMPLE_DATA_JSON: &str = include_str!(concat!( +const EXAMPLE_DATA_JSON: &str = include_str!(concat!( env!("CARGO_MANIFEST_DIR"), "/data/example_data.json" )); diff --git a/crates/voicevox_core/src/engine/acoustic_feature_extractor.rs b/crates/voicevox_core/src/engine/acoustic_feature_extractor.rs index 4a30f71a5..5ee7ea540 100644 --- a/crates/voicevox_core/src/engine/acoustic_feature_extractor.rs +++ b/crates/voicevox_core/src/engine/acoustic_feature_extractor.rs @@ -61,7 +61,7 @@ static PHONEME_MAP: Lazy> = Lazy::new(|| { }); #[derive(Debug, Clone, PartialEq, new, Default, Getters)] -pub struct OjtPhoneme { +pub(crate) struct OjtPhoneme { phoneme: String, #[allow(dead_code)] start: f32, @@ -70,15 +70,15 @@ pub struct OjtPhoneme { } impl OjtPhoneme { - pub fn num_phoneme() -> usize { + pub(crate) fn num_phoneme() -> usize { PHONEME_MAP.len() } - pub fn space_phoneme() -> String { + fn space_phoneme() -> String { "pau".into() } - pub fn phoneme_id(&self) -> i64 { + pub(crate) fn phoneme_id(&self) -> i64 { if self.phoneme.is_empty() { -1 } else { @@ -86,7 +86,7 @@ impl OjtPhoneme { } } - pub fn convert(phonemes: &[OjtPhoneme]) -> Vec { + pub(crate) fn convert(phonemes: &[OjtPhoneme]) -> Vec { let mut phonemes = phonemes.to_owned(); if let Some(first_phoneme) = phonemes.first_mut() { if first_phoneme.phoneme.contains("sil") { diff --git a/crates/voicevox_core/src/engine/kana_parser.rs b/crates/voicevox_core/src/engine/kana_parser.rs index fe10c5b3f..eaa3d93c1 100644 --- a/crates/voicevox_core/src/engine/kana_parser.rs +++ b/crates/voicevox_core/src/engine/kana_parser.rs @@ -163,7 +163,7 @@ pub(crate) fn parse_kana(text: &str) -> KanaParseResult> Ok(parsed_result) } -pub fn create_kana(accent_phrases: &[AccentPhraseModel]) -> String { +pub(crate) fn create_kana(accent_phrases: &[AccentPhraseModel]) -> String { let mut text = String::new(); for phrase in accent_phrases { let moras = phrase.moras(); diff --git a/crates/voicevox_core/src/engine/mora_list.rs b/crates/voicevox_core/src/engine/mora_list.rs index 9c2c8d188..6e4b8ba2b 100644 --- a/crates/voicevox_core/src/engine/mora_list.rs +++ b/crates/voicevox_core/src/engine/mora_list.rs @@ -186,7 +186,7 @@ pub(super) const MORA_LIST_MINIMUM: &[[&str; 3]] = &[ ["ア", "", "a"], ]; -pub fn mora2text(mora: &str) -> &str { +pub(crate) fn mora2text(mora: &str) -> &str { for &[text, consonant, vowel] in MORA_LIST_MINIMUM { if mora.len() >= consonant.len() && &mora[..consonant.len()] == consonant diff --git a/crates/voicevox_core/src/infer/status.rs b/crates/voicevox_core/src/infer/status.rs index db529e2e5..2a575153d 100644 --- a/crates/voicevox_core/src/infer/status.rs +++ b/crates/voicevox_core/src/infer/status.rs @@ -31,14 +31,14 @@ pub(crate) struct Status { } impl Status { - pub fn new(session_options: EnumMap) -> Self { + pub(crate) fn new(session_options: EnumMap) -> Self { Self { loaded_models: Default::default(), session_options, } } - pub fn insert_model( + pub(crate) fn insert_model( &self, model_header: &VoiceModelHeader, model_bytes: &EnumMap>, @@ -64,11 +64,11 @@ impl Status { Ok(()) } - pub fn unload_model(&self, voice_model_id: &VoiceModelId) -> Result<()> { + pub(crate) fn unload_model(&self, voice_model_id: &VoiceModelId) -> Result<()> { self.loaded_models.lock().unwrap().remove(voice_model_id) } - pub fn metas(&self) -> VoiceModelMeta { + pub(crate) fn metas(&self) -> VoiceModelMeta { self.loaded_models.lock().unwrap().metas() } @@ -76,18 +76,18 @@ impl Status { self.loaded_models.lock().unwrap().ids_for(style_id) } - pub fn is_loaded_model(&self, voice_model_id: &VoiceModelId) -> bool { + pub(crate) fn is_loaded_model(&self, voice_model_id: &VoiceModelId) -> bool { self.loaded_models .lock() .unwrap() .contains_voice_model(voice_model_id) } - pub fn is_loaded_model_by_style_id(&self, style_id: StyleId) -> bool { + pub(crate) fn is_loaded_model_by_style_id(&self, style_id: StyleId) -> bool { self.loaded_models.lock().unwrap().contains_style(style_id) } - pub fn validate_speaker_id(&self, style_id: StyleId) -> bool { + pub(crate) fn validate_speaker_id(&self, style_id: StyleId) -> bool { self.is_loaded_model_by_style_id(style_id) } diff --git a/crates/voicevox_core/src/lib.rs b/crates/voicevox_core/src/lib.rs index c4b9834c3..7cb4abaf1 100644 --- a/crates/voicevox_core/src/lib.rs +++ b/crates/voicevox_core/src/lib.rs @@ -12,13 +12,13 @@ mod numerics; mod result; mod synthesizer; mod task; +mod text_analyzer; mod user_dict; mod version; mod voice_model; pub mod __internal; pub mod blocking; -pub mod text_analyzer; pub mod tokio; #[cfg(test)] diff --git a/crates/voicevox_core/src/test_util.rs b/crates/voicevox_core/src/test_util.rs index 926fe45bb..d60785246 100644 --- a/crates/voicevox_core/src/test_util.rs +++ b/crates/voicevox_core/src/test_util.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use crate::Result; -pub async fn open_default_vvm_file() -> crate::tokio::VoiceModel { +pub(crate) async fn open_default_vvm_file() -> crate::tokio::VoiceModel { crate::tokio::VoiceModel::from_path( ::test_util::convert_zip_vvm( PathBuf::from(env!("CARGO_WORKSPACE_DIR")) diff --git a/crates/voicevox_core/src/text_analyzer.rs b/crates/voicevox_core/src/text_analyzer.rs index b684eac7c..8540f26e0 100644 --- a/crates/voicevox_core/src/text_analyzer.rs +++ b/crates/voicevox_core/src/text_analyzer.rs @@ -3,13 +3,13 @@ use crate::{ AccentPhraseModel, FullcontextExtractor, Result, }; -pub trait TextAnalyzer { +pub(crate) trait TextAnalyzer { fn analyze(&self, text: &str) -> Result>; } /// AquesTalk風記法からAccentPhraseの配列を生成するTextAnalyzer #[derive(Clone)] -pub struct KanaAnalyzer; +pub(crate) struct KanaAnalyzer; impl TextAnalyzer for KanaAnalyzer { fn analyze(&self, text: &str) -> Result> { @@ -22,10 +22,10 @@ impl TextAnalyzer for KanaAnalyzer { /// OpenJtalkからAccentPhraseの配列を生成するTextAnalyzer #[derive(Clone)] -pub struct OpenJTalkAnalyzer(O); +pub(crate) struct OpenJTalkAnalyzer(O); impl OpenJTalkAnalyzer { - pub fn new(open_jtalk: O) -> Self { + pub(crate) fn new(open_jtalk: O) -> Self { Self(open_jtalk) } } diff --git a/crates/voicevox_core/src/user_dict/part_of_speech_data.rs b/crates/voicevox_core/src/user_dict/part_of_speech_data.rs index 76e36e389..b7bc95440 100644 --- a/crates/voicevox_core/src/user_dict/part_of_speech_data.rs +++ b/crates/voicevox_core/src/user_dict/part_of_speech_data.rs @@ -1,37 +1,36 @@ -use derive_getters::Getters; use once_cell::sync::Lazy; use std::collections::HashMap; use crate::UserDictWordType; /// 最小の優先度。 -pub static MIN_PRIORITY: u32 = 0; +pub(super) static MIN_PRIORITY: u32 = 0; /// 最大の優先度。 -pub static MAX_PRIORITY: u32 = 10; +pub(super) static MAX_PRIORITY: u32 = 10; /// 品詞ごとの情報。 -#[derive(Debug, Getters)] -pub struct PartOfSpeechDetail { +#[derive(Debug)] +pub(super) struct PartOfSpeechDetail { /// 品詞。 - pub part_of_speech: &'static str, + pub(super) part_of_speech: &'static str, /// 品詞細分類1。 - pub part_of_speech_detail_1: &'static str, + pub(super) part_of_speech_detail_1: &'static str, /// 品詞細分類2。 - pub part_of_speech_detail_2: &'static str, + pub(super) part_of_speech_detail_2: &'static str, /// 品詞細分類3。 - pub part_of_speech_detail_3: &'static str, + pub(super) part_of_speech_detail_3: &'static str, /// 文脈IDは辞書の左・右文脈IDのこと。 /// /// 参考: - pub context_id: i32, + pub(super) context_id: i32, /// コストのパーセンタイル。 - pub cost_candidates: Vec, + cost_candidates: Vec, /// アクセント結合規則の一覧。 - pub accent_associative_rules: Vec<&'static str>, + _accent_associative_rules: Vec<&'static str>, // unused for now } // 元データ: https://github.com/VOICEVOX/voicevox_engine/blob/master/voicevox_engine/part_of_speech_data.py -pub static PART_OF_SPEECH_DETAIL: Lazy> = +pub(super) static PART_OF_SPEECH_DETAIL: Lazy> = Lazy::new(|| { HashMap::from_iter([ ( @@ -45,7 +44,7 @@ pub static PART_OF_SPEECH_DETAIL: Lazy &'static [i32] { .cost_candidates } -pub fn priority2cost(context_id: i32, priority: u32) -> i32 { +pub(super) fn priority2cost(context_id: i32, priority: u32) -> i32 { let cost_candidates = search_cost_candidates(context_id); cost_candidates[(MAX_PRIORITY - priority) as usize] } diff --git a/crates/voicevox_core/src/user_dict/word.rs b/crates/voicevox_core/src/user_dict/word.rs index f2abc905d..7ed98a949 100644 --- a/crates/voicevox_core/src/user_dict/word.rs +++ b/crates/voicevox_core/src/user_dict/word.rs @@ -219,7 +219,7 @@ pub enum UserDictWordType { } impl UserDictWord { - pub fn to_mecab_format(&self) -> String { + pub(super) fn to_mecab_format(&self) -> String { let pos = PART_OF_SPEECH_DETAIL.get(&self.word_type).unwrap(); format!( "{},{},{},{},{},{},{},{},{},{},{},{},{},{}/{},{}", diff --git a/crates/voicevox_core_c_api/src/helpers.rs b/crates/voicevox_core_c_api/src/helpers.rs index d69641c34..74177db9c 100644 --- a/crates/voicevox_core_c_api/src/helpers.rs +++ b/crates/voicevox_core_c_api/src/helpers.rs @@ -63,7 +63,7 @@ pub(crate) fn into_result_code_with_error(result: CApiResult<()>) -> VoicevoxRes pub(crate) type CApiResult = std::result::Result; #[derive(Error, Debug)] -pub enum CApiError { +pub(crate) enum CApiError { #[error("{0}")] RustApi(#[from] voicevox_core::Error), #[error("UTF-8として不正な入力です")] diff --git a/crates/voicevox_core_java_api/src/common.rs b/crates/voicevox_core_java_api/src/common.rs index 0cfedf7df..71a60f5f3 100644 --- a/crates/voicevox_core_java_api/src/common.rs +++ b/crates/voicevox_core_java_api/src/common.rs @@ -29,7 +29,7 @@ macro_rules! enum_object { }; } -pub fn throw_if_err(mut env: JNIEnv<'_>, fallback: T, inner: F) -> T +pub(crate) fn throw_if_err(mut env: JNIEnv<'_>, fallback: T, inner: F) -> T where F: FnOnce(&mut JNIEnv<'_>) -> Result, { @@ -155,7 +155,7 @@ where } #[derive(From, Debug)] -pub enum JavaApiError { +pub(crate) enum JavaApiError { #[from] RustApi(voicevox_core::Error), diff --git a/crates/voicevox_core_python_api/src/convert.rs b/crates/voicevox_core_python_api/src/convert.rs index 1d315d826..3f629f90e 100644 --- a/crates/voicevox_core_python_api/src/convert.rs +++ b/crates/voicevox_core_python_api/src/convert.rs @@ -22,7 +22,7 @@ use crate::{ UseUserDictError, WordNotFoundError, }; -pub fn from_acceleration_mode(ob: &PyAny) -> PyResult { +pub(crate) fn from_acceleration_mode(ob: &PyAny) -> PyResult { let py = ob.py(); let class = py.import("voicevox_core")?.getattr("AccelerationMode")?; @@ -40,7 +40,7 @@ pub fn from_acceleration_mode(ob: &PyAny) -> PyResult { } // FIXME: `UserDict`についてはこれではなく、`PathBuf::extract`を直接使うようにする -pub fn from_utf8_path(ob: &PyAny) -> PyResult { +pub(crate) fn from_utf8_path(ob: &PyAny) -> PyResult { PathBuf::extract(ob)? .into_os_string() .into_string() @@ -48,7 +48,7 @@ pub fn from_utf8_path(ob: &PyAny) -> PyResult { .map_err(|s| PyValueError::new_err(format!("{s:?} cannot be encoded to UTF-8"))) } -pub fn from_dataclass(ob: &PyAny) -> PyResult { +pub(crate) fn from_dataclass(ob: &PyAny) -> PyResult { let py = ob.py(); let ob = py.import("dataclasses")?.call_method1("asdict", (ob,))?; @@ -59,7 +59,7 @@ pub fn from_dataclass(ob: &PyAny) -> PyResult { serde_json::from_str(json).into_py_value_result() } -pub fn to_pydantic_voice_model_meta<'py>( +pub(crate) fn to_pydantic_voice_model_meta<'py>( metas: &VoiceModelMeta, py: Python<'py>, ) -> PyResult> { @@ -74,7 +74,7 @@ pub fn to_pydantic_voice_model_meta<'py>( .collect::>>() } -pub fn to_pydantic_dataclass(x: impl Serialize, class: &PyAny) -> PyResult<&PyAny> { +pub(crate) fn to_pydantic_dataclass(x: impl Serialize, class: &PyAny) -> PyResult<&PyAny> { let py = class.py(); let x = serde_json::to_string(&x).into_py_value_result()?; @@ -108,7 +108,7 @@ pub(crate) fn blocking_modify_accent_phrases<'py>( .collect() } -pub fn async_modify_accent_phrases<'py, Fun, Fut>( +pub(crate) fn async_modify_accent_phrases<'py, Fun, Fut>( accent_phrases: &'py PyList, speaker_id: StyleId, py: Python<'py>, @@ -145,16 +145,16 @@ where ) } -pub fn to_rust_uuid(ob: &PyAny) -> PyResult { +pub(crate) fn to_rust_uuid(ob: &PyAny) -> PyResult { let uuid = ob.getattr("hex")?.extract::()?; uuid.parse::().into_py_value_result() } -pub fn to_py_uuid(py: Python<'_>, uuid: Uuid) -> PyResult { +pub(crate) fn to_py_uuid(py: Python<'_>, uuid: Uuid) -> PyResult { let uuid = uuid.hyphenated().to_string(); let uuid = py.import("uuid")?.call_method1("UUID", (uuid,))?; Ok(uuid.to_object(py)) } -pub fn to_rust_user_dict_word(ob: &PyAny) -> PyResult { +pub(crate) fn to_rust_user_dict_word(ob: &PyAny) -> PyResult { voicevox_core::UserDictWord::new( ob.getattr("surface")?.extract()?, ob.getattr("pronunciation")?.extract()?, @@ -164,7 +164,7 @@ pub fn to_rust_user_dict_word(ob: &PyAny) -> PyResult( +pub(crate) fn to_py_user_dict_word<'py>( py: Python<'py>, word: &voicevox_core::UserDictWord, ) -> PyResult<&'py PyAny> { @@ -174,14 +174,14 @@ pub fn to_py_user_dict_word<'py>( .downcast()?; to_pydantic_dataclass(word, class) } -pub fn to_rust_word_type(word_type: &PyAny) -> PyResult { +pub(crate) fn to_rust_word_type(word_type: &PyAny) -> PyResult { let name = word_type.getattr("name")?.extract::()?; serde_json::from_value::(json!(name)).into_py_value_result() } #[ext(VoicevoxCoreResultExt)] -pub impl voicevox_core::Result { +pub(crate) impl voicevox_core::Result { fn into_py_result(self, py: Python<'_>) -> PyResult { use voicevox_core::ErrorKind;