Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2c80669
Add SIGMOSFilterStage and ensure_cudnn_loaded utility
shubhamNvidia Mar 5, 2026
5faad7a
Add SIGMOS model files
shubhamNvidia Mar 5, 2026
e64f75b
Add unit tests for SIGMOSFilterStage
shubhamNvidia Mar 5, 2026
f3f8928
Simplified config, removed temp file creation, uses in-memory predict…
shubhamNvidia Mar 11, 2026
01dc37e
Guard GPU fallback, delegate GPU detection to stage, replace print wi…
shubhamNvidia Mar 12, 2026
ffd5888
Fix copyrights, restore upstream gpu_utils and added ensure cudnn fun…
shubhamNvidia Mar 20, 2026
be96268
Add common utilities, replace duplicate _resolve_model_path in sigmos.py
shubhamNvidia Mar 22, 2026
ab83471
change resource allocation pattern
shubhamNvidia Mar 22, 2026
dfc6ae9
Remove SIGMOSConfig, modernize types, untrack ADV test
shubhamNvidia Mar 24, 2026
7dacb2e
Merge upstream/main into pr/audio-sigmos
shubhamNvidia Mar 25, 2026
b2c48cf
Merge branch 'main' into pr/audio-sigmos
sarahyurick Mar 25, 2026
e910433
Fix ruff lint violations in audio sigmos filter stage
shubhamNvidia Mar 25, 2026
9e3c559
Migrate to AudioTask single-dict pattern
shubhamNvidia Mar 26, 2026
3840328
Merge upstream/main, resolve conflicts keeping utility functions
shubhamNvidia Mar 26, 2026
250c67f
Add nested segments handling to SIGMOSFilterStage
shubhamNvidia Mar 30, 2026
6912606
Merge branch 'main' into pr/audio-sigmos
sarahyurick Mar 31, 2026
65730b0
fix ruff linting errors in sigmos files
shubhamNvidia Mar 31, 2026
de20c46
Merge upstream/main into pr/audio-sigmos
shubhamNvidia Apr 1, 2026
672dfe0
fix: lazy import predict_audio_mos to avoid onnxruntime import at col…
shubhamNvidia Apr 1, 2026
a1f3c82
fix: guard sigmos import to avoid ImportError during test collection
shubhamNvidia Apr 1, 2026
3747312
Merge branch 'main' into pr/audio-sigmos
shubhamNvidia Apr 2, 2026
e089988
Merge remote-tracking branch 'upstream/main' into pr/audio-sigmos
shubhamNvidia Apr 2, 2026
b3228af
Merge branch 'main' into pr/audio-sigmos
shubhamNvidia Apr 2, 2026
32215b4
Merge upstream/main, resolve conflicts keeping both changes
shubhamNvidia Apr 3, 2026
a0022ea
Merge upstream/main and address reviewer feedback for SIGMOS
shubhamNvidia Apr 5, 2026
75809cc
Remove bundled ONNX model, auto-download from Microsoft GitHub
shubhamNvidia Apr 5, 2026
d0936c4
Address review feedback: guard teardown, add deps, remove dead code
shubhamNvidia Apr 5, 2026
f297f01
Merge branch 'main' into pr/audio-sigmos
sarahyurick Apr 6, 2026
b194a3d
Add Microsoft MIT attribution for SIGMOS and Apache 2.0 contribution …
shubhamNvidia Apr 6, 2026
9aa21a3
Merge branch 'main' into pr/audio-sigmos
shubhamNvidia Apr 6, 2026
961e8d0
Adding Microsoft license to LICENSE file
shubhamNvidia Apr 6, 2026
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
33 changes: 33 additions & 0 deletions nemo_curator/stages/audio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
NeMo Curator Audio Processing Stages.

Filtering:
- SIGMOSFilterStage: SIGMOS quality filtering
"""

from nemo_curator.stages.audio.filtering import (
SIGMOSFilterStage,
)

from nemo_curator.stages.audio.configs import (
SIGMOSConfig,
)

__all__ = [
"SIGMOSFilterStage",
"SIGMOSConfig",
]
95 changes: 95 additions & 0 deletions nemo_curator/stages/audio/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from abc import abstractmethod
from dataclasses import dataclass
from operator import eq, ge, gt, le, lt, ne
from typing import Any, Dict, Optional, Tuple

import soundfile
import torch
from loguru import logger

from nemo_curator.stages.base import ProcessingStage
Expand Down Expand Up @@ -118,3 +121,95 @@ def process_dataset_entry(self, data_entry: AudioBatch) -> list[AudioBatch]:
return [AudioBatch(data=data_entry)]
else:
return []


def load_audio_file(audio_path: str, mono: bool = True) -> Tuple[torch.Tensor, int]:
"""Load audio file and return waveform tensor (channels, samples) and sample rate."""
data, sample_rate = soundfile.read(audio_path, dtype='float32')
waveform = torch.from_numpy(data)
if waveform.dim() == 1:
waveform = waveform.unsqueeze(0)
else:
waveform = waveform.T
if mono and waveform.shape[0] > 1:
waveform = waveform.mean(dim=0, keepdim=True)
return waveform, sample_rate


def ensure_waveform_2d(waveform) -> torch.Tensor:
"""Ensure waveform is a torch.Tensor in 2D (channels, samples) format."""
if not torch.is_tensor(waveform):
waveform = torch.as_tensor(waveform, dtype=torch.float32)
if waveform.dim() == 1:
waveform = waveform.unsqueeze(0)
return waveform


def ensure_mono(waveform: torch.Tensor) -> torch.Tensor:
"""Convert multi-channel waveform to mono. Assumes 2D (channels, samples) input."""
if waveform.shape[0] > 1:
waveform = waveform.mean(dim=0, keepdim=True)
return waveform


def resolve_waveform_from_item(
item: Dict[str, Any], task_id: str, mono: bool = True
) -> Optional[Tuple[torch.Tensor, int]]:
"""
Resolve (waveform, sample_rate) from an item dict, loading from file if needed.

Checks item['waveform'] + item['sample_rate'], falls back to loading from
item['audio_filepath'], resolves missing sample_rate from file header.
Updates item in-place when loading from file.
Returns None if resolution fails.
"""
waveform = item.get("waveform")
sample_rate = item.get("sample_rate")

if waveform is None:
audio_filepath = item.get("audio_filepath")
if audio_filepath and os.path.exists(audio_filepath):
try:
waveform, sample_rate = load_audio_file(audio_filepath, mono=mono)
item["waveform"] = waveform
item["sample_rate"] = sample_rate
except Exception as e:
logger.error(f"[{task_id}] Failed to load audio file: {e}")
return None
else:
logger.warning(f"[{task_id}] No waveform or valid audio_filepath found")
return None
elif sample_rate is None:
audio_filepath = item.get("audio_filepath")
if audio_filepath and os.path.exists(audio_filepath):
try:
info = soundfile.info(audio_filepath)
sample_rate = info.samplerate
item["sample_rate"] = sample_rate
except Exception as e:
logger.error(f"[{task_id}] Waveform present but sample_rate missing "
f"and could not read from '{audio_filepath}': {e}")
return None
else:
logger.error(f"[{task_id}] Waveform present but 'sample_rate' missing "
"and no audio_filepath available.")
return None

waveform = ensure_waveform_2d(waveform)
if mono:
waveform = ensure_mono(waveform)

return waveform, sample_rate


def resolve_model_path(model_path: str, reference_file: str, module_subdir: str) -> str:
"""Resolve a relative model path using the reference file's directory and module subdirectory."""
if os.path.isabs(model_path):
return model_path
current_dir = os.path.dirname(os.path.abspath(reference_file))
module_dir = os.path.join(current_dir, module_subdir)
for base in (module_dir, current_dir):
resolved = os.path.join(base, model_path)
if os.path.exists(resolved):
return resolved
return os.path.join(module_dir, model_path)
21 changes: 21 additions & 0 deletions nemo_curator/stages/audio/configs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Configuration classes for audio processing stages."""

from .sigmos import SIGMOSConfig

__all__ = [
"SIGMOSConfig",
]
83 changes: 83 additions & 0 deletions nemo_curator/stages/audio/configs/sigmos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""SIGMOS (Signal-based Mean Opinion Score) configuration."""

from dataclasses import dataclass
from typing import Any, Optional

_MODEL_PATH = "model/model-sigmos_1697718653_41d092e8-epo-200.onnx"


@dataclass
class SIGMOSConfig:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Discussed offline. We do not need a config class per stage.

"""
Configuration for SIGMOS quality assessment filter.

SIGMOS predicts audio quality dimensions (1-5 scale).
Set threshold to None to disable that check.

Attributes:
noise_threshold: Minimum noise score (None to disable)
ovrl_threshold: Minimum overall score (None to disable)
sig_threshold: Minimum signal score (None to disable)
col_threshold: Minimum coloration score (None to disable)
disc_threshold: Minimum discontinuity score (None to disable)
loud_threshold: Minimum loudness score (None to disable)
reverb_threshold: Minimum reverb score (None to disable)

Example:
config = SIGMOSConfig(noise_threshold=4.0, ovrl_threshold=3.5)
"""

noise_threshold: Optional[float] = 4.0
ovrl_threshold: Optional[float] = 3.5
sig_threshold: Optional[float] = None
col_threshold: Optional[float] = None
disc_threshold: Optional[float] = None
loud_threshold: Optional[float] = None
reverb_threshold: Optional[float] = None

@property
def model_path(self) -> str:
return _MODEL_PATH

@classmethod
def from_dict(cls, d: Optional[dict] = None) -> "SIGMOSConfig":
if d is None:
return cls()
valid_keys = cls.__dataclass_fields__.keys()
return cls(**{k: v for k, v in d.items() if k in valid_keys})

def to_dict(self) -> dict:
return {
'noise_threshold': self.noise_threshold,
'ovrl_threshold': self.ovrl_threshold,
'sig_threshold': self.sig_threshold,
'col_threshold': self.col_threshold,
'disc_threshold': self.disc_threshold,
'loud_threshold': self.loud_threshold,
'reverb_threshold': self.reverb_threshold,
}

def get(self, key: str, default: Any = None) -> Any:
return getattr(self, key, default)

def get_active_thresholds(self) -> dict:
thresholds = {}
for name in ['noise', 'ovrl', 'sig', 'col', 'disc', 'loud', 'reverb']:
val = getattr(self, f'{name}_threshold')
if val is not None:
thresholds[name] = val
return thresholds
21 changes: 21 additions & 0 deletions nemo_curator/stages/audio/filtering/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Audio quality filtering stages."""
Comment thread
shubhamNvidia marked this conversation as resolved.
Resolved

from .sigmos import SIGMOSFilterStage

__all__ = [
"SIGMOSFilterStage",
]
Loading