diff --git a/crates/sbv2_core/src/jtalk.rs b/crates/sbv2_core/src/jtalk.rs index c242f65..75588ec 100644 --- a/crates/sbv2_core/src/jtalk.rs +++ b/crates/sbv2_core/src/jtalk.rs @@ -76,7 +76,12 @@ static MORA_PATTERN: Lazy> = Lazy::new(|| { }); static LONG_PATTERN: Lazy = Lazy::new(|| Regex::new(r"(\w)(ー*)").unwrap()); -fn phone_tone_to_kana(phones: Vec, tones: Vec) -> Vec<(String, i32)> { +fn phone_tone_to_kana( + phones: Vec, + tones: Vec, +) -> Vec<(String, Option, String, i32)> { + let phones = &phones[1..]; + let tones = &tones[1..]; let mut results = Vec::new(); let mut current_mora = String::new(); for ((phone, next_phone), (&tone, &next_tone)) in phones @@ -85,7 +90,7 @@ fn phone_tone_to_kana(phones: Vec, tones: Vec) -> Vec<(String, i32) .zip(tones.iter().zip(tones.iter().skip(1))) { if PUNCTUATIONS.contains(&phone.clone().as_str()) { - results.push((phone.to_string(), tone)); + results.push((phone.to_string(), None, "pau".to_string(), tone)); continue; } if CONSONANTS.contains(&phone.clone()) { @@ -94,13 +99,8 @@ fn phone_tone_to_kana(phones: Vec, tones: Vec) -> Vec<(String, i32) current_mora = phone.to_string() } else { current_mora += phone; - results.push(( - MORA_PHONEMES_TO_MORA_KATA - .get(¤t_mora) - .unwrap() - .to_string(), - tone, - )); + let (kana, consonant, vowel) = MORA_PHONEMES_TO_MORA_KATA.get(¤t_mora).unwrap(); + results.push((kana.to_string(), consonant.clone(), vowel.to_string(), tone)); current_mora = String::new(); } } @@ -196,7 +196,7 @@ impl JTalkProcess { Ok((phones, tones, new_word2ph)) } - pub fn g2kana_tone(&self) -> Result> { + pub fn g2kana_tone(&self) -> Result, String, i32)>> { let (phones, tones, _) = self.g2p()?; Ok(phone_tone_to_kana(phones, tones)) } diff --git a/crates/sbv2_core/src/mora.rs b/crates/sbv2_core/src/mora.rs index 4becd67..1f63062 100644 --- a/crates/sbv2_core/src/mora.rs +++ b/crates/sbv2_core/src/mora.rs @@ -25,20 +25,25 @@ static MORA_LIST_ADDITIONAL: Lazy> = Lazy::new(|| { data.additional }); -pub static MORA_PHONEMES_TO_MORA_KATA: Lazy> = Lazy::new(|| { - let mut map = HashMap::new(); - for mora in MORA_LIST_MINIMUM.iter() { - map.insert( - format!( - "{}{}", - mora.consonant.clone().unwrap_or("".to_string()), - mora.vowel - ), - mora.mora.clone(), - ); - } - map -}); +pub static MORA_PHONEMES_TO_MORA_KATA: Lazy, String)>> = + Lazy::new(|| { + let mut map = HashMap::new(); + for mora in MORA_LIST_MINIMUM.iter() { + map.insert( + format!( + "{}{}", + mora.consonant.clone().unwrap_or("".to_string()), + mora.vowel + ), + ( + mora.mora.clone(), + mora.consonant.clone(), + mora.vowel.clone(), + ), + ); + } + map + }); pub static MORA_KATA_TO_MORA_PHONEMES: Lazy, String)>> = Lazy::new(|| { diff --git a/crates/sbv2_voicevox/src/main.rs b/crates/sbv2_voicevox/src/main.rs index 46b2e75..a68f1c6 100644 --- a/crates/sbv2_voicevox/src/main.rs +++ b/crates/sbv2_voicevox/src/main.rs @@ -12,11 +12,11 @@ struct RequestCreateAudioQuery { text: String, } -async fn create_audio_query(Query(request): Query) -> AppResult<()> { +async fn create_audio_query(Query(request): Query) -> AppResult { let (normalized_text, process) = preprocess_parse_text(&request.text, &JTalk::new()?)?; let kana_tone_list = process.g2kana_tone()?; println!("{:?}", kana_tone_list); - Ok(()) + Ok(normalized_text) } #[tokio::main]