Merge feature/modellseite: Modellarten und Stimmenfreigabe

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GmHhg5PTXgibMTZUHzfLYM
This commit is contained in:
2026-11-18 20:35:59 +01:00
11 changed files with 429 additions and 15 deletions

View File

@ -281,6 +281,51 @@ pub(super) async fn speak(
Ok(request) => request,
Err(message) => return bad(message),
};
speak_request(state, slot, correlation, started, viewer, request, false).await
}
/// Getrennter Weg für Probehören: Text wird serverseitig festgelegt.
pub(super) async fn preview(
State(state): State<Arc<AppState>>,
Extension(slot): Extension<AccessSlot>,
Extension(RequestId(correlation)): Extension<RequestId>,
Extension(StartedAt(started)): Extension<StartedAt>,
headers: HeaderMap,
body: Bytes,
) -> Response {
let viewer = match json_viewer(&state, &headers, &slot) {
Ok(v) => v,
Err(response) => return response,
};
let Ok(input) = serde_json::from_slice::<Value>(&body) else {
return bad("Die Anfrage ist kein gültiges JSON.");
};
if input
.get("voice")
.and_then(Value::as_str)
.is_none_or(str::is_empty)
{
return bad("Die Stimme fehlt.");
}
const TESTSATZ: &str = "Guten Tag, ich bin eine Stimme von Nexus.";
let request = match build_speech_request(&json!({
"model": input.get("model"), "voice": input.get("voice"), "input": TESTSATZ
})) {
Ok(request) => request,
Err(message) => return bad(message),
};
speak_request(state, slot, correlation, started, viewer, request, true).await
}
async fn speak_request(
state: Arc<AppState>,
slot: AccessSlot,
correlation: String,
started: std::time::Instant,
viewer: super::Viewer,
request: Value,
preview: bool,
) -> Response {
let model = request["model"].as_str().unwrap_or_default();
let plan = match state.store().start_plan(model) {
Ok(Some(plan)) if plan.engine_name == "tts" && viewer.key.rights.allows(model) => plan,
@ -294,6 +339,28 @@ pub(super) async fn speak(
if !speech_offered(&state.runtime, &plan.model_path.to_string_lossy()) {
return ApiError::speech_model_not_installed().into_response();
}
let voice = request["voice"].as_str().unwrap_or_default();
let kind = voice_art(&plan.model_path.to_string_lossy());
let known = state
.runtime
.engine_voices("tts")
.await
.into_iter()
.any(|v| {
v.id == voice
&& (kind == "alle" || (kind == "gespeichert") == v.saved)
&& (preview
|| state
.store()
.voice_approved(voice, v.saved, &viewer.user)
.unwrap_or(false))
});
if !known {
return super::refused(
StatusCode::FORBIDDEN,
"Die Stimme ist nicht freigegeben oder nicht verfügbar.",
);
}
let Ok(bytes) = serde_json::to_vec(&request) else {
return ApiError::internal().into_response();
};
@ -361,10 +428,15 @@ pub(super) async fn voices(
.engine_voices(&plan.engine_name)
.await
.into_iter()
.filter(|v| match art {
"gespeichert" => v.saved,
"eingebaut" => !v.saved,
_ => true,
.filter(|v| {
(match art {
"gespeichert" => v.saved,
"eingebaut" => !v.saved,
_ => true,
}) && state
.store()
.voice_approved(&v.id, v.saved, &user.user)
.unwrap_or(false)
})
.map(|v| json!({ "id": v.id, "name": v.name, "gespeichert": v.saved }))
.collect();