mirror of
https://github.com/neodyland/sbv2-api.git
synced 2025-12-22 23:49:58 +00:00
fix
This commit is contained in:
@@ -76,7 +76,12 @@ static MORA_PATTERN: Lazy<Vec<String>> = Lazy::new(|| {
|
||||
});
|
||||
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, i32)> {
|
||||
fn phone_tone_to_kana(
|
||||
phones: Vec<String>,
|
||||
tones: Vec<i32>,
|
||||
) -> Vec<(String, Option<String>, 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<String>, tones: Vec<i32>) -> 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<String>, tones: Vec<i32>) -> 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<Vec<(String, i32)>> {
|
||||
pub fn g2kana_tone(&self) -> Result<Vec<(String, Option<String>, String, i32)>> {
|
||||
let (phones, tones, _) = self.g2p()?;
|
||||
Ok(phone_tone_to_kana(phones, tones))
|
||||
}
|
||||
|
||||
@@ -25,20 +25,25 @@ static MORA_LIST_ADDITIONAL: Lazy<Vec<Mora>> = Lazy::new(|| {
|
||||
data.additional
|
||||
});
|
||||
|
||||
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() {
|
||||
map.insert(
|
||||
format!(
|
||||
"{}{}",
|
||||
mora.consonant.clone().unwrap_or("".to_string()),
|
||||
mora.vowel
|
||||
),
|
||||
mora.mora.clone(),
|
||||
);
|
||||
}
|
||||
map
|
||||
});
|
||||
pub static MORA_PHONEMES_TO_MORA_KATA: Lazy<HashMap<String, (String, Option<String>, 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<HashMap<String, (Option<String>, String)>> =
|
||||
Lazy::new(|| {
|
||||
|
||||
@@ -12,11 +12,11 @@ struct RequestCreateAudioQuery {
|
||||
text: String,
|
||||
}
|
||||
|
||||
async fn create_audio_query(Query(request): Query<RequestCreateAudioQuery>) -> AppResult<()> {
|
||||
async fn create_audio_query(Query(request): Query<RequestCreateAudioQuery>) -> AppResult<String> {
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user