audio-helper 1.5.5__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.
- audio_helper-1.5.5/LICENSE +29 -0
- audio_helper-1.5.5/PKG-INFO +228 -0
- audio_helper-1.5.5/README.md +177 -0
- audio_helper-1.5.5/audio_helper/__init__.py +55 -0
- audio_helper-1.5.5/audio_helper/api.py +369 -0
- audio_helper-1.5.5/audio_helper/cli_argparse.py +369 -0
- audio_helper-1.5.5/audio_helper/cli_click.py +286 -0
- audio_helper-1.5.5/audio_helper/main.py +1460 -0
- audio_helper-1.5.5/audio_helper/mcp.py +90 -0
- audio_helper-1.5.5/audio_helper.egg-info/PKG-INFO +228 -0
- audio_helper-1.5.5/audio_helper.egg-info/SOURCES.txt +21 -0
- audio_helper-1.5.5/audio_helper.egg-info/dependency_links.txt +1 -0
- audio_helper-1.5.5/audio_helper.egg-info/entry_points.txt +4 -0
- audio_helper-1.5.5/audio_helper.egg-info/requires.txt +31 -0
- audio_helper-1.5.5/audio_helper.egg-info/top_level.txt +1 -0
- audio_helper-1.5.5/pyproject.toml +109 -0
- audio_helper-1.5.5/setup.cfg +4 -0
- audio_helper-1.5.5/tests/test_api.py +61 -0
- audio_helper-1.5.5/tests/test_audio_helper.py +185 -0
- audio_helper-1.5.5/tests/test_cli.py +104 -0
- audio_helper-1.5.5/tests/test_local.py +224 -0
- audio_helper-1.5.5/tests/test_mcp.py +39 -0
- audio_helper-1.5.5/tests/test_unit.py +74 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Warith HARCHAOUI
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: audio-helper
|
|
3
|
+
Version: 1.5.5
|
|
4
|
+
Summary: Audio Helper โ utility functions for processing audio files exposed as library, argparse CLI, click CLI, FastAPI HTTP surface and MCP tools. Load audio, convert formats, separate audio sources (Demucs), split and concatenate audio. Shannon-correct resampling via ffmpeg/libswresample.
|
|
5
|
+
Author-email: Warith HARCHAOUI <warithmetics@deraison.ai>
|
|
6
|
+
License: BSD-3-Clause
|
|
7
|
+
Project-URL: Homepage, https://github.com/warith-harchaoui/audio-helper
|
|
8
|
+
Project-URL: Issues, https://github.com/warith-harchaoui/audio-helper/issues
|
|
9
|
+
Keywords: audio,ffmpeg,scipy,demucs,resampling,pcm
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Multimedia :: Sound/Audio
|
|
20
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Conversion
|
|
21
|
+
Requires-Python: <3.14,>=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: os-helper>=1.4.2
|
|
25
|
+
Requires-Dist: ffmpeg-python<0.3,>=0.2.0
|
|
26
|
+
Requires-Dist: tqdm<5,>=4.67.1
|
|
27
|
+
Requires-Dist: scipy<2,>=1.15.1
|
|
28
|
+
Requires-Dist: numpy>=1.24
|
|
29
|
+
Provides-Extra: demucs
|
|
30
|
+
Requires-Dist: torch<3,>=2.5.1; extra == "demucs"
|
|
31
|
+
Requires-Dist: torchaudio<3,>=2.5.1; extra == "demucs"
|
|
32
|
+
Provides-Extra: cli
|
|
33
|
+
Requires-Dist: click<9,>=8.1; extra == "cli"
|
|
34
|
+
Provides-Extra: api
|
|
35
|
+
Requires-Dist: fastapi<1,>=0.111; extra == "api"
|
|
36
|
+
Requires-Dist: uvicorn<1,>=0.30; extra == "api"
|
|
37
|
+
Requires-Dist: python-multipart<1,>=0.0.9; extra == "api"
|
|
38
|
+
Provides-Extra: mcp
|
|
39
|
+
Requires-Dist: fastapi-mcp<1,>=0.3; extra == "mcp"
|
|
40
|
+
Requires-Dist: fastapi<1,>=0.111; extra == "mcp"
|
|
41
|
+
Requires-Dist: uvicorn<1,>=0.30; extra == "mcp"
|
|
42
|
+
Requires-Dist: python-multipart<1,>=0.0.9; extra == "mcp"
|
|
43
|
+
Provides-Extra: dev
|
|
44
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
45
|
+
Requires-Dist: httpx>=0.27; extra == "dev"
|
|
46
|
+
Requires-Dist: click<9,>=8.1; extra == "dev"
|
|
47
|
+
Requires-Dist: fastapi<1,>=0.111; extra == "dev"
|
|
48
|
+
Requires-Dist: python-multipart<1,>=0.0.9; extra == "dev"
|
|
49
|
+
Requires-Dist: fastapi-mcp<1,>=0.3; extra == "dev"
|
|
50
|
+
Dynamic: license-file
|
|
51
|
+
|
|
52
|
+
# Audio Helper
|
|
53
|
+
|
|
54
|
+
[๐ซ๐ท](https://github.com/warith-harchaoui/audio-helper/blob/main/LISEZMOI.md) ยท [๐ฌ๐ง](https://github.com/warith-harchaoui/audio-helper/blob/main/README.md)
|
|
55
|
+
|
|
56
|
+
[](https://github.com/warith-harchaoui/audio-helper/actions/workflows/ci.yml) [](LICENSE) [](#)
|
|
57
|
+
|
|
58
|
+
`Audio Helper` belongs to a collection of libraries called `AI Helpers` developed for building Artificial Intelligence.
|
|
59
|
+
|
|
60
|
+
[๐ AI Helpers](https://harchaoui.org/warith/ai-helpers)
|
|
61
|
+
|
|
62
|
+
[](https://harchaoui.org/warith/ai-helpers)
|
|
63
|
+
|
|
64
|
+
Audio Helper is a Python library that provides utility functions for processing audio files. It includes features like loading audio, converting formats, separating audio sources, and splitting and concatenating audio files.
|
|
65
|
+
|
|
66
|
+
# Installation
|
|
67
|
+
|
|
68
|
+
**Prerequisites** โ **Python 3.10โ3.13** and **git**, **ffmpeg**, cross-platform:
|
|
69
|
+
|
|
70
|
+
- ๐ **macOS** ([Homebrew](https://brew.sh)): `brew install python git ffmpeg`
|
|
71
|
+
- ๐ง **Ubuntu/Debian**: `sudo apt update && sudo apt install -y python3 python3-pip git ffmpeg`
|
|
72
|
+
- ๐ช **Windows** (PowerShell): `winget install Python.Python.3.12 Git.Git Gyan.FFmpeg`
|
|
73
|
+
|
|
74
|
+
Then install the package:
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
## Install Package
|
|
78
|
+
|
|
79
|
+
We recommend using Python environments. Check this link if you're unfamiliar with setting one up:
|
|
80
|
+
|
|
81
|
+
[๐ฅธ Tech tips](https://harchaoui.org/warith/4ml/#install)
|
|
82
|
+
|
|
83
|
+
## Install `ffmpeg`
|
|
84
|
+
To install Audio Helper, you must install `ffmpeg`:
|
|
85
|
+
|
|
86
|
+
- For macos ๐
|
|
87
|
+
|
|
88
|
+
Get [brew](https://brew.sh)
|
|
89
|
+
```bash
|
|
90
|
+
brew install ffmpeg
|
|
91
|
+
```
|
|
92
|
+
- For Ubuntu ๐ง
|
|
93
|
+
```bash
|
|
94
|
+
sudo apt install ffmpeg
|
|
95
|
+
```
|
|
96
|
+
- For Windows ๐ช
|
|
97
|
+
|
|
98
|
+
Go to the [FFmpeg website](https://ffmpeg.org/download.html) and follow the instructions for downloading FFmpeg. You'll need to manually add FFmpeg to your system PATH.
|
|
99
|
+
|
|
100
|
+
and finally we still discuss between different python package managers and try to support as much as possible
|
|
101
|
+
|
|
102
|
+
Audio Helper ships in two flavors. Pick the one you need:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Core audio utilities only (load, convert, split, concatenate, silent audio, chunks)
|
|
106
|
+
pip install --force-reinstall --no-cache-dir \
|
|
107
|
+
"git+https://github.com/warith-harchaoui/audio-helper.git@v1.5.5"
|
|
108
|
+
|
|
109
|
+
# Add Demucs source separation (pulls in torch + torchaudio, ~2 GB)
|
|
110
|
+
pip install --force-reinstall --no-cache-dir \
|
|
111
|
+
"audio-helper[demucs] @ git+https://github.com/warith-harchaoui/audio-helper.git@v1.5.5"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
If you call `separate_sources` without the `[demucs]` extra, the function raises an `ImportError` pointing you back here.
|
|
115
|
+
|
|
116
|
+
# Usage
|
|
117
|
+
|
|
118
|
+
For the full catalog of recipes, see [๐ EXAMPLES.md](https://github.com/warith-harchaoui/audio-helper/blob/main/EXAMPLES.md).
|
|
119
|
+
|
|
120
|
+
Hereโs an example of how to use Audio Helper to load, convert, and split an audio file:
|
|
121
|
+
|
|
122
|
+
(download [example.mp3](https://harchaoui.org/warith/example.mp3) )
|
|
123
|
+
|
|
124
|
+
It is part of a JFK speech that is badly recorded
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
import audio_helper as ah
|
|
128
|
+
|
|
129
|
+
# Load an audio file
|
|
130
|
+
audio_file = "example.mp3"
|
|
131
|
+
audio, sample_rate = ah.load_audio(audio_file)
|
|
132
|
+
|
|
133
|
+
# Convert the audio file to a different format
|
|
134
|
+
output_audio = "audio_tests/example.wav"
|
|
135
|
+
ah.sound_converter(audio_file, output_audio)
|
|
136
|
+
|
|
137
|
+
# Split the audio file into chunks of 30 seconds
|
|
138
|
+
chunks = ah.split_audio_regularly(audio_file, "audio_tests/chunks_folder", split_time=30.0, overwrite = True)
|
|
139
|
+
# Concatenate the chunks back together
|
|
140
|
+
new_concatenated_audio = "audio_tests/concatenated.wav"
|
|
141
|
+
concatenated_audio = ah.audio_concatenation(chunks, output_audio_filename = new_concatenated_audio)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Another cool example is about source separation (DEMUCS from META) with AI separating one audio track into 4 tracks:
|
|
145
|
+
- vocals
|
|
146
|
+
- drums
|
|
147
|
+
- bass
|
|
148
|
+
- other
|
|
149
|
+
|
|
150
|
+
It works with speech and songs
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
import audio_helper as ah
|
|
154
|
+
|
|
155
|
+
audio_path = "input_audio.m4a"
|
|
156
|
+
|
|
157
|
+
sources = ah.separate_sources(
|
|
158
|
+
audio_path,
|
|
159
|
+
output_folder="audio_tests",
|
|
160
|
+
device = "cpu", # or "cuda" if GPU or nothing to let it decide
|
|
161
|
+
nb_workers = 4, # ignored if not cpu
|
|
162
|
+
output_format = "mp3",
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
print(sources)
|
|
166
|
+
# {'vocals': 'audio_tests/vocals.mp3', 'drums': 'audio_tests/drums.mp3', 'bass': 'audio_tests/bass.mp3', 'other': 'audio_tests/other.mp3'}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
# Features
|
|
170
|
+
- Audio Loading: load files with optional resampling and mono downmix.
|
|
171
|
+
- Sound Conversion: ffmpeg-backed format/sample-rate/channels conversion.
|
|
172
|
+
- Source Separation: vocals / drums / bass / other via Demucs (optional `[demucs]` extra).
|
|
173
|
+
- Audio Splitting: fixed-duration chunks and arbitrary `[start, end]` slices.
|
|
174
|
+
- Concatenation: head-to-tail join into any ffmpeg-supported container.
|
|
175
|
+
- Silent Audio Generation: write silence of a specified duration.
|
|
176
|
+
- Room-Tone Mixing: pink/white/brown ambient noise to mask edits between cuts.
|
|
177
|
+
- Similarity: MFCC-based `sound_resemblance` score for A/B comparison.
|
|
178
|
+
- Feature Extraction: scipy-based Mel / MFCC primitives.
|
|
179
|
+
|
|
180
|
+
# Multi-surface exposure
|
|
181
|
+
|
|
182
|
+
`audio-helper` is not just a library โ the same functions are exposed
|
|
183
|
+
as a CLI, a FastAPI HTTP surface, and an MCP tool set:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
# Python library (default)
|
|
187
|
+
import audio_helper as ah
|
|
188
|
+
|
|
189
|
+
# argparse-based CLI (installed automatically)
|
|
190
|
+
audio-helper convert --input in.mp3 --output out.wav --freq 44100
|
|
191
|
+
audio-helper split --input in.mp3 --output-dir chunks/ --seconds 30
|
|
192
|
+
audio-helper separate --input mix.mp3 --output-dir stems/
|
|
193
|
+
audio-helper resemblance --a a.mp3 --b b.mp3
|
|
194
|
+
|
|
195
|
+
# click-based CLI twin (needs the [cli] extra)
|
|
196
|
+
pip install 'audio-helper[cli] @ git+https://github.com/warith-harchaoui/audio-helper.git@v1.5.5'
|
|
197
|
+
audio-helper-click convert --input in.mp3 --output out.wav --freq 44100
|
|
198
|
+
|
|
199
|
+
# FastAPI HTTP surface (needs the [api] extra)
|
|
200
|
+
pip install 'audio-helper[api] @ git+https://github.com/warith-harchaoui/audio-helper.git@v1.5.5'
|
|
201
|
+
uvicorn audio_helper.api:app --port 8000
|
|
202
|
+
# โ OpenAPI docs at http://localhost:8000/docs
|
|
203
|
+
|
|
204
|
+
# MCP tools over FastAPI (needs the [api,mcp] extras)
|
|
205
|
+
pip install 'audio-helper[api,mcp] @ git+https://github.com/warith-harchaoui/audio-helper.git@v1.5.5'
|
|
206
|
+
audio-helper-mcp # serves FastAPI + MCP on port 8000
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Docker image (light, without Demucs by default):
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
docker build -t audio-helper .
|
|
213
|
+
docker run --rm -p 8000:8000 audio-helper
|
|
214
|
+
# with Demucs:
|
|
215
|
+
docker build --build-arg WITH_DEMUCS=1 -t audio-helper:demucs .
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
An innovative GUI plan (canvas-based recipe editor, ear-first
|
|
219
|
+
comparator, MFCC-cluster batch view) lives in [GUI.md](https://github.com/warith-harchaoui/audio-helper/blob/main/GUI.md).
|
|
220
|
+
|
|
221
|
+
The competitive landscape (librosa, torchaudio, pydub, essentia,
|
|
222
|
+
Demucs, Spleeter, โฆ) is analysed in [LANDSCAPE.md](https://github.com/warith-harchaoui/audio-helper/blob/main/LANDSCAPE.md).
|
|
223
|
+
|
|
224
|
+
# Author
|
|
225
|
+
- [Warith HARCHAOUI](https://linkedin.com/in/warith-harchaoui)
|
|
226
|
+
|
|
227
|
+
# Acknowledgements
|
|
228
|
+
Special thanks to [Mohamed Chelali](https://mchelali.github.io) and [Bachir Zerroug](https://www.linkedin.com/in/bachirzerroug) for fruitful discussions.
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Audio Helper
|
|
2
|
+
|
|
3
|
+
[๐ซ๐ท](https://github.com/warith-harchaoui/audio-helper/blob/main/LISEZMOI.md) ยท [๐ฌ๐ง](https://github.com/warith-harchaoui/audio-helper/blob/main/README.md)
|
|
4
|
+
|
|
5
|
+
[](https://github.com/warith-harchaoui/audio-helper/actions/workflows/ci.yml) [](LICENSE) [](#)
|
|
6
|
+
|
|
7
|
+
`Audio Helper` belongs to a collection of libraries called `AI Helpers` developed for building Artificial Intelligence.
|
|
8
|
+
|
|
9
|
+
[๐ AI Helpers](https://harchaoui.org/warith/ai-helpers)
|
|
10
|
+
|
|
11
|
+
[](https://harchaoui.org/warith/ai-helpers)
|
|
12
|
+
|
|
13
|
+
Audio Helper is a Python library that provides utility functions for processing audio files. It includes features like loading audio, converting formats, separating audio sources, and splitting and concatenating audio files.
|
|
14
|
+
|
|
15
|
+
# Installation
|
|
16
|
+
|
|
17
|
+
**Prerequisites** โ **Python 3.10โ3.13** and **git**, **ffmpeg**, cross-platform:
|
|
18
|
+
|
|
19
|
+
- ๐ **macOS** ([Homebrew](https://brew.sh)): `brew install python git ffmpeg`
|
|
20
|
+
- ๐ง **Ubuntu/Debian**: `sudo apt update && sudo apt install -y python3 python3-pip git ffmpeg`
|
|
21
|
+
- ๐ช **Windows** (PowerShell): `winget install Python.Python.3.12 Git.Git Gyan.FFmpeg`
|
|
22
|
+
|
|
23
|
+
Then install the package:
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Install Package
|
|
27
|
+
|
|
28
|
+
We recommend using Python environments. Check this link if you're unfamiliar with setting one up:
|
|
29
|
+
|
|
30
|
+
[๐ฅธ Tech tips](https://harchaoui.org/warith/4ml/#install)
|
|
31
|
+
|
|
32
|
+
## Install `ffmpeg`
|
|
33
|
+
To install Audio Helper, you must install `ffmpeg`:
|
|
34
|
+
|
|
35
|
+
- For macos ๐
|
|
36
|
+
|
|
37
|
+
Get [brew](https://brew.sh)
|
|
38
|
+
```bash
|
|
39
|
+
brew install ffmpeg
|
|
40
|
+
```
|
|
41
|
+
- For Ubuntu ๐ง
|
|
42
|
+
```bash
|
|
43
|
+
sudo apt install ffmpeg
|
|
44
|
+
```
|
|
45
|
+
- For Windows ๐ช
|
|
46
|
+
|
|
47
|
+
Go to the [FFmpeg website](https://ffmpeg.org/download.html) and follow the instructions for downloading FFmpeg. You'll need to manually add FFmpeg to your system PATH.
|
|
48
|
+
|
|
49
|
+
and finally we still discuss between different python package managers and try to support as much as possible
|
|
50
|
+
|
|
51
|
+
Audio Helper ships in two flavors. Pick the one you need:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Core audio utilities only (load, convert, split, concatenate, silent audio, chunks)
|
|
55
|
+
pip install --force-reinstall --no-cache-dir \
|
|
56
|
+
"git+https://github.com/warith-harchaoui/audio-helper.git@v1.5.5"
|
|
57
|
+
|
|
58
|
+
# Add Demucs source separation (pulls in torch + torchaudio, ~2 GB)
|
|
59
|
+
pip install --force-reinstall --no-cache-dir \
|
|
60
|
+
"audio-helper[demucs] @ git+https://github.com/warith-harchaoui/audio-helper.git@v1.5.5"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
If you call `separate_sources` without the `[demucs]` extra, the function raises an `ImportError` pointing you back here.
|
|
64
|
+
|
|
65
|
+
# Usage
|
|
66
|
+
|
|
67
|
+
For the full catalog of recipes, see [๐ EXAMPLES.md](https://github.com/warith-harchaoui/audio-helper/blob/main/EXAMPLES.md).
|
|
68
|
+
|
|
69
|
+
Hereโs an example of how to use Audio Helper to load, convert, and split an audio file:
|
|
70
|
+
|
|
71
|
+
(download [example.mp3](https://harchaoui.org/warith/example.mp3) )
|
|
72
|
+
|
|
73
|
+
It is part of a JFK speech that is badly recorded
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
import audio_helper as ah
|
|
77
|
+
|
|
78
|
+
# Load an audio file
|
|
79
|
+
audio_file = "example.mp3"
|
|
80
|
+
audio, sample_rate = ah.load_audio(audio_file)
|
|
81
|
+
|
|
82
|
+
# Convert the audio file to a different format
|
|
83
|
+
output_audio = "audio_tests/example.wav"
|
|
84
|
+
ah.sound_converter(audio_file, output_audio)
|
|
85
|
+
|
|
86
|
+
# Split the audio file into chunks of 30 seconds
|
|
87
|
+
chunks = ah.split_audio_regularly(audio_file, "audio_tests/chunks_folder", split_time=30.0, overwrite = True)
|
|
88
|
+
# Concatenate the chunks back together
|
|
89
|
+
new_concatenated_audio = "audio_tests/concatenated.wav"
|
|
90
|
+
concatenated_audio = ah.audio_concatenation(chunks, output_audio_filename = new_concatenated_audio)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Another cool example is about source separation (DEMUCS from META) with AI separating one audio track into 4 tracks:
|
|
94
|
+
- vocals
|
|
95
|
+
- drums
|
|
96
|
+
- bass
|
|
97
|
+
- other
|
|
98
|
+
|
|
99
|
+
It works with speech and songs
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
import audio_helper as ah
|
|
103
|
+
|
|
104
|
+
audio_path = "input_audio.m4a"
|
|
105
|
+
|
|
106
|
+
sources = ah.separate_sources(
|
|
107
|
+
audio_path,
|
|
108
|
+
output_folder="audio_tests",
|
|
109
|
+
device = "cpu", # or "cuda" if GPU or nothing to let it decide
|
|
110
|
+
nb_workers = 4, # ignored if not cpu
|
|
111
|
+
output_format = "mp3",
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
print(sources)
|
|
115
|
+
# {'vocals': 'audio_tests/vocals.mp3', 'drums': 'audio_tests/drums.mp3', 'bass': 'audio_tests/bass.mp3', 'other': 'audio_tests/other.mp3'}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
# Features
|
|
119
|
+
- Audio Loading: load files with optional resampling and mono downmix.
|
|
120
|
+
- Sound Conversion: ffmpeg-backed format/sample-rate/channels conversion.
|
|
121
|
+
- Source Separation: vocals / drums / bass / other via Demucs (optional `[demucs]` extra).
|
|
122
|
+
- Audio Splitting: fixed-duration chunks and arbitrary `[start, end]` slices.
|
|
123
|
+
- Concatenation: head-to-tail join into any ffmpeg-supported container.
|
|
124
|
+
- Silent Audio Generation: write silence of a specified duration.
|
|
125
|
+
- Room-Tone Mixing: pink/white/brown ambient noise to mask edits between cuts.
|
|
126
|
+
- Similarity: MFCC-based `sound_resemblance` score for A/B comparison.
|
|
127
|
+
- Feature Extraction: scipy-based Mel / MFCC primitives.
|
|
128
|
+
|
|
129
|
+
# Multi-surface exposure
|
|
130
|
+
|
|
131
|
+
`audio-helper` is not just a library โ the same functions are exposed
|
|
132
|
+
as a CLI, a FastAPI HTTP surface, and an MCP tool set:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
# Python library (default)
|
|
136
|
+
import audio_helper as ah
|
|
137
|
+
|
|
138
|
+
# argparse-based CLI (installed automatically)
|
|
139
|
+
audio-helper convert --input in.mp3 --output out.wav --freq 44100
|
|
140
|
+
audio-helper split --input in.mp3 --output-dir chunks/ --seconds 30
|
|
141
|
+
audio-helper separate --input mix.mp3 --output-dir stems/
|
|
142
|
+
audio-helper resemblance --a a.mp3 --b b.mp3
|
|
143
|
+
|
|
144
|
+
# click-based CLI twin (needs the [cli] extra)
|
|
145
|
+
pip install 'audio-helper[cli] @ git+https://github.com/warith-harchaoui/audio-helper.git@v1.5.5'
|
|
146
|
+
audio-helper-click convert --input in.mp3 --output out.wav --freq 44100
|
|
147
|
+
|
|
148
|
+
# FastAPI HTTP surface (needs the [api] extra)
|
|
149
|
+
pip install 'audio-helper[api] @ git+https://github.com/warith-harchaoui/audio-helper.git@v1.5.5'
|
|
150
|
+
uvicorn audio_helper.api:app --port 8000
|
|
151
|
+
# โ OpenAPI docs at http://localhost:8000/docs
|
|
152
|
+
|
|
153
|
+
# MCP tools over FastAPI (needs the [api,mcp] extras)
|
|
154
|
+
pip install 'audio-helper[api,mcp] @ git+https://github.com/warith-harchaoui/audio-helper.git@v1.5.5'
|
|
155
|
+
audio-helper-mcp # serves FastAPI + MCP on port 8000
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Docker image (light, without Demucs by default):
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
docker build -t audio-helper .
|
|
162
|
+
docker run --rm -p 8000:8000 audio-helper
|
|
163
|
+
# with Demucs:
|
|
164
|
+
docker build --build-arg WITH_DEMUCS=1 -t audio-helper:demucs .
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
An innovative GUI plan (canvas-based recipe editor, ear-first
|
|
168
|
+
comparator, MFCC-cluster batch view) lives in [GUI.md](https://github.com/warith-harchaoui/audio-helper/blob/main/GUI.md).
|
|
169
|
+
|
|
170
|
+
The competitive landscape (librosa, torchaudio, pydub, essentia,
|
|
171
|
+
Demucs, Spleeter, โฆ) is analysed in [LANDSCAPE.md](https://github.com/warith-harchaoui/audio-helper/blob/main/LANDSCAPE.md).
|
|
172
|
+
|
|
173
|
+
# Author
|
|
174
|
+
- [Warith HARCHAOUI](https://linkedin.com/in/warith-harchaoui)
|
|
175
|
+
|
|
176
|
+
# Acknowledgements
|
|
177
|
+
Special thanks to [Mohamed Chelali](https://mchelali.github.io) and [Bachir Zerroug](https://www.linkedin.com/in/bachirzerroug) for fruitful discussions.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Audio Helper โ public API surface.
|
|
3
|
+
|
|
4
|
+
Re-exports the utility functions from :mod:`audio_helper.main` so that
|
|
5
|
+
downstream code can simply write ``import audio_helper as ah`` and reach
|
|
6
|
+
every supported operation (load, save, convert, split, concatenate,
|
|
7
|
+
silence generation, room-tone mix, MFCC similarity, and optional Demucs
|
|
8
|
+
source separation) without knowing about the module layout.
|
|
9
|
+
|
|
10
|
+
Usage Example
|
|
11
|
+
-------------
|
|
12
|
+
>>> import audio_helper as ah
|
|
13
|
+
>>> audio, sr = ah.load_audio("example.mp3", to_numpy=True, to_mono=True)
|
|
14
|
+
>>> ah.sound_converter("example.mp3", "example.wav")
|
|
15
|
+
>>> chunks = ah.split_audio_regularly("example.mp3", "chunks/", split_time=30.0)
|
|
16
|
+
|
|
17
|
+
Author
|
|
18
|
+
------
|
|
19
|
+
Warith Harchaoui, Ph.D. โ https://linkedin.com/in/warith-harchaoui/
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
__author__ = "Warith Harchaoui, Ph.D."
|
|
23
|
+
__email__ = "warithmetics@deraison.ai"
|
|
24
|
+
|
|
25
|
+
# Specify the public API of this module using __all__
|
|
26
|
+
__all__ = [
|
|
27
|
+
"is_valid_audio_file",
|
|
28
|
+
"get_audio_duration",
|
|
29
|
+
"load_audio",
|
|
30
|
+
"sound_converter",
|
|
31
|
+
"separate_sources",
|
|
32
|
+
"extract_audio_chunk",
|
|
33
|
+
"generate_silent_audio",
|
|
34
|
+
"audio_concatenation",
|
|
35
|
+
"mix_room_tone",
|
|
36
|
+
"split_audio_regularly",
|
|
37
|
+
"save_audio",
|
|
38
|
+
"sound_resemblance",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
from .main import (
|
|
43
|
+
is_valid_audio_file,
|
|
44
|
+
get_audio_duration,
|
|
45
|
+
load_audio,
|
|
46
|
+
sound_converter,
|
|
47
|
+
separate_sources,
|
|
48
|
+
extract_audio_chunk,
|
|
49
|
+
generate_silent_audio,
|
|
50
|
+
audio_concatenation,
|
|
51
|
+
mix_room_tone,
|
|
52
|
+
split_audio_regularly,
|
|
53
|
+
save_audio,
|
|
54
|
+
sound_resemblance,
|
|
55
|
+
)
|