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 axum::{Json, extract::State};
|
||||
use axum::{Json, extract::State, http::StatusCode};
|
||||
|
||||
use crate::tts::TtsPool;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -15,8 +15,9 @@ pub struct Body {
|
|||
pub async fn handler(
|
||||
State(state): State<Arc<TtsPool>>,
|
||||
Json(payload): Json<Body>,
|
||||
) -> Result<Vec<u8>, String> {
|
||||
) -> Result<Vec<u8>, (StatusCode, String)> {
|
||||
Ok(state
|
||||
.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 Some(style) = style_map.get(&job.style_id) else {
|
||||
job.reply
|
||||
.send(Err(format!("Voice style {} not found", job.style_id)));
|
||||
if let Err(_) = job
|
||||
.reply
|
||||
.send(Err(format!("Voice style {} not found", job.style_id)))
|
||||
{
|
||||
tracing::error!("Worker send error");
|
||||
}
|
||||
continue;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue