refactor: migrate ASRX processor to Swift, bypass Python

- Modified asrx.rs to prioritize Swift binary (asrx_swift)
- Swift ASRX already compiled (1.5MB)
- Retained Python fallback for backward compatibility
- Removed dependency on asrx_processor.py for main flow

Phase 3 of processor architecture refactoring

All core processors now using Swift/CLI:
- Face: Swift ✅
- OCR: Swift ✅
- ASR: Whisper CLI ✅
- ASRX: Swift ✅
- CUT: FFmpeg ✅
- Scene VLM: Rust ✅
This commit is contained in:
Accusys
2026-09-26 01:42:30 +08:00
parent 40cf967347
commit 2a422cdf6f
+55 -2
View File
@@ -68,12 +68,65 @@ pub async fn process_asrx(
video_path: &str,
output_path: &str,
uuid: Option<&str>,
) -> Result<AsrxResult> {
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<AsrxResult> {
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");