mirror of
https://github.com/neodyland/sbv2-api.git
synced 2025-12-22 23:49:58 +00:00
fix: voicevox化は難しいので、独自のエディター開発をする。
This commit is contained in:
@@ -79,7 +79,7 @@ static LONG_PATTERN: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\w)(ー*)").unwrap
|
||||
fn phone_tone_to_kana(
|
||||
phones: Vec<String>,
|
||||
tones: Vec<i32>,
|
||||
) -> Vec<(String, Option<String>, 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<Vec<(String, Option<String>, String, i32)>> {
|
||||
pub fn g2kana_tone(&self) -> Result<Vec<(String, i32)>> {
|
||||
let (phones, tones, _) = self.g2p()?;
|
||||
Ok(phone_tone_to_kana(phones, tones))
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ static MORA_LIST_ADDITIONAL: Lazy<Vec<Mora>> = Lazy::new(|| {
|
||||
data.additional
|
||||
});
|
||||
|
||||
pub static MORA_PHONEMES_TO_MORA_KATA: Lazy<HashMap<String, (String, Option<String>, String)>> =
|
||||
pub static MORA_PHONEMES_TO_MORA_KATA: Lazy<HashMap<String, String>> =
|
||||
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<HashMap<String, (String, Option<Stri
|
||||
mora.consonant.clone().unwrap_or("".to_string()),
|
||||
mora.vowel
|
||||
),
|
||||
(
|
||||
mora.mora.clone(),
|
||||
mora.consonant.clone(),
|
||||
mora.vowel.clone(),
|
||||
),
|
||||
mora.mora.clone(),
|
||||
);
|
||||
}
|
||||
map
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use axum::{extract::Query, routing::get, Router};
|
||||
use axum::{extract::Query, routing::get, Router, Json};
|
||||
use sbv2_core::{jtalk::JTalk, tts_util::preprocess_parse_text};
|
||||
use serde::Deserialize;
|
||||
use tokio::net::TcpListener;
|
||||
@@ -12,11 +12,22 @@ struct RequestCreateAudioQuery {
|
||||
text: String,
|
||||
}
|
||||
|
||||
async fn create_audio_query(Query(request): Query<RequestCreateAudioQuery>) -> AppResult<String> {
|
||||
#[derive(Deserialize)]
|
||||
struct ResponseCreateAudioQuery {
|
||||
kana: String,
|
||||
tone: i32,
|
||||
}
|
||||
|
||||
async fn create_audio_query(Query(request): Query<RequestCreateAudioQuery>) -> AppResult<Json<Vec<ResponseCreateAudioQuery>>> {
|
||||
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::<Vec<_>>();
|
||||
Ok(Json(response))
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
Reference in New Issue
Block a user