feat: Sprachausgabe über das Gateway (POST /v1/audio/speech, Adapter tts für das Qwen3-TTS Studio) (#1060)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GmHhg3Td16J38kAyDLzb39
This commit is contained in:
2026-11-17 19:44:56 +01:00
parent bdca8e0054
commit 9dd8037b64
17 changed files with 493 additions and 12 deletions

View File

@ -178,7 +178,20 @@ async fn fake_backend() -> u16 {
.unwrap()
}
}
// Sprachausgabe: liefert ein winziges „Audio“ und gibt die gesehenen Felder im Kopf zurück.
async fn speech(body: Bytes) -> Response {
let req: Value = serde_json::from_slice(&body).unwrap();
Response::builder()
.header(CONTENT_TYPE, "audio/wav")
.body(Body::from(format!(
"RIFF|{}|{}",
req["model"].as_str().unwrap_or(""),
req["input"].as_str().unwrap_or("")
)))
.unwrap()
}
serve(Router::new()
.route("/v1/audio/speech", post(speech))
.route("/", axum::routing::get(|| async { axum::response::Html("<html><script src='/app.js'></script>ENGINE-INHALT-NICHT-AUSLIEFERN</html>") }))
.route("/v1/chat/completions", post(chat))).await
}
@ -496,6 +509,37 @@ async fn chat_ohne_streaming_startet_die_instanz_und_reicht_die_antwort_durch()
assert_eq!(gw.engine.starts.load(Ordering::SeqCst), 1);
}
#[tokio::test]
async fn sprachausgabe_reicht_audio_durch_und_verlangt_key_und_modell() {
let gw = gateway(0, false).await;
let body = json!({"model": "bonsai", "input": "Hallo", "voice": "Vivian"}).to_string();
let post = |key: Option<&str>, body: String| {
let mut req = gw
.client
.post(format!("{}/v1/audio/speech", gw.base))
.header(CONTENT_TYPE, "application/json")
.body(body);
if let Some(k) = key {
req = req.bearer_auth(k);
}
async move { req.send().await.unwrap() }
};
let resp = post(Some(&gw.key), body.clone()).await;
assert_eq!(resp.status(), 200);
assert_eq!(resp.headers()[CONTENT_TYPE], "audio/wav");
// Die Attrappe gibt zurück, was sie gesehen hat: Modellname und Text unverändert.
assert_eq!(resp.text().await.unwrap(), "RIFF|bonsai|Hallo");
assert_eq!(gw.engine.starts.load(Ordering::SeqCst), 1);
assert_eq!(post(None, body.clone()).await.status(), 401);
let unbekannt = json!({"model": "gibt-es-nicht", "input": "x", "voice": "v"}).to_string();
assert_eq!(post(Some(&gw.key), unbekannt).await.status(), 404);
assert_eq!(
post(Some(&gw.key), "kein json".to_string()).await.status(),
400
);
}
#[tokio::test]
async fn streaming_wird_stueckweise_durchgereicht_und_nicht_gepuffert() {
let gw = gateway(0, false).await;