Skip to main content

Demucs v4 audio source separation plugin for the cjm-plugin-system that provides vocals extraction for removing background noise and music from speech audio.

Project description

cjm-media-plugin-demucs

Install

pip install cjm_media_plugin_demucs

Project Structure

nbs/
├── meta.ipynb   # Metadata introspection for the Demucs plugin used by cjm-ctl to generate the registration manifest.
└── plugin.ipynb # Demucs v4 audio source separation plugin — provides vocals extraction for removing background noise and music from speech audio.

Total: 2 notebooks

Module Dependencies

graph LR
    meta["meta<br/>Metadata"]
    plugin["plugin<br/>Plugin"]

No cross-module dependencies detected.

CLI Reference

No CLI commands found in this project.

Module Overview

Detailed documentation for each module in the project:

Metadata (meta.ipynb)

Metadata introspection for the Demucs plugin used by cjm-ctl to generate the registration manifest.

Import

from cjm_media_plugin_demucs.meta import (
    get_plugin_metadata
)

Functions

def get_plugin_metadata() -> Dict[str, Any]:  # Plugin metadata for manifest generation
    """Return metadata required to register this plugin with the PluginManager."""
    # Fallback base path (current behavior for backward compatibility)
    base_path = os.path.dirname(os.path.dirname(sys.executable))
    
    # Use CJM config if available, else fallback to env-relative paths
    cjm_data_dir = os.environ.get("CJM_DATA_DIR")
    cjm_models_dir = os.environ.get("CJM_MODELS_DIR")
    
    # Plugin data directory
    plugin_name = "cjm-media-plugin-demucs"
    if cjm_data_dir
    "Return metadata required to register this plugin with the PluginManager."

Plugin (plugin.ipynb)

Demucs v4 audio source separation plugin — provides vocals extraction for removing background noise and music from speech audio.

Import

from cjm_media_plugin_demucs.plugin import (
    DemucsPluginConfig,
    DemucsProcessingPlugin
)

Classes

@dataclass
class DemucsPluginConfig:
    "Configuration for the Demucs processing plugin."
    
    model: str = field(...)
    device: str = field(...)
    shifts: int = field(...)
    overlap: float = field(...)
    segment: Optional[int] = field(...)
    save_other_stems: bool = field(...)
    output_format: str = field(...)
class DemucsProcessingPlugin:
    def __init__(self):
        """Initialize the plugin."""
        self.logger = logging.getLogger(f"{__name__}.{type(self).__name__}")
        self.config: Optional[DemucsPluginConfig] = None
    "Demucs v4 source separation plugin for vocals extraction."
    
    def __init__(self):
            """Initialize the plugin."""
            self.logger = logging.getLogger(f"{__name__}.{type(self).__name__}")
            self.config: Optional[DemucsPluginConfig] = None
        "Initialize the plugin."
    
    def name(self) -> str:  # Plugin name identifier
            """Get the plugin name."""
            return "cjm-media-plugin-demucs"
        
        @property
        def version(self) -> str:  # Plugin version string
        "Get the plugin name."
    
    def version(self) -> str:  # Plugin version string
            """Get the plugin version."""
            from cjm_media_plugin_demucs import __version__
            return __version__
        
        @property
        def supported_media_types(self) -> List[str]:  # Supported media types
        "Get the plugin version."
    
    def supported_media_types(self) -> List[str]:  # Supported media types
            """Get supported media types."""
            return ["audio"]
        
        # ── Lifecycle ────────────────────────────────────────────────────
        
        def _apply_config(self,
                          config: Optional[Any] = None,  # Configuration dict or None for defaults
                         ) -> None
        "Get supported media types."
    
    def initialize(self,
                       config: Optional[Any] = None,  # Configuration dict or None for defaults
                      ) -> None
        "First-time setup. CR-4: config application factored into _apply_config; the
substrate's reconfigure path fires _release_model on a model/device change then
re-applies config."
    
    def prefetch(self) -> None:
            """CR-4 (SG-19): eagerly load the model so the first execute() doesn't pay
            the download/load cost. Idempotent via _load_model's None-guard."""
            self._load_model()
    
        def on_disable(self) -> None
        "CR-4 (SG-19): eagerly load the model so the first execute() doesn't pay
the download/load cost. Idempotent via _load_model's None-guard."
    
    def on_disable(self) -> None:
            """CR-2: release the GPU model when the operator disables the plugin (the
            worker stays alive); lazy reload on the next execute after re-enable."""
            self._release_model()
    
        def cleanup(self) -> None
        "CR-2: release the GPU model when the operator disables the plugin (the
worker stays alive); lazy reload on the next execute after re-enable."
    
    def cleanup(self) -> None:
            """Clean up plugin resources."""
            self._release_model()
            self.logger.info("Plugin cleaned up")
        
        def is_available(self) -> bool:  # Whether the plugin can run
        "Clean up plugin resources."
    
    def is_available(self) -> bool:  # Whether the plugin can run
            """Check if the plugin is available on this system."""
            try
        "Check if the plugin is available on this system."
    
    def get_config_schema(self) -> Dict[str, Any]:  # JSON Schema for UI forms
            """Return JSON Schema for the plugin configuration."""
            return dataclass_to_jsonschema(DemucsPluginConfig)
        
        def get_current_config(self) -> Dict[str, Any]:  # Current config as dict
        "Return JSON Schema for the plugin configuration."
    
    def get_current_config(self) -> Dict[str, Any]:  # Current config as dict
            """Return the current configuration."""
            return config_to_dict(self.config) if self.config else {}
        
        # ── Model Management ────────────────────────────────────────────
        
        def _load_model(self) -> None
        "Return the current configuration."
    
    def execute(self,
                    action: str = "separate_vocals",  # Action to perform
                    **kwargs
                   ) -> Dict[str, Any]:  # Action result
        "Dispatch to the `@plugin_action`-tagged handler for `action` (SG-44)."
    
    def get_info(self,
                     file_path: str,  # Path to audio file
                    ) -> MediaMetadata:  # File metadata
        "Get basic audio file metadata via ffprobe."
    
    def convert(self, input_path, output_format, **kwargs):
            """Not applicable for source separation."""
            raise PluginInputError(  # SG-47: typed input-validation; this method is
                # not applicable for this plugin domain.
                "convert is not supported by the Demucs plugin. "
                "Use 'separate_vocals' instead.",
                fields_invalid=["action"],
            )
        
        def extract_segment(self, input_path, start, end, output_path=None)
        "Not applicable for source separation."
    
    def extract_segment(self, input_path, start, end, output_path=None):
            """Not applicable for source separation."""
            raise PluginInputError(  # SG-47: typed input-validation; this method is
                # not applicable for this plugin domain.
                "extract_segment is not supported by the Demucs plugin. "
                "Use 'separate_vocals' instead.",
                fields_invalid=["action"],
            )
        
        # ── Core Action ──────────────────────────────────────────────────
        
        def _separate_vocals(self,
                             input_path: str,  # Path to audio file
                             output_dir: Optional[str] = None,  # Output directory (default: data_dir/vocals/)
                             output_format: Optional[str] = None,  # Output format override
                            ) -> Dict[str, Any]:  # Separation result
        "Not applicable for source separation."

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cjm_media_plugin_demucs-0.0.6.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cjm_media_plugin_demucs-0.0.6-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file cjm_media_plugin_demucs-0.0.6.tar.gz.

File metadata

  • Download URL: cjm_media_plugin_demucs-0.0.6.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for cjm_media_plugin_demucs-0.0.6.tar.gz
Algorithm Hash digest
SHA256 969f10f004ca6e43b3c473ec3b619a0ffc9e4e6b832f4cb9315af3028fee19f9
MD5 7840f5c885b01a669a590069951e1fdd
BLAKE2b-256 a89024d65b7e764a94ce8d0d8e4ec0af1353868469fd72c11070fe5333ef46c4

See more details on using hashes here.

File details

Details for the file cjm_media_plugin_demucs-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for cjm_media_plugin_demucs-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9fa7b86ce1d788a3d22cb55d0267c071116bc5539c27f1a70c654f9fb6271700
MD5 64976bb7e566e72a62310e79064dcf28
BLAKE2b-256 ccda2ba26fb39d1b4e7c8ebd2132b38643568f47eea21dbca1122b6e43cfc0dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page