Commit 10fa098
authored
* Add file-level chunking for large audio files (#158)
- Add AudioChunker class for splitting/merging audio files
- Add chunk_duration parameter to Separator class
- Implement _process_with_chunking() for chunk-based processing
- Add --chunk_duration CLI option
- Chunks are processed sequentially with simple concatenation
- GPU cache cleared between chunks to manage memory
This implementation follows the reference approach from issue #44
without overlap/crossfade (can be added in future PR if needed).
* Add comprehensive unit tests for AudioChunker
- 17 test cases covering initialization, splitting, merging
- Tests for edge cases (short files, exact multiples, boundaries)
- Integration tests with actual audio segments
- Mock tests for error handling
- All tests passing
* docs: Add documentation for large file processing with chunking
Updated README.md with comprehensive section on using --chunk_duration
option for processing large audio files. Documents the split-process-merge
workflow, benefits, recommendations, and limitation (simple concatenation).
Relates to #158
* fix: Ensure chunk files are saved to temp directory and cleaned up properly
Fixed two issues in chunk processing:
1. Convert relative output file paths to absolute paths when collecting chunk results
2. Temporarily change both Separator and model_instance output_dir to temp directory during chunk processing
This ensures chunk files are saved to the temp directory and automatically
cleaned up, keeping the output directory clean with only final merged files.
Relates to #158
* refactor: Simplify docstrings and remove redundant comments
- Simplified audio_chunking.py module docstring to match existing codebase style
- Removed self-explanatory inline comments in _process_with_chunking
- Kept important comments for non-obvious operations (GPU cache clearing)
- All unit tests passing (17/17)
Relates to #158
* fix: Adjust log levels for internal operations
- Changed 'Loading audio file' to debug (internal AudioChunker operation)
- Changed 'Created temporary directory' to debug (low-priority detail)
- Removed 'File-level chunking enabled' log from __init__ (unnecessary, already logged when actually used)
- INFO level now shows only user-relevant information:
- Splitting/merging progress
- Chunk processing status
- Completion messages
Relates to #158
* refactor: Remove redundant 'Successfully split' log message
The completion message after splitting is redundant since we already
log the splitting operation. Follows existing codebase pattern where
'completed' messages are typically debug level.
Relates to #158
* Fix multi-stem model support in chunking
- Replace hardcoded primary/secondary lists with dynamic stem dictionary
- Extract stem names from chunk filenames using regex pattern
- Support 2-stem, 4-stem, and 6-stem models (MDX, Demucs, Demucs 6s)
- Add re module import for stem name extraction
- Update README to document multi-stem support
Previously, only the first 2 stems were preserved when using chunking
with 4-stem or 6-stem models. This fix ensures all stems are correctly
processed and merged.
The chunking feature now supports:
- 2-stem models (e.g., MDX): Vocals + Instrumental
- 4-stem models (e.g., Demucs): Drums, Bass, Other, Vocals
- 6-stem models (e.g., Demucs 6s): Bass, Drums, Other, Vocals, Guitar, Piano
* Add comprehensive unit tests for chunking functionality
Add 15 new unit tests for Separator chunking logic, covering:
**Basic Functionality (6 tests):**
- 2-stem model compatibility (Vocals, Instrumental)
- 4-stem Demucs model (Drums, Bass, Other, Vocals)
- 6-stem Demucs model (all 6 stems)
- Stem name extraction from filenames with regex
- Fallback handling for non-matching patterns
- Sorted stem order in merged output
**Internal Logic & State Management (6 tests):**
- State restoration after chunking (chunk_duration, output_dir)
- GPU cache clearing between chunks
- Temporary directory cleanup verification
- State restoration on error (exception handling)
- AudioChunker initialization with correct parameters
- custom_output_names parameter handling
**Edge Cases (3 tests):**
- Empty output handling (no stems produced)
- Inconsistent stem counts across chunks
- Filename pattern match failure with fallback naming
Total test coverage: 32 tests (17 AudioChunker + 15 Separator chunking)
All tests passing.
* Fix test_cli.py to include chunk_duration parameter
The common_expected_args fixture was missing the new chunk_duration
parameter added to Separator.__init__(), causing all CLI tests to fail
in CI. Also corrected parameter order to match actual constructor
(use_soundfile before use_autocast).
Fixes:
- Added chunk_duration: None to expected args
- Reordered use_soundfile/use_autocast to match Separator.__init__()
All tests/unit/test_cli.py tests now pass (13 passed, 2 skipped).
* Fix ruff lint errors in test_audio_chunking.py
Addressed CodeRabbit feedback:
1. Renamed unused mock parameter mock_makedirs to _mock_makedirs (ARG002)
2. Renamed unused lambda parameter key to _ (ARG005)
3. Replaced hardcoded /tmp paths with pytest tmp_path fixture (S108)
All 17 tests still pass after these changes.
1 parent bfa7380 commit 10fa098
File tree
7 files changed
+1263
-1
lines changed- audio_separator
- separator
- utils
- tests/unit
7 files changed
+1263
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
281 | 321 | | |
282 | 322 | | |
283 | 323 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
| 98 | + | |
97 | 99 | | |
98 | 100 | | |
99 | 101 | | |
| |||
182 | 184 | | |
183 | 185 | | |
184 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
185 | 192 | | |
186 | 193 | | |
187 | 194 | | |
| |||
866 | 873 | | |
867 | 874 | | |
868 | 875 | | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
869 | 888 | | |
870 | 889 | | |
871 | 890 | | |
| |||
899 | 918 | | |
900 | 919 | | |
901 | 920 | | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
902 | 1032 | | |
903 | 1033 | | |
904 | 1034 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| 73 | + | |
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
| |||
200 | 202 | | |
201 | 203 | | |
202 | 204 | | |
| 205 | + | |
203 | 206 | | |
204 | 207 | | |
205 | 208 | | |
| |||
0 commit comments