feat(ui): Stimme im Playground als Auswahlliste aus dem Studio, Version 0.1.10-rc3
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GmHhg3Td16J38kAyDLzb39
This commit is contained in:
@ -21,6 +21,11 @@ pub trait Engine: Send + Sync {
|
||||
crate::types::Frontend::None
|
||||
}
|
||||
|
||||
/// Stimmen der Sprachausgabe (leer bei Engines ohne Sprachausgabe oder wenn sie nicht antwortet).
|
||||
async fn voices(&self) -> Vec<crate::types::Voice> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// Wie die Engine gestartet wird (nur zur Anzeige, ohne Geheimnisse).
|
||||
fn start_info(&self) -> StartInfo {
|
||||
StartInfo::default()
|
||||
|
||||
@ -34,5 +34,5 @@ pub use process::process_exists;
|
||||
pub use studio::{StudioConfig, StudioEngine};
|
||||
pub use types::{
|
||||
AdapterError, Capabilities, DiscoveredArtifact, Endpoint, EngineInfo, Frontend, Health,
|
||||
InstanceHandle, Mode, ProfileSpec, Protocol, Result, StartInfo, Usage,
|
||||
InstanceHandle, Mode, ProfileSpec, Protocol, Result, StartInfo, Usage, Voice,
|
||||
};
|
||||
|
||||
@ -95,6 +95,26 @@ impl StudioEngine {
|
||||
}
|
||||
}
|
||||
|
||||
/// Stimmen aus `/studio/voices` (gespeichert) oder `/tts/speakers` (eingebaut): `{"voices": [{id, name}]}`.
|
||||
fn voices_from(json: &Value, saved: bool) -> Vec<crate::types::Voice> {
|
||||
json["voices"]
|
||||
.as_array()
|
||||
.map(|list| {
|
||||
list.iter()
|
||||
.filter_map(|v| {
|
||||
let id = v["id"].as_str()?;
|
||||
let name = v["name"].as_str().unwrap_or(id);
|
||||
Some(crate::types::Voice {
|
||||
id: id.to_string(),
|
||||
name: name.to_string(),
|
||||
saved,
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Aus der Antwort von `/v1/models`: Modellnamen des Studios als Vorschläge.
|
||||
fn models_from(json: &Value) -> Vec<DiscoveredArtifact> {
|
||||
json["data"]
|
||||
@ -143,6 +163,31 @@ impl Engine for StudioEngine {
|
||||
}
|
||||
}
|
||||
|
||||
async fn voices(&self) -> Vec<crate::types::Voice> {
|
||||
let get = |path: &'static str| {
|
||||
let url = format!("{}{path}", self.base());
|
||||
let http = self.http.clone();
|
||||
async move {
|
||||
let resp = http
|
||||
.get(url)
|
||||
.timeout(Duration::from_secs(5))
|
||||
.send()
|
||||
.await
|
||||
.ok()?;
|
||||
let bytes = resp.bytes().await.ok()?;
|
||||
serde_json::from_slice::<Value>(&bytes).ok()
|
||||
}
|
||||
};
|
||||
let mut out = Vec::new();
|
||||
if let Some(json) = get("/studio/voices").await {
|
||||
out.extend(voices_from(&json, true));
|
||||
}
|
||||
if let Some(json) = get("/tts/speakers").await {
|
||||
out.extend(voices_from(&json, false));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
async fn discover(&self) -> Result<Vec<DiscoveredArtifact>> {
|
||||
let resp = self
|
||||
.http
|
||||
@ -284,6 +329,21 @@ mod tests {
|
||||
assert!(models_from(&Value::Null).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stimmen_aus_den_studio_listen() {
|
||||
let gespeichert: Value = serde_json::from_str(
|
||||
r#"{"voices":[{"id":"abc123","name":"Erzähler"},{"name":"ohne id"}]}"#,
|
||||
)
|
||||
.unwrap();
|
||||
let v = voices_from(&gespeichert, true);
|
||||
assert_eq!(v.len(), 1);
|
||||
assert!(v[0].saved && v[0].id == "abc123" && v[0].name == "Erzähler");
|
||||
let eingebaut: Value = serde_json::from_str(r#"{"voices":[{"id":"Vivian"}]}"#).unwrap();
|
||||
let v = voices_from(&eingebaut, false);
|
||||
assert!(!v[0].saved && v[0].name == "Vivian");
|
||||
assert!(voices_from(&Value::Null, true).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn beschreibt_nur_sprachausgabe() {
|
||||
let info = engine(1).describe();
|
||||
|
||||
@ -45,6 +45,17 @@ pub enum Frontend {
|
||||
Url(String),
|
||||
}
|
||||
|
||||
/// Eine Stimme der Sprachausgabe (für die Auswahl im Playground).
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Voice {
|
||||
/// Wert für das Feld `voice` der Anfrage.
|
||||
pub id: String,
|
||||
/// Anzeigename.
|
||||
pub name: String,
|
||||
/// Gespeicherte (geklonte) Stimme, braucht ein Base-Modell; sonst eingebaute Stimme.
|
||||
pub saved: bool,
|
||||
}
|
||||
|
||||
/// Wie das Gateway eine Engine startet, zum Anzeigen in der Oberfläche. Enthält
|
||||
/// keine Geheimnisse und nichts, was das Gateway erst beim Start einsetzt
|
||||
/// (Port, Modellpfad), nur Platzhalter in spitzen Klammern.
|
||||
|
||||
Reference in New Issue
Block a user