From dd73aca1141488a954d03c4169a4526700edbc1c Mon Sep 17 00:00:00 2001 From: Rin Iwai Date: Thu, 1 Feb 2024 16:28:38 +0900 Subject: [PATCH] refactor --- crates/voicevox_core/src/synthesizer.rs | 14 +++++++------- crates/voicevox_core/src/text_analyzer.rs | 18 ++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/crates/voicevox_core/src/synthesizer.rs b/crates/voicevox_core/src/synthesizer.rs index 59ac4db00..1a439e234 100644 --- a/crates/voicevox_core/src/synthesizer.rs +++ b/crates/voicevox_core/src/synthesizer.rs @@ -92,7 +92,7 @@ pub(crate) mod blocking { InferenceSessionOptions, }, numerics::F32Ext as _, - text_analyzer::{KanaParser, OpenJtalk, TextAnalyzer}, + text_analyzer::{KanaAnalyzer, OpenJTalkAnalyzer, TextAnalyzer}, AccentPhraseModel, AudioQueryModel, FullcontextExtractor, Result, StyleId, SupportedDevices, SynthesisOptions, VoiceModelId, VoiceModelMeta, }; @@ -104,8 +104,8 @@ pub(crate) mod blocking { /// 音声シンセサイザ。 pub struct Synthesizer { pub(super) status: Status, - open_jtalk: OpenJtalk, - kana_parser: KanaParser, + open_jtalk_analyzer: OpenJTalkAnalyzer, + kana_analyzer: KanaAnalyzer, use_gpu: bool, } @@ -178,8 +178,8 @@ pub(crate) mod blocking { return Ok(Self { status, - open_jtalk: OpenJtalk::new(open_jtalk), - kana_parser: KanaParser::new(), + open_jtalk_analyzer: OpenJTalkAnalyzer::new(open_jtalk), + kana_analyzer: KanaAnalyzer::new(), use_gpu, }); @@ -460,7 +460,7 @@ pub(crate) mod blocking { kana: &str, style_id: StyleId, ) -> Result> { - let accent_phrases = self.kana_parser.analyze(kana)?; + let accent_phrases = self.kana_analyzer.analyze(kana)?; self.replace_mora_data(&accent_phrases, style_id) } @@ -747,7 +747,7 @@ pub(crate) mod blocking { text: &str, style_id: StyleId, ) -> Result> { - let accent_phrases = self.open_jtalk.analyze(text)?; + let accent_phrases = self.open_jtalk_analyzer.analyze(text)?; self.replace_mora_data(&accent_phrases, style_id) } diff --git a/crates/voicevox_core/src/text_analyzer.rs b/crates/voicevox_core/src/text_analyzer.rs index 5e4cf1560..7f842c1f2 100644 --- a/crates/voicevox_core/src/text_analyzer.rs +++ b/crates/voicevox_core/src/text_analyzer.rs @@ -8,38 +8,36 @@ pub trait TextAnalyzer { } /// AquesTalk風記法からAccentPhraseの配列を生成するTextAnalyzer -pub struct KanaParser {} +pub struct KanaAnalyzer; -impl KanaParser { +impl KanaAnalyzer { pub fn new() -> Self { Self {} } } -impl TextAnalyzer for KanaParser { +impl TextAnalyzer for KanaAnalyzer { fn analyze(&self, text: &str) -> Result> { Ok(parse_kana(text)?) } } /// OpenJtalkからAccentPhraseの配列を生成するTextAnalyzer -pub struct OpenJtalk { - open_jtalk: O, -} +pub struct OpenJTalkAnalyzer(O); -impl OpenJtalk { +impl OpenJTalkAnalyzer { pub fn new(open_jtalk: O) -> Self { - Self { open_jtalk } + Self(open_jtalk) } } -impl TextAnalyzer for OpenJtalk { +impl TextAnalyzer for OpenJTalkAnalyzer { fn analyze(&self, text: &str) -> Result> { if text.is_empty() { return Ok(Vec::new()); } - let utterance = Utterance::extract_full_context_label(&self.open_jtalk, text)?; + let utterance = Utterance::extract_full_context_label(&self.0, text)?; let accent_phrases: Vec = utterance .breath_groups()