audio-separation 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 felipe-infantino
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: audio-separation
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Local vocal removal
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Author: Felipe Infantino
|
|
7
|
+
Author-email: felipe.infantino@icloud.com
|
|
8
|
+
Requires-Python: >=3.11,<3.15
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Requires-Dist: demucs (>=4.0.1,<5.0.0)
|
|
15
|
+
Requires-Dist: huggingface-hub (>=0.23,<0.24)
|
|
16
|
+
Requires-Dist: librosa (>=0.11.0,<0.12.0)
|
|
17
|
+
Requires-Dist: pydub (>=0.25.1,<0.26.0)
|
|
18
|
+
Requires-Dist: resampy (>=0.4.3,<0.5.0)
|
|
19
|
+
Requires-Dist: torch (>=2.10,<3.0)
|
|
20
|
+
Requires-Dist: torchaudio (>=2.10,<3.0)
|
|
21
|
+
Requires-Dist: tqdm (>=4.67.3,<5.0.0)
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# audio-separation
|
|
25
|
+
|
|
26
|
+
Local audio source separation. Drums, Bass, Vocal and other.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install audio-separation
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
audio-separation "track.mp3" ./outputs/
|
|
38
|
+
audio-separation "track.mp3" ./outputs/ --device cuda
|
|
39
|
+
audio-separation "track.mp3" ./outputs/ --device mps
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Output files are saved as `<track>_<stem>.mp3` in the specified directory.
|
|
43
|
+
|
|
44
|
+
## Arguments
|
|
45
|
+
|
|
46
|
+
| Argument | Description |
|
|
47
|
+
|---|---|
|
|
48
|
+
| `input_file` | Path to the input audio file |
|
|
49
|
+
| `output_dir` | Directory where the output MP3 will be saved |
|
|
50
|
+
|
|
51
|
+
## Options
|
|
52
|
+
|
|
53
|
+
| Flag | Default | Description |
|
|
54
|
+
|---|---|---|
|
|
55
|
+
| `--device` | `cpu` | Inference device: `cpu`, `cuda`, `mps` |
|
|
56
|
+
|
|
57
|
+
## Requirements
|
|
58
|
+
|
|
59
|
+
- Python 3.11–3.14
|
|
60
|
+
- FFmpeg (`brew install ffmpeg` / `apt install ffmpeg`)
|
|
61
|
+
|
|
62
|
+
> Model weights download automatically on first run from Hugging Face (`felipeinfantino/voice-remover`).
|
|
63
|
+
> Cached at `~/.cache/voice-remover/models/`.
|
|
64
|
+
|
|
65
|
+
## Development
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
git clone https://github.com/felipeinfantino/audio-separation
|
|
69
|
+
cd audio-separation
|
|
70
|
+
poetry install
|
|
71
|
+
poetry run audio-separation "inputs/Alucinados.mp3" "outputs"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Extending with a new package
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
poetry add [packagename]
|
|
78
|
+
|
|
79
|
+
# Check the CLI is still working
|
|
80
|
+
poetry run audio-separation "inputs/Alucinados.mp3" "outputs"
|
|
81
|
+
|
|
82
|
+
# Verify lockfile is clean
|
|
83
|
+
poetry lock
|
|
84
|
+
|
|
85
|
+
# Bump version
|
|
86
|
+
poetry version patch # or minor / major
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT
|
|
92
|
+
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# audio-separation
|
|
2
|
+
|
|
3
|
+
Local audio source separation. Drums, Bass, Vocal and other.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install audio-separation
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
audio-separation "track.mp3" ./outputs/
|
|
15
|
+
audio-separation "track.mp3" ./outputs/ --device cuda
|
|
16
|
+
audio-separation "track.mp3" ./outputs/ --device mps
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Output files are saved as `<track>_<stem>.mp3` in the specified directory.
|
|
20
|
+
|
|
21
|
+
## Arguments
|
|
22
|
+
|
|
23
|
+
| Argument | Description |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `input_file` | Path to the input audio file |
|
|
26
|
+
| `output_dir` | Directory where the output MP3 will be saved |
|
|
27
|
+
|
|
28
|
+
## Options
|
|
29
|
+
|
|
30
|
+
| Flag | Default | Description |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| `--device` | `cpu` | Inference device: `cpu`, `cuda`, `mps` |
|
|
33
|
+
|
|
34
|
+
## Requirements
|
|
35
|
+
|
|
36
|
+
- Python 3.11–3.14
|
|
37
|
+
- FFmpeg (`brew install ffmpeg` / `apt install ffmpeg`)
|
|
38
|
+
|
|
39
|
+
> Model weights download automatically on first run from Hugging Face (`felipeinfantino/voice-remover`).
|
|
40
|
+
> Cached at `~/.cache/voice-remover/models/`.
|
|
41
|
+
|
|
42
|
+
## Development
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
git clone https://github.com/felipeinfantino/audio-separation
|
|
46
|
+
cd audio-separation
|
|
47
|
+
poetry install
|
|
48
|
+
poetry run audio-separation "inputs/Alucinados.mp3" "outputs"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Extending with a new package
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
poetry add [packagename]
|
|
55
|
+
|
|
56
|
+
# Check the CLI is still working
|
|
57
|
+
poetry run audio-separation "inputs/Alucinados.mp3" "outputs"
|
|
58
|
+
|
|
59
|
+
# Verify lockfile is clean
|
|
60
|
+
poetry lock
|
|
61
|
+
|
|
62
|
+
# Bump version
|
|
63
|
+
poetry version patch # or minor / major
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
MIT
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def main() -> None:
|
|
6
|
+
parser = argparse.ArgumentParser(description="Run vocal removal on an audio file.")
|
|
7
|
+
parser.add_argument("input_file", help="Path to the input audio file")
|
|
8
|
+
parser.add_argument("output_dir", help="Directory where the output MP3 will be saved")
|
|
9
|
+
parser.add_argument(
|
|
10
|
+
"--device",
|
|
11
|
+
default="cpu",
|
|
12
|
+
help="Compute device: cpu | cuda | mps (default: cpu)",
|
|
13
|
+
)
|
|
14
|
+
args = parser.parse_args()
|
|
15
|
+
|
|
16
|
+
from app.inference import run_inference
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
run_inference(args.input_file, args.output_dir, device=args.device)
|
|
20
|
+
except FileNotFoundError as exc:
|
|
21
|
+
print(f"Error: {exc}", file=sys.stderr)
|
|
22
|
+
sys.exit(1)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import soundfile as sf
|
|
6
|
+
import torch
|
|
7
|
+
import torchaudio.functional as F
|
|
8
|
+
from demucs.apply import apply_model
|
|
9
|
+
from demucs.pretrained import get_model
|
|
10
|
+
|
|
11
|
+
DEMUCS_MODEL = "htdemucs"
|
|
12
|
+
|
|
13
|
+
_model = None
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _load_demucs(device: str) -> torch.nn.Module:
|
|
17
|
+
"""Load htdemucs once and cache it for the process lifetime."""
|
|
18
|
+
global _model
|
|
19
|
+
if _model is None:
|
|
20
|
+
print(f"Loading {DEMUCS_MODEL} (downloading once if not cached)...")
|
|
21
|
+
_model = get_model(DEMUCS_MODEL)
|
|
22
|
+
_model.eval()
|
|
23
|
+
return _model.to(device)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def run_inference(input_file: str, output_dir: str, device: str = "cpu") -> dict[str, str]:
|
|
27
|
+
"""Separate *input_file* into drums / bass / other / vocals.
|
|
28
|
+
|
|
29
|
+
Returns a dict mapping stem name → output file path.
|
|
30
|
+
"""
|
|
31
|
+
start = time.perf_counter()
|
|
32
|
+
|
|
33
|
+
input_path = Path(input_file)
|
|
34
|
+
if not input_path.exists():
|
|
35
|
+
raise FileNotFoundError(f"Input file not found: {input_file}")
|
|
36
|
+
|
|
37
|
+
# ── 1. Load model ────────────────────────────────────────────────────────
|
|
38
|
+
model = _load_demucs(device)
|
|
39
|
+
|
|
40
|
+
# ── 2. Load audio ────────────────────────────────────────────────────────
|
|
41
|
+
data, sr = sf.read(str(input_path), always_2d=True) # [T, C] float64
|
|
42
|
+
wav = torch.from_numpy(data.T.astype(np.float32)) # [C, T]
|
|
43
|
+
|
|
44
|
+
if sr != model.samplerate:
|
|
45
|
+
wav = F.resample(wav, sr, model.samplerate)
|
|
46
|
+
|
|
47
|
+
if wav.shape[0] == 1:
|
|
48
|
+
wav = wav.repeat(2, 1) # mono → stereo
|
|
49
|
+
|
|
50
|
+
wav = wav.unsqueeze(0) # [1, C, T] (batch dim)
|
|
51
|
+
|
|
52
|
+
# ── 3. Separate ──────────────────────────────────────────────────────────
|
|
53
|
+
with torch.no_grad():
|
|
54
|
+
sources = apply_model(model, wav, device=device) # [1, stems, C, T]
|
|
55
|
+
|
|
56
|
+
sources = sources.squeeze(0) # [stems, C, T]
|
|
57
|
+
|
|
58
|
+
# ── 4. Save one MP3 per stem ─────────────────────────────────────────────
|
|
59
|
+
basename = input_path.stem
|
|
60
|
+
out_dir = Path(output_dir)
|
|
61
|
+
out_dir.mkdir(parents=True, exist_ok=True)
|
|
62
|
+
|
|
63
|
+
output_paths: dict[str, str] = {}
|
|
64
|
+
for stem_name, stem_wav in zip(model.sources, sources):
|
|
65
|
+
out_path = out_dir / f"{basename}_{stem_name}.mp3"
|
|
66
|
+
audio_np = stem_wav.cpu().numpy().T # [T, C]
|
|
67
|
+
sf.write(str(out_path), audio_np, model.samplerate, format="MP3")
|
|
68
|
+
output_paths[stem_name] = str(out_path)
|
|
69
|
+
print(f" {stem_name:8s} → {out_path}")
|
|
70
|
+
|
|
71
|
+
elapsed = time.perf_counter() - start
|
|
72
|
+
print(f"Done in {elapsed:.2f}s")
|
|
73
|
+
return output_paths
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "audio-separation"
|
|
3
|
+
version = "0.1.2"
|
|
4
|
+
description = "Local vocal removal"
|
|
5
|
+
authors = ["Felipe Infantino <felipe.infantino@icloud.com>"]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
packages = [{ include = "app" }]
|
|
8
|
+
|
|
9
|
+
[tool.poetry.dependencies]
|
|
10
|
+
python = ">=3.11,<3.15"
|
|
11
|
+
pydub = "^0.25.1"
|
|
12
|
+
librosa = "^0.11.0"
|
|
13
|
+
resampy = "^0.4.3"
|
|
14
|
+
|
|
15
|
+
# torch & torchaudio are pulled in transitively by demucs.
|
|
16
|
+
# No explicit source: PyPI ships macOS (arm64 + x86_64) wheels natively.
|
|
17
|
+
# On Linux/Windows you can pin source = "pytorch-cpu" for the smaller CPU build.
|
|
18
|
+
torch = "^2.10"
|
|
19
|
+
torchaudio = "^2.10"
|
|
20
|
+
|
|
21
|
+
huggingface-hub = "^0.23"
|
|
22
|
+
|
|
23
|
+
# ---------------------------------------------------------------------------
|
|
24
|
+
# Sources
|
|
25
|
+
# ---------------------------------------------------------------------------
|
|
26
|
+
# Default PyPI
|
|
27
|
+
tqdm = "^4.67.3"
|
|
28
|
+
demucs = "^4.0.1"
|
|
29
|
+
[[tool.poetry.source]]
|
|
30
|
+
name = "pypi"
|
|
31
|
+
priority = "primary"
|
|
32
|
+
|
|
33
|
+
# PyTorch CPU-only wheels (smaller, works everywhere).
|
|
34
|
+
# Swap the URL for a CUDA build if you need GPU locally:
|
|
35
|
+
# https://download.pytorch.org/whl/cu121 (CUDA 12.1)
|
|
36
|
+
# https://download.pytorch.org/whl/cu124 (CUDA 12.4)
|
|
37
|
+
[[tool.poetry.source]]
|
|
38
|
+
name = "pytorch-cpu"
|
|
39
|
+
url = "https://download.pytorch.org/whl/cpu"
|
|
40
|
+
priority = "explicit"
|
|
41
|
+
|
|
42
|
+
# ---------------------------------------------------------------------------
|
|
43
|
+
# Scripts
|
|
44
|
+
# ---------------------------------------------------------------------------
|
|
45
|
+
[tool.poetry.scripts]
|
|
46
|
+
audio-separation = "app.cli:main"
|
|
47
|
+
|
|
48
|
+
# ---------------------------------------------------------------------------
|
|
49
|
+
# Build system
|
|
50
|
+
# ---------------------------------------------------------------------------
|
|
51
|
+
[build-system]
|
|
52
|
+
requires = ["poetry-core>=2.0.0"]
|
|
53
|
+
build-backend = "poetry.core.masonry.api"
|