Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
451 changes: 445 additions & 6 deletions Cargo.lock

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,24 @@ gloo-net = { version = "0.7", features = ["websocket"] }
# (Ubuntu 24.04 LTS). Drop it once upstream no longer requires 1.26.
[patch.crates-io]
gst-plugin-isobmff = { git = "https://github.com/srperens/gst-plugin-isobmff", tag = "v0.15.4-strom1" }

# Voice isolation runs a neural network in pure Rust; unoptimised it cannot
# keep up with live audio, so debug builds and tests optimise these crates.
[profile.dev.package.tract-core]
opt-level = 3
[profile.dev.package.tract-data]
opt-level = 3
[profile.dev.package.tract-linalg]
opt-level = 3
[profile.dev.package.tract-hir]
opt-level = 3
[profile.dev.package.tract-onnx]
opt-level = 3
[profile.dev.package.tract-onnx-opl]
opt-level = 3
[profile.dev.package.tract-nnef]
opt-level = 3
[profile.dev.package.rustfft]
opt-level = 3
[profile.dev.package.realfft]
opt-level = 3
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ RUN --mount=type=secret,id=aws_access_key_id \
export CMAKE_C_FLAGS="-std=gnu17" && \
export CMAKE_CXX_FLAGS="-std=gnu++17" && \
export RUSTFLAGS="-L /usr/lib/aarch64-linux-gnu" && \
cargo zigbuild --release --package strom --no-default-features --features no-gui,efp --target aarch64-unknown-linux-gnu.2.36 && \
cargo zigbuild --release --package strom --no-default-features --features no-gui,efp,voice-isolation --target aarch64-unknown-linux-gnu.2.36 && \
# Move the binary to expected location (cargo-zigbuild puts it in target/aarch64-unknown-linux-gnu/release)
mkdir -p target/release && \
cp target/aarch64-unknown-linux-gnu/release/strom target/release/strom; \
Expand Down
11 changes: 10 additions & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ default-run = "strom"
autotests = false

[features]
default = ["nvidia"]
default = ["nvidia", "voice-isolation"]
no-gui = []
# DPDFNet speech enhancement on mixer channels, run with tract (pure Rust).
# The model is downloaded at build time and embedded in the binary.
voice-isolation = ["dep:tract-onnx", "dep:realfft", "dep:byte-slice-cast"]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature is on by default, and with it every build runs curl against GitHub (backend/build.rs:428). docs/DEVELOPMENT.md's Optional Cargo Features table needs a row for it, saying it needs curl and network access, or STROM_VOICE_ISOLATION_MODEL for offline builds.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Claude, on behalf of @wagenet. Added a voice-isolation row to the Optional Cargo Features table in docs/DEVELOPMENT.md (357c04e). It says it needs curl and network access, or STROM_VOICE_ISOLATION_MODEL for offline builds.

nvidia = ["dep:nvml-wrapper"]
efp = ["dep:gst-plugin-efp"]

Expand Down Expand Up @@ -74,6 +77,11 @@ gst-plugin-isobmff.workspace = true
gst-plugin-stromdsp = { git = "https://github.com/Eyevinn/strom-dsp", tag = "v0.2.4", package = "gst-plugin-stromdsp" }
gst-plugin-efp = { git = "https://github.com/Eyevinn/efp", tag = "v0.4.1", package = "gst-plugin-efp", optional = true }

# Voice isolation (DPDFNet model inference)
tract-onnx = { version = "0.23", optional = true }
realfft = { version = "3.5", optional = true }
byte-slice-cast = { version = "1.2", optional = true }

# Encoding
base64 = "0.22"

Expand Down Expand Up @@ -146,6 +154,7 @@ eframe = { workspace = true }

[build-dependencies]
chrono = "0.4"
sha2 = "0.10"
uuid = { version = "1.23", features = ["v4"] }

# NVML does not exist on macOS, so the `nvidia` feature pulls in nothing there
Expand Down
45 changes: 45 additions & 0 deletions backend/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ fn main() {
// Set version and build information
set_version_info();

if std::env::var_os("CARGO_FEATURE_VOICE_ISOLATION").is_some() {
fetch_voice_isolation_model();
}

// Embed Windows resources (icon, version info)
#[cfg(windows)]
embed_windows_resources();
Expand Down Expand Up @@ -414,3 +418,44 @@ fn embed_windows_resources() {
eprintln!("cargo:warning=Failed to compile Windows resources: {}", e);
}
}

/// DPDFNet 48 kHz model (Apache-2.0, Ceva), as re-hosted by sherpa-onnx.
const VOICE_MODEL_URL: &str =
"https://github.com/k2-fsa/sherpa-onnx/releases/download/speech-enhancement-models/dpdfnet2_48khz_hr.onnx";
const VOICE_MODEL_SHA256: &str = "0b399f8a58dc4d70d8cd97541f5c39869406145193b957d00a03b66070944928";

/// Put the voice isolation model in OUT_DIR for `include_bytes!`. Downloads it
/// with curl unless STROM_VOICE_ISOLATION_MODEL names a local copy (offline
/// builds). Either way the file must match the pinned hash.
fn fetch_voice_isolation_model() {
use sha2::{Digest, Sha256};

println!("cargo:rerun-if-env-changed=STROM_VOICE_ISOLATION_MODEL");
let out = PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("dpdfnet2_48khz_hr.onnx");
let matches = |p: &Path| {
fs::read(p)
.map(|b| format!("{:x}", Sha256::digest(&b)) == VOICE_MODEL_SHA256)
.unwrap_or(false)
};
if matches(&out) {
return;
}
if let Some(local) = std::env::var_os("STROM_VOICE_ISOLATION_MODEL") {
fs::copy(&local, &out).expect("copy STROM_VOICE_ISOLATION_MODEL");
} else {
let status = Command::new("curl")
.args(["-fsSL", "--retry", "3", "-o"])
.arg(&out)
.arg(VOICE_MODEL_URL)
.status()
.expect("run curl to download the voice isolation model");
assert!(
status.success(),
"downloading {VOICE_MODEL_URL} failed: {status}"
);
}
assert!(
matches(&out),
"voice isolation model does not match sha256 {VOICE_MODEL_SHA256}"
);
}
32 changes: 27 additions & 5 deletions backend/src/blocks/builtin/mixer/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tracing::{debug, info, warn};
use super::elements::*;
use super::metering::connect_mixer_meter_handler;
use super::properties::*;
use super::voice_isolation::push_voice_isolation;
use super::{METER_INTERVAL_NS, MIN_KNEE_LINEAR};
use strom_types::mixer::{
DEFAULT_DSP_BACKEND, DEFAULT_INTERNAL_BUS_LATENCY_MS, DEFAULT_LATENCY_MS,
Expand Down Expand Up @@ -811,6 +812,15 @@ impl BlockBuilder for MixerBuilder {
let hpf = make_hpf_element(&hpf_id, hpf_enabled, hpf_freq)?;
elements.push((hpf_id.clone(), hpf));

let voice_isolation = push_voice_isolation(
instance_id,
ch,
properties,
sample_rate,
&mut elements,
&mut internal_links,
)?;

// ----------------------------------------------------------------
// Gate (LSP Gate Stereo with fallback)
// ----------------------------------------------------------------
Expand Down Expand Up @@ -1096,7 +1106,7 @@ impl BlockBuilder for MixerBuilder {
// ----------------------------------------------------------------
// Main chain links
// ----------------------------------------------------------------
// Chain: convert → resample → caps → gain → hpf → gate → comp → eq → level → pre_fader_tee
// Chain: convert → resample → caps → gain → hpf → [voice isolation] → gate → comp → eq → level → pre_fader_tee
// The channel `level` element sits pre-fader (after EQ/dynamics, before
// pan/fader/mute) so the meter reflects the signal hitting the fader.
internal_links.push((
Expand All @@ -1115,10 +1125,22 @@ impl BlockBuilder for MixerBuilder {
ElementPadRef::pad(&gain_id, "src"),
ElementPadRef::pad(&hpf_id, "sink"),
));
internal_links.push((
ElementPadRef::pad(&hpf_id, "src"),
ElementPadRef::pad(&gate_id, "sink"),
));
match &voice_isolation {
Some((first, last)) => {
internal_links.push((
ElementPadRef::pad(&hpf_id, "src"),
ElementPadRef::pad(first, "sink"),
));
internal_links.push((
ElementPadRef::pad(last, "src"),
ElementPadRef::pad(&gate_id, "sink"),
));
}
None => internal_links.push((
ElementPadRef::pad(&hpf_id, "src"),
ElementPadRef::pad(&gate_id, "sink"),
)),
}
internal_links.push((
ElementPadRef::pad(&gate_id, "src"),
ElementPadRef::pad(&comp_id, "sink"),
Expand Down
42 changes: 42 additions & 0 deletions backend/src/blocks/builtin/mixer/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,48 @@ pub(super) fn mixer_definition() -> BlockDefinition {
visible_when: None,
});

// ============================================================
// Voice isolation properties
// ============================================================
exposed_properties.push(ExposedProperty {
name: format!("ch{}_voice_isolation", ch),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property is exposed whether or not the feature is compiled in, and the frontend toggle is unconditional too (frontend/src/mixer/detail.rs). The ARM64 Docker image is built without default features (Dockerfile:231: --no-default-features --features no-gui,efp), so it has no voiceiso_N element. On that image the switch is shown but does nothing. At build time it only warn!s (mixer/voice_isolation.rs:38). A live toggle should fail with ElementNotFound from update_element_property (backend/src/gst/pipeline/properties.rs:192-195). I have not traced the route from the block property to that function. Either add the feature to the ARM64 build, or leave these properties out when the feature is off (cfg!(feature = "voice-isolation")).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Claude, on behalf of @wagenet. Confirmed: Dockerfile:231 built ARM64 with --no-default-features --features no-gui,efp, so the image had no voiceiso_N element. Fixed in 357c04e by adding voice-isolation to that list (the builder image has curl). I did not trace the route to update_element_property, since the element now exists on that image. The ARM64 Docker build has not been run. #1102 rewrites the same line, so whichever lands second has to carry the feature across.

label: format!("Ch {} Voice Isolation", ch),
description: format!(
"Keep speech and suppress everything else on channel {} (music, fans, typing). \
Delays the channel 60 ms while on.",
ch
),
property_type: PropertyType::Bool,
default_value: Some(PropertyValue::Bool(false)),
mapping: PropertyMapping {
element_id: format!("voiceiso_{}", ch - 1),
property_name: "enabled".to_string(),
transform: None,
},
live: true,
persist: None,
visible_when: None,
});

exposed_properties.push(ExposedProperty {
name: format!("ch{}_voice_isolation_limit", ch),
label: format!("Ch {} Voice Isolation Limit", ch),
description: format!(
"Most voice isolation may reduce channel {} at any frequency, in dB (0-100; 100 = no limit)",
ch
),
property_type: PropertyType::Float,
default_value: Some(PropertyValue::Float(VOICE_ISOLATION_NO_LIMIT_DB as f64)),
mapping: PropertyMapping {
element_id: format!("voiceiso_{}", ch - 1),
property_name: "attenuation-limit".to_string(),
transform: None,
},
live: true,
persist: None,
visible_when: None,
});

// ============================================================
// Gate properties
// ============================================================
Expand Down
3 changes: 3 additions & 0 deletions backend/src/blocks/builtin/mixer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ mod metering;
mod properties;
#[cfg(test)]
mod tests;
mod voice_isolation;
#[cfg(all(test, feature = "voice-isolation"))]
mod voice_isolation_tests;

use strom_types::mixer::{
DEFAULT_CHANNELS, MAX_AUX_BUSES, MAX_CHANNELS, MAX_GROUPS, MIN_KNEE_LINEAR,
Expand Down
16 changes: 8 additions & 8 deletions backend/src/blocks/builtin/mixer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn type_name(element: &gst::Element) -> &'static str {
element.type_().name()
}

fn props(pairs: &[(&str, PropertyValue)]) -> HashMap<String, PropertyValue> {
pub(super) fn props(pairs: &[(&str, PropertyValue)]) -> HashMap<String, PropertyValue> {
pairs
.iter()
.map(|(k, v)| (k.to_string(), v.clone()))
Expand Down Expand Up @@ -511,7 +511,7 @@ const INSTANCE: &str = "mx";

/// Two channels, one aux, one group: small enough to read, and it exercises
/// every kind of bus the builder wires.
fn small_mixer_props(extra: &[(&str, PropertyValue)]) -> HashMap<String, PropertyValue> {
pub(super) fn small_mixer_props(extra: &[(&str, PropertyValue)]) -> HashMap<String, PropertyValue> {
let mut p = props(&[
("num_channels", PropertyValue::UInt(2)),
("num_aux_buses", PropertyValue::UInt(1)),
Expand All @@ -522,13 +522,13 @@ fn small_mixer_props(extra: &[(&str, PropertyValue)]) -> HashMap<String, Propert
p
}

struct Assembled {
pipeline: gst::Pipeline,
pub(super) struct Assembled {
pub(super) pipeline: gst::Pipeline,
result: BlockBuildResult,
}

impl Assembled {
fn element(&self, id: &str) -> &gst::Element {
pub(super) fn element(&self, id: &str) -> &gst::Element {
let full = format!("{INSTANCE}:{id}");
self.result
.elements
Expand All @@ -538,7 +538,7 @@ impl Assembled {
.unwrap_or_else(|| panic!("builder produced no element {full}"))
}

fn has_element(&self, id: &str) -> bool {
pub(super) fn has_element(&self, id: &str) -> bool {
let full = format!("{INSTANCE}:{id}");
self.result.elements.iter().any(|(k, _)| *k == full)
}
Expand Down Expand Up @@ -579,7 +579,7 @@ fn resolve_pad(element: &gst::Element, name: &str) -> gst::Pad {

/// Build through the real builder and link the result the way the pipeline
/// manager does: named pads pad-to-pad, element refs by `Element::link`.
fn assemble(properties: &HashMap<String, PropertyValue>) -> Assembled {
pub(super) fn assemble(properties: &HashMap<String, PropertyValue>) -> Assembled {
init_gst();
let ctx = BlockBuildContext::new(Vec::new(), "all".to_string());
let result = MixerBuilder
Expand Down Expand Up @@ -1043,7 +1043,7 @@ fn test_sample_rate_property_parsing() {
}

/// Link an `audiotestsrc` into `channel`.
fn feed(m: &Assembled, channel: usize, live: bool) {
pub(super) fn feed(m: &Assembled, channel: usize, live: bool) {
let src = gst::ElementFactory::make("audiotestsrc")
.property("is-live", live)
.build()
Expand Down
Loading
Loading