Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
eyr1n committed Feb 1, 2024
1 parent 2d377e7 commit dd73aca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
14 changes: 7 additions & 7 deletions crates/voicevox_core/src/synthesizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -104,8 +104,8 @@ pub(crate) mod blocking {
/// 音声シンセサイザ。
pub struct Synthesizer<O> {
pub(super) status: Status<InferenceRuntimeImpl, InferenceDomainImpl>,
open_jtalk: OpenJtalk<O>,
kana_parser: KanaParser,
open_jtalk_analyzer: OpenJTalkAnalyzer<O>,
kana_analyzer: KanaAnalyzer,
use_gpu: bool,
}

Expand Down Expand Up @@ -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,
});

Expand Down Expand Up @@ -460,7 +460,7 @@ pub(crate) mod blocking {
kana: &str,
style_id: StyleId,
) -> Result<Vec<AccentPhraseModel>> {
let accent_phrases = self.kana_parser.analyze(kana)?;
let accent_phrases = self.kana_analyzer.analyze(kana)?;
self.replace_mora_data(&accent_phrases, style_id)
}

Expand Down Expand Up @@ -747,7 +747,7 @@ pub(crate) mod blocking {
text: &str,
style_id: StyleId,
) -> Result<Vec<AccentPhraseModel>> {
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)
}

Expand Down
18 changes: 8 additions & 10 deletions crates/voicevox_core/src/text_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<AccentPhraseModel>> {
Ok(parse_kana(text)?)
}
}

/// OpenJtalkからAccentPhraseの配列を生成するTextAnalyzer
pub struct OpenJtalk<O> {
open_jtalk: O,
}
pub struct OpenJTalkAnalyzer<O>(O);

impl<O> OpenJtalk<O> {
impl<O> OpenJTalkAnalyzer<O> {
pub fn new(open_jtalk: O) -> Self {
Self { open_jtalk }
Self(open_jtalk)
}
}

impl<O: FullcontextExtractor> TextAnalyzer for OpenJtalk<O> {
impl<O: FullcontextExtractor> TextAnalyzer for OpenJTalkAnalyzer<O> {
fn analyze(&self, text: &str) -> Result<Vec<AccentPhraseModel>> {
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<AccentPhraseModel> = utterance
.breath_groups()
Expand Down

0 comments on commit dd73aca

Please sign in to comment.