Repository navigation
Add VADSegmentationStage for voice activity detection #1578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
bf035d9
8de8742
eb4b2bc
5dee980
76d6af7
a1206b7
f53d83c
511a4ae
c11d25e
8208545
174a521
494c088
fcac79b
b184313
551ede5
23db429
4088c20
46eb1d8
c26094d
6e650d8
e240495
ef09da8
ed69cb8
7aa9caf
6e29adc
0f34b80
835cd3e
1a265e3
baee33b
599f658
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||
|
|
||
| Segmentation: | ||
| - VADSegmentationStage: Voice Activity Detection segmentation | ||
| """ | ||
|
|
||
| from nemo_curator.stages.audio.segmentation import ( | ||
| VADSegmentationStage, | ||
| ) | ||
|
|
||
| from nemo_curator.stages.audio.configs import ( | ||
| VADConfig, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "VADSegmentationStage", | ||
| "VADConfig", | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. | ||
| # Licensed under the Apache License, Version 2.0 | ||
|
|
||
| """Configuration classes for audio processing stages.""" | ||
|
|
||
| from .vad import VADConfig | ||
|
|
||
| __all__ = [ | ||
| "VADConfig", | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # 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. | ||
|
|
||
| """VAD (Voice Activity Detection) configuration.""" | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Any | ||
|
|
||
| # Internal defaults (not exposed in config) | ||
| _MIN_INTERVAL_MS = 500 | ||
| _THRESHOLD = 0.5 | ||
| _SPEECH_PAD_MS = 300 | ||
|
|
||
|
|
||
| @dataclass | ||
| class VADConfig: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Voice Activity Detection stage. | ||
|
|
||
| Controls how audio is segmented based on speech activity. | ||
| Uses Silero VAD model which supports both CPU and GPU execution. | ||
|
|
||
| Attributes: | ||
| min_duration_sec: Minimum segment duration to keep (seconds) | ||
| max_duration_sec: Maximum segment duration (seconds) | ||
|
|
||
| Example: | ||
| config = VADConfig(min_duration_sec=2.0, max_duration_sec=30.0) | ||
| """ | ||
|
|
||
| min_duration_sec: float = 2.0 | ||
| max_duration_sec: float = 60.0 | ||
|
|
||
| @property | ||
| def min_interval_ms(self) -> int: | ||
| return _MIN_INTERVAL_MS | ||
|
|
||
| @property | ||
| def threshold(self) -> float: | ||
| return _THRESHOLD | ||
|
|
||
| @property | ||
| def speech_pad_ms(self) -> int: | ||
| return _SPEECH_PAD_MS | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
These three parameters are declared as
This directly breaks multiple tests:
These fields must be promoted to proper dataclass fields to be configurable: @dataclass
class VADConfig:
min_duration_sec: float = 2.0
max_duration_sec: float = 60.0
threshold: float = _THRESHOLD
speech_pad_ms: int = _SPEECH_PAD_MS
min_interval_ms: int = _MIN_INTERVAL_MSAnd |
||
|
|
||
| @classmethod | ||
| def from_dict(cls, d: dict) -> "VADConfig": | ||
| """Create config from dictionary.""" | ||
| 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}) | ||
|
shubhamNvidia marked this conversation as resolved.
Resolved
|
||
|
|
||
| def to_dict(self) -> dict: | ||
| """Convert to dictionary.""" | ||
| return { | ||
| 'min_duration_sec': self.min_duration_sec, | ||
| 'max_duration_sec': self.max_duration_sec, | ||
| } | ||
|
|
||
| def get(self, key: str, default: Any = None) -> Any: | ||
| """Get configuration value with default.""" | ||
| return getattr(self, key, default) | ||
|
shubhamNvidia marked this conversation as resolved.
Resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. | ||
| # Licensed under the Apache License, Version 2.0 | ||
|
|
||
| """Audio segmentation stages.""" | ||
|
shubhamNvidia marked this conversation as resolved.
Resolved
|
||
|
|
||
| from .vad_segmentation import VADSegmentationStage | ||
|
|
||
| __all__ = ["VADSegmentationStage"] | ||
Uh oh!
There was an error while loading. Please reload this page.