This commit is contained in:
Masato Kikuchi
2025-03-28 20:08:07 +09:00
parent 70e16f95ad
commit 3785faf81e
3 changed files with 27 additions and 28 deletions

View File

@@ -76,10 +76,7 @@ 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, i32)> {
let phones = &phones[1..];
let tones = &tones[1..];
let mut results = Vec::new();

View File

@@ -25,21 +25,20 @@ 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>> = 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_KATA_TO_MORA_PHONEMES: Lazy<HashMap<String, (Option<String>, String)>> =
Lazy::new(|| {

View File

@@ -1,6 +1,6 @@
use axum::{extract::Query, routing::get, Router, Json};
use axum::{extract::Query, response::IntoResponse, routing::get, Json, Router};
use sbv2_core::{jtalk::JTalk, tts_util::preprocess_parse_text};
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use tokio::net::TcpListener;
use error::AppResult;
@@ -12,21 +12,24 @@ struct RequestCreateAudioQuery {
text: String,
}
#[derive(Deserialize)]
#[derive(Serialize)]
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()?)?;
async fn create_audio_query(
Query(request): Query<RequestCreateAudioQuery>,
) -> AppResult<impl IntoResponse> {
let (_, process) = preprocess_parse_text(&request.text, &JTalk::new()?)?;
let kana_tone_list = process.g2kana_tone()?;
let response = kana_tone_list.iter().map(|(kana, tone)| {
ResponseCreateAudioQuery {
let response = kana_tone_list
.iter()
.map(|(kana, tone)| ResponseCreateAudioQuery {
kana: kana.clone(),
tone: *tone,
}
}).collect::<Vec<_>>();
})
.collect::<Vec<_>>();
Ok(Json(response))
}