fix api respond
This commit is contained in:
parent
f24cfdceaa
commit
2f4885305e
2 changed files with 10 additions and 5 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use axum::{Json, extract::State};
|
use axum::{Json, extract::State, http::StatusCode};
|
||||||
|
|
||||||
use crate::tts::TtsPool;
|
use crate::tts::TtsPool;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
@ -15,8 +15,9 @@ pub struct Body {
|
||||||
pub async fn handler(
|
pub async fn handler(
|
||||||
State(state): State<Arc<TtsPool>>,
|
State(state): State<Arc<TtsPool>>,
|
||||||
Json(payload): Json<Body>,
|
Json(payload): Json<Body>,
|
||||||
) -> Result<Vec<u8>, String> {
|
) -> Result<Vec<u8>, (StatusCode, String)> {
|
||||||
Ok(state
|
Ok(state
|
||||||
.synthesize(payload.text, payload.lang, payload.style_id)
|
.synthesize(payload.text, payload.lang, payload.style_id)
|
||||||
.await?)
|
.await
|
||||||
|
.map_err(|err| (StatusCode::BAD_REQUEST, err))?)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,12 @@ impl TtsPool {
|
||||||
let start_at = Instant::now();
|
let start_at = Instant::now();
|
||||||
|
|
||||||
let Some(style) = style_map.get(&job.style_id) else {
|
let Some(style) = style_map.get(&job.style_id) else {
|
||||||
job.reply
|
if let Err(_) = job
|
||||||
.send(Err(format!("Voice style {} not found", job.style_id)));
|
.reply
|
||||||
|
.send(Err(format!("Voice style {} not found", job.style_id)))
|
||||||
|
{
|
||||||
|
tracing::error!("Worker send error");
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue