diff --git a/desktop/src-tauri/src/lib.rs b/desktop/src-tauri/src/lib.rs index 55dba784..b9cde488 100644 --- a/desktop/src-tauri/src/lib.rs +++ b/desktop/src-tauri/src/lib.rs @@ -167,6 +167,50 @@ async fn run_jarvis_command(args: Vec) -> Result { } } +/// Transcribe audio via the speech API endpoint. +#[tauri::command] +async fn transcribe_audio( + api_url: String, + audio_data: Vec, + filename: String, +) -> Result { + let url = format!("{}/v1/speech/transcribe", api_url); + let client = reqwest::Client::new(); + + let part = reqwest::multipart::Part::bytes(audio_data) + .file_name(filename) + .mime_str("audio/webm") + .map_err(|e| format!("Failed to create multipart: {}", e))?; + + let form = reqwest::multipart::Form::new().part("file", part); + + let resp = client + .post(&url) + .multipart(form) + .send() + .await + .map_err(|e| format!("Connection failed: {}", e))?; + let body: serde_json::Value = resp + .json() + .await + .map_err(|e| format!("Invalid response: {}", e))?; + Ok(body) +} + +/// Check speech backend health. +#[tauri::command] +async fn speech_health(api_url: String) -> Result { + let url = format!("{}/v1/speech/health", api_url); + let resp = reqwest::get(&url) + .await + .map_err(|e| format!("Connection failed: {}", e))?; + let body: serde_json::Value = resp + .json() + .await + .map_err(|e| format!("Invalid response: {}", e))?; + Ok(body) +} + #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() @@ -240,6 +284,8 @@ pub fn run() { search_memory, fetch_agents, run_jarvis_command, + transcribe_audio, + speech_health, ]) .run(tauri::generate_context!()) .expect("error while running OpenJarvis Desktop");