Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

fix(windows): background removal and Chatterbox no longer ask a CPU runtime for DirectML (#399)

Jareere461750e61ce
diff --git a/src/crates/concat-speech/src/chatterbox.rs b/src/crates/concat-speech/src/chatterbox.rs
index 35cdd6a1..412d67ae 100644
--- a/src/crates/concat-speech/src/chatterbox.rs
+++ b/src/crates/concat-speech/src/chatterbox.rs
@@ -300,19 +300,7 @@ fn session(path: &Path, accelerated: bool) -> Result<Session, String> {
path.file_name().unwrap_or_default().to_string_lossy()
);
}
- // DirectML, the GPU of any vendor through Direct3D 12. The runtime is
- // built with it on Windows already, for the cutout models (concat-vision).
- #[cfg(target_os = "windows")]
- if accelerated {
- builder = builder
- .with_execution_providers([ort::ep::DirectML::default().build()])
- .map_err(|error| format!("onnx runtime: directml: {error}"))?;
- log::info!(
- "chatterbox: {} asked to run on DirectML",
- path.file_name().unwrap_or_default().to_string_lossy()
- );
- }
- #[cfg(not(any(target_os = "macos", target_os = "windows")))]
+ #[cfg(not(target_os = "macos"))]
let _ = accelerated;
builder
.commit_from_file(path)
diff --git a/src/crates/concat-speech/src/lib.rs b/src/crates/concat-speech/src/lib.rs
index d7cc5103..b76fdc7c 100644
--- a/src/crates/concat-speech/src/lib.rs
+++ b/src/crates/concat-speech/src/lib.rs
@@ -26,10 +26,9 @@ pub use transcribe::Transcriber;
pub use tts::Speech;
/// Whether the voices ask for the machine's own accelerator: CoreML, the
-/// Mac's GPU and Neural Engine, and on Windows DirectML for Chatterbox -
-/// Kokoro and Pocket run through sherpa's own runtime, which k2-fsa builds
-/// for the CPU there, so they stay on it. Linux has no accelerator in the
-/// runtime the app ships. Not a setting. Measured on an M5 against
+/// Mac's GPU and Neural Engine. Windows and Linux have none in the runtime
+/// the app ships - Windows' is Microsoft's CPU build, and asking it for
+/// DirectML crashed Chatterbox on its second network (#399). Not a setting. Measured on an M5 against
/// the CPU, a warm read took 10.3 s against 14.8 for Kokoro (and came out
/// sample for sample the same), 5.6 against 6.5 for Pocket and 48.6
/// against 60.6 for Chatterbox. The one cost is Chatterbox's load, about
@@ -37,7 +36,7 @@ pub use tts::Speech;
/// run since the engine stays loaded. A model that will not load for CoreML
/// at all loads for the CPU instead (tts.rs).
pub const fn accelerated() -> bool {
- cfg!(any(target_os = "macos", target_os = "windows"))
+ cfg!(target_os = "macos")
}
/// How far a transcription or a read has got, as it reports it: the stage
diff --git a/src/crates/concat-speech/src/tts.rs b/src/crates/concat-speech/src/tts.rs
index 3c4a4cca..a5ba9887 100644
--- a/src/crates/concat-speech/src/tts.rs
+++ b/src/crates/concat-speech/src/tts.rs
@@ -459,8 +459,6 @@ impl std::fmt::Display for ReadError {
fn accelerator() -> &'static str {
if cfg!(target_os = "macos") {
"CoreML"
- } else if cfg!(target_os = "windows") {
- "DirectML"
} else {
"the accelerator"
}
diff --git a/src/crates/concat-vision/src/runtime.rs b/src/crates/concat-vision/src/runtime.rs
index b9336006..d1449510 100644
--- a/src/crates/concat-vision/src/runtime.rs
+++ b/src/crates/concat-vision/src/runtime.rs
@@ -142,17 +142,15 @@ fn platform_accelerator() -> Option<ort::ep::ExecutionProviderDispatch> {
Some(ort::ep::CoreML::default().build())
}
-#[cfg(target_os = "windows")]
-fn platform_accelerator() -> Option<ort::ep::ExecutionProviderDispatch> {
- Some(ort::ep::DirectML::default().build())
-}
-
#[cfg(target_os = "android")]
fn platform_accelerator() -> Option<ort::ep::ExecutionProviderDispatch> {
Some(ort::ep::NNAPI::default().build())
}
-#[cfg(not(any(target_vendor = "apple", target_os = "windows", target_os = "android")))]
+// Not DirectML on Windows: the bundle ships Microsoft's CPU build of the
+// runtime, which has no DirectML, and asking it for one crashed the second
+// session a process opened - an object cutout after a person one (#399).
+#[cfg(not(any(target_vendor = "apple", target_os = "android")))]
fn platform_accelerator() -> Option<ort::ep::ExecutionProviderDispatch> {
None
}