2026-02-26 15:53:09 -08:00
|
|
|
use serde_json::{json, Value};
|
|
|
|
|
|
|
|
|
|
use crate::sidecar::messages::IPCMessage;
|
2026-02-26 16:50:14 -08:00
|
|
|
use crate::sidecar::sidecar;
|
2026-02-26 15:53:09 -08:00
|
|
|
|
|
|
|
|
/// Start transcription of an audio file via the Python sidecar.
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
pub fn transcribe_file(
|
|
|
|
|
file_path: String,
|
|
|
|
|
model: Option<String>,
|
|
|
|
|
device: Option<String>,
|
|
|
|
|
language: Option<String>,
|
|
|
|
|
) -> Result<Value, String> {
|
2026-02-26 16:50:14 -08:00
|
|
|
let manager = sidecar();
|
|
|
|
|
manager.ensure_running()?;
|
2026-02-26 15:53:09 -08:00
|
|
|
|
|
|
|
|
let request_id = uuid::Uuid::new_v4().to_string();
|
|
|
|
|
let msg = IPCMessage::new(
|
|
|
|
|
&request_id,
|
|
|
|
|
"transcribe.start",
|
|
|
|
|
json!({
|
|
|
|
|
"file": file_path,
|
|
|
|
|
"model": model.unwrap_or_else(|| "base".to_string()),
|
|
|
|
|
"device": device.unwrap_or_else(|| "cpu".to_string()),
|
|
|
|
|
"compute_type": "int8",
|
|
|
|
|
"language": language,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let response = manager.send_and_receive(&msg)?;
|
|
|
|
|
|
|
|
|
|
if response.msg_type == "error" {
|
|
|
|
|
return Err(format!(
|
|
|
|
|
"Transcription error: {}",
|
|
|
|
|
response.payload.get("message").and_then(|v| v.as_str()).unwrap_or("unknown")
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(response.payload)
|
|
|
|
|
}
|
2026-02-26 16:09:48 -08:00
|
|
|
|
|
|
|
|
/// Run the full transcription + diarization pipeline via the Python sidecar.
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
pub fn run_pipeline(
|
|
|
|
|
file_path: String,
|
|
|
|
|
model: Option<String>,
|
|
|
|
|
device: Option<String>,
|
|
|
|
|
language: Option<String>,
|
|
|
|
|
num_speakers: Option<u32>,
|
|
|
|
|
min_speakers: Option<u32>,
|
|
|
|
|
max_speakers: Option<u32>,
|
|
|
|
|
skip_diarization: Option<bool>,
|
|
|
|
|
) -> Result<Value, String> {
|
2026-02-26 16:50:14 -08:00
|
|
|
let manager = sidecar();
|
|
|
|
|
manager.ensure_running()?;
|
2026-02-26 16:09:48 -08:00
|
|
|
|
|
|
|
|
let request_id = uuid::Uuid::new_v4().to_string();
|
|
|
|
|
let msg = IPCMessage::new(
|
|
|
|
|
&request_id,
|
|
|
|
|
"pipeline.start",
|
|
|
|
|
json!({
|
|
|
|
|
"file": file_path,
|
|
|
|
|
"model": model.unwrap_or_else(|| "base".to_string()),
|
|
|
|
|
"device": device.unwrap_or_else(|| "cpu".to_string()),
|
|
|
|
|
"compute_type": "int8",
|
|
|
|
|
"language": language,
|
|
|
|
|
"num_speakers": num_speakers,
|
|
|
|
|
"min_speakers": min_speakers,
|
|
|
|
|
"max_speakers": max_speakers,
|
|
|
|
|
"skip_diarization": skip_diarization.unwrap_or(false),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let response = manager.send_and_receive(&msg)?;
|
|
|
|
|
|
|
|
|
|
if response.msg_type == "error" {
|
|
|
|
|
return Err(format!(
|
|
|
|
|
"Pipeline error: {}",
|
|
|
|
|
response.payload.get("message").and_then(|v| v.as_str()).unwrap_or("unknown")
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(response.payload)
|
|
|
|
|
}
|