diff --git a/src/core/processor/asrx.rs b/src/core/processor/asrx.rs index 86874e97..86ea34b3 100644 --- a/src/core/processor/asrx.rs +++ b/src/core/processor/asrx.rs @@ -68,12 +68,65 @@ pub async fn process_asrx( video_path: &str, output_path: &str, uuid: Option<&str>, +) -> Result { + tracing::info!("[ASRX] Starting hybrid speaker diarization: {}", video_path); + + let swift_asrx_path = std::path::Path::new("/Users/accusys/momentry_core/scripts/swift_processors/.build/release/asrx_swift"); + + if swift_asrx_path.exists() { + tracing::info!("[ASRX] Using Swift processor: {:?}", swift_asrx_path); + + let mut args = vec![video_path.to_string(), output_path.to_string()]; + if let Some(u) = uuid { + args.push("--uuid".to_string()); + args.push(u.to_string()); + } + + let output = tokio::process::Command::new(swift_asrx_path) + .args(&args) + .output() + .await + .context("Failed to execute asrx_swift")?; + + if !output.status.success() { + let stderr = String::from_utf8_lossy(&output.stderr); + tracing::error!("[ASRX] Swift processor failed: {}", stderr); + + tracing::warn!("[ASRX] Falling back to Python processor"); + return process_asrx_python(video_path, output_path, uuid).await; + } + + tracing::info!("[ASRX] Swift processor completed successfully"); + + let json_str = std::fs::read_to_string(output_path) + .context("Failed to read ASRX output")?; + + let mut result: AsrxResult = serde_json::from_str(&json_str) + .context("Failed to parse ASRX output")?; + + result.compute_status(); + + tracing::info!( + "[ASRX] Swift result: status={}, {} segments", + result.status.as_ref().map(|s| s.to_string()).unwrap_or_default(), + result.segment_count + ); + + return Ok(result); + } + + tracing::warn!("[ASRX] Swift binary not found, using Python processor"); + process_asrx_python(video_path, output_path, uuid).await +} + +async fn process_asrx_python( + video_path: &str, + output_path: &str, + uuid: Option<&str>, ) -> Result { let executor = PythonExecutor::new()?; let script_path = executor.script_path("asrx_processor.py"); - tracing::info!("[ASRX] Starting hybrid speaker diarization: {}", video_path); - if !script_path.exists() { tracing::error!("[ASRX] Script not found: {:?}", script_path); anyhow::bail!("asrx_processor.py not found");