From 70e16f95adab72cc2045d802901dfe8650cead85 Mon Sep 17 00:00:00 2001 From: Masato Kikuchi Date: Fri, 28 Mar 2025 20:06:00 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20voicevox=E5=8C=96=E3=81=AF=E9=9B=A3?= =?UTF-8?q?=E3=81=97=E3=81=84=E3=81=AE=E3=81=A7=E3=80=81=E7=8B=AC=E8=87=AA?= =?UTF-8?q?=E3=81=AE=E3=82=A8=E3=83=87=E3=82=A3=E3=82=BF=E3=83=BC=E9=96=8B?= =?UTF-8?q?=E7=99=BA=E3=82=92=E3=81=99=E3=82=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 2 +- crates/sbv2_core/src/jtalk.rs | 10 +++++----- crates/sbv2_core/src/mora.rs | 8 ++------ .../{sbv2_voicevox => sbv2_editor}/Cargo.toml | 0 .../{sbv2_voicevox => sbv2_editor}/README.md | 0 .../query2.json | 0 .../src/error.rs | 0 .../src/main.rs | 19 +++++++++++++++---- 8 files changed, 23 insertions(+), 16 deletions(-) rename crates/{sbv2_voicevox => sbv2_editor}/Cargo.toml (100%) rename crates/{sbv2_voicevox => sbv2_editor}/README.md (100%) rename crates/{sbv2_voicevox => sbv2_editor}/query2.json (100%) rename crates/{sbv2_voicevox => sbv2_editor}/src/error.rs (100%) rename crates/{sbv2_voicevox => sbv2_editor}/src/main.rs (63%) diff --git a/Cargo.toml b/Cargo.toml index fcc17c0..fe3e0ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["./crates/sbv2_api", "./crates/sbv2_core", "./crates/sbv2_bindings", "./crates/sbv2_wasm", "crates/sbv2_voicevox"] +members = ["./crates/sbv2_api", "./crates/sbv2_core", "./crates/sbv2_bindings", "./crates/sbv2_wasm", "crates/sbv2_editor"] [workspace.package] version = "0.2.0-alpha6" diff --git a/crates/sbv2_core/src/jtalk.rs b/crates/sbv2_core/src/jtalk.rs index 75588ec..f73c159 100644 --- a/crates/sbv2_core/src/jtalk.rs +++ b/crates/sbv2_core/src/jtalk.rs @@ -79,7 +79,7 @@ static LONG_PATTERN: Lazy = Lazy::new(|| Regex::new(r"(\w)(ー*)").unwrap fn phone_tone_to_kana( phones: Vec, tones: Vec, -) -> Vec<(String, Option, String, i32)> { +) -> Vec<(String, i32)> { let phones = &phones[1..]; let tones = &tones[1..]; let mut results = Vec::new(); @@ -90,7 +90,7 @@ fn phone_tone_to_kana( .zip(tones.iter().zip(tones.iter().skip(1))) { if PUNCTUATIONS.contains(&phone.clone().as_str()) { - results.push((phone.to_string(), None, "pau".to_string(), tone)); + results.push((phone.to_string(), tone)); continue; } if CONSONANTS.contains(&phone.clone()) { @@ -99,8 +99,8 @@ fn phone_tone_to_kana( current_mora = phone.to_string() } else { current_mora += phone; - let (kana, consonant, vowel) = MORA_PHONEMES_TO_MORA_KATA.get(¤t_mora).unwrap(); - results.push((kana.to_string(), consonant.clone(), vowel.to_string(), tone)); + let kana = MORA_PHONEMES_TO_MORA_KATA.get(¤t_mora).unwrap(); + results.push((kana.to_string(), tone)); current_mora = String::new(); } } @@ -196,7 +196,7 @@ impl JTalkProcess { Ok((phones, tones, new_word2ph)) } - pub fn g2kana_tone(&self) -> Result, String, i32)>> { + pub fn g2kana_tone(&self) -> Result> { 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 1f63062..dfe1ea8 100644 --- a/crates/sbv2_core/src/mora.rs +++ b/crates/sbv2_core/src/mora.rs @@ -25,7 +25,7 @@ static MORA_LIST_ADDITIONAL: Lazy> = Lazy::new(|| { data.additional }); -pub static MORA_PHONEMES_TO_MORA_KATA: Lazy, String)>> = +pub static MORA_PHONEMES_TO_MORA_KATA: Lazy> = Lazy::new(|| { let mut map = HashMap::new(); for mora in MORA_LIST_MINIMUM.iter() { @@ -35,11 +35,7 @@ pub static MORA_PHONEMES_TO_MORA_KATA: Lazy) -> AppResult { +#[derive(Deserialize)] +struct ResponseCreateAudioQuery { + kana: String, + tone: i32, +} + +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(normalized_text) + let response = kana_tone_list.iter().map(|(kana, tone)| { + ResponseCreateAudioQuery { + kana: kana.clone(), + tone: *tone, + } + }).collect::>(); + Ok(Json(response)) } #[tokio::main]