Create and activate a virtual environment
!curl -LsSf https://astral.sh/uv/install.sh | shcurl: /MATLAB/bin/glnxa64/libcurl.so.4: no version information available (required by curl)
downloading uv 0.8.15 x86_64-unknown-linux-gnu
curl: /MATLAB/bin/glnxa64/libcurl.so.4: no version information available (required by curl)
no checksums to verify
installing to /home/matlab/.local/bin
uv
uvx
everything's installed!
To add $HOME/.local/bin to your PATH, either restart your shell or run:
source $HOME/.local/bin/env (sh, bash, zsh)
source $HOME/.local/bin/env.fish (fish)
% 1) Point PATH to where uv was installed
setenv('PATH', [getenv('HOME') '/.local/bin:' getenv('PATH')]);
% Sanity checks
system('which uv'); % should print ~/.local/bin/uv/home/matlab/.local/bin/uv
system('uv --version'); uv 0.8.15
system('uvx --version');uvx 0.8.15
system('python --version');Python 3.10.17
Setting the --clear flag to reset already existing environment called env that might exist in the same location
% 2) Create a venv OUTSIDE MATLAB Drive (symlinks are fine here)
system('~/.local/bin/uv venv --clear /home/matlab/venvs/env');Using CPython 3.10.17 interpreter at: �[36m/usr/bin/python�[39m
Creating virtual environment at: �[36m/home/matlab/venvs/env�[39m
Activate with: �[32msource /home/matlab/venvs/env/bin/activate�[39m
% 3) "Activate" it for this MATLAB session
setenv('VIRTUAL_ENV','/home/matlab/venvs/env');
setenv('PATH', ['/home/matlab/venvs/env/bin:' getenv('PATH')]);Install Numpy (in quiet mode with flag -q) and time it
system('time uv pip install -q numpy');real 0m0.078s
user 0m0.009s
sys 0m0.028s
Install pytorch
tic;
system('uv pip install -q torch');
tocElapsed time is 0.291048 seconds.
system('uv pip install demucs');�[2mUsing Python 3.10.17 environment at: /home/matlab/venvs/env�[0m
�[37m⠋�[0m �[2mResolving dependencies... �[0m
�[2K�[37m⠙�[0m �[2mResolving dependencies... �[0m
�[2K�[37m⠋�[0m �[2mResolving dependencies... �[0m
�[2K�[37m⠙�[0m �[2mResolving dependencies... �[0m
�[2K�[37m⠙�[0m �[2mdemucs==4.0.1 �[0m
�[2K�[37m⠙�[0m �[2mdora-search==0.1.12 �[0m
�[2K�[37m⠙�[0m �[2meinops==0.8.1 �[0m
�[2K�[37m⠙�[0m �[2mjulius==0.2.7 �[0m
�[2K�[37m⠙�[0m �[2mlameenc==1.8.1 �[0m
�[2K�[37m⠙�[0m �[2mopenunmix==1.3.0 �[0m
�[2K�[37m⠙�[0m �[2mpyyaml==6.0.2 �[0m
�[2K�[37m⠙�[0m �[2mtorch==2.8.0 �[0m
�[2K�[37m⠙�[0m �[2mnvidia-cuda-nvrtc-cu12==12.8.93 �[0m
�[2K�[37m⠙�[0m �[2mnvidia-cuda-nvrtc-cu12==12.8.93 �[0m
�[2K�[37m⠙�[0m �[2mnvidia-cuda-runtime-cu12==12.8.90 �[0m
�[2K�[37m⠙�[0m �[2mnvidia-cuda-runtime-cu12==12.8.90 �[0m
�[2K�[37m⠙�[0m �[2mnvidia-cuda-cupti-cu12==12.8.90 �[0m
�[2K�[37m⠙�[0m �[2mnvidia-cuda-cupti-cu12==12.8.90 �[0m
�[2K�[37m⠙�[0m �[2mnvidia-cudnn-cu12==9.10.2.21 �[0m
�[2K�[37m⠙�[0m �[2mnvidia-cudnn-cu12==9.10.2.21 �[0m
�[2K�[37m⠙�[0m �[2mnvidia-cublas-cu12==12.8.4.1 �[0m
�[2K�[37m⠙�[0m �[2mnvidia-cublas-cu12==12.8.4.1 �[0m
�[2K�[2mResolved �[1m41 packages�[0m �[2min 29ms�[0m�[0m
░░░░░░░░░░░░░░░░░░░░ [0/0] �[2mInstalling wheels... �[0m
�[2K░░░░░░░░░░░░░░░░░░░░ [0/15] �[2mInstalling wheels... �[0m
�[2K░░░░░░░░░░░░░░░░░░░░ [0/15] �[2mcloudpickle==3.1.1 �[0m
�[2K█░░░░░░░░░░░░░░░░░░░ [1/15] �[2mcloudpickle==3.1.1 �[0m
�[2K█░░░░░░░░░░░░░░░░░░░ [1/15] �[2meinops==0.8.1 �[0m
�[2K██░░░░░░░░░░░░░░░░░░ [2/15] �[2meinops==0.8.1 �[0m
�[2K██░░░░░░░░░░░░░░░░░░ [2/15] �[2mretrying==1.4.2 �[0m
�[2K████░░░░░░░░░░░░░░░░ [3/15] �[2mretrying==1.4.2 �[0m
�[2K████░░░░░░░░░░░░░░░░ [3/15] �[2mtreetable==0.2.6 �[0m
�[2K█████░░░░░░░░░░░░░░░ [4/15] �[2mtreetable==0.2.6 �[0m
�[2K█████░░░░░░░░░░░░░░░ [4/15] �[2msubmitit==1.5.3 �[0m
�[2K██████░░░░░░░░░░░░░░ [5/15] �[2msubmitit==1.5.3 �[0m
�[2K██████░░░░░░░░░░░░░░ [5/15] �[2mlameenc==1.8.1 �[0m
�[2K████████░░░░░░░░░░░░ [6/15] �[2mlameenc==1.8.1 �[0m
�[2K████████░░░░░░░░░░░░ [6/15] �[2momegaconf==2.3.0 �[0m
�[2K█████████░░░░░░░░░░░ [7/15] �[2momegaconf==2.3.0 �[0m
�[2K█████████░░░░░░░░░░░ [7/15] �[2mpyyaml==6.0.2 �[0m
�[2K██████████░░░░░░░░░░ [8/15] �[2mpyyaml==6.0.2 �[0m
�[2K██████████░░░░░░░░░░ [8/15] �[2mjulius==0.2.7 �[0m
�[2K████████████░░░░░░░░ [9/15] �[2mjulius==0.2.7 �[0m
�[2K�[2mInstalled �[1m15 packages�[0m �[2min 5ms�[0m�[0m
�[32m+�[39m �[1mantlr4-python3-runtime�[0m�[2m==4.9.3�[0m
�[32m+�[39m �[1mcloudpickle�[0m�[2m==3.1.1�[0m
�[32m+�[39m �[1mdemucs�[0m�[2m==4.0.1�[0m
�[32m+�[39m �[1mdora-search�[0m�[2m==0.1.12�[0m
�[32m+�[39m �[1meinops�[0m�[2m==0.8.1�[0m
�[32m+�[39m �[1mjulius�[0m�[2m==0.2.7�[0m
�[32m+�[39m �[1mlameenc�[0m�[2m==1.8.1�[0m
�[32m+�[39m �[1momegaconf�[0m�[2m==2.3.0�[0m
�[32m+�[39m �[1mopenunmix�[0m�[2m==1.3.0�[0m
�[32m+�[39m �[1mpyyaml�[0m�[2m==6.0.2�[0m
�[32m+�[39m �[1mretrying�[0m�[2m==1.4.2�[0m
�[32m+�[39m �[1msubmitit�[0m�[2m==1.5.3�[0m
�[32m+�[39m �[1mtorchaudio�[0m�[2m==2.8.0�[0m
�[32m+�[39m �[1mtqdm�[0m�[2m==4.67.1�[0m
�[32m+�[39m �[1mtreetable�[0m�[2m==0.2.6�[0m
inputFile = "audio.mp3";
outputDir = "demucs_output";
cmd = sprintf('demucs %s -o %s -n htdemucs_ft',inputFile,outputDir);
% For GPU, add flags like `--gpu`; for WAV output, adjust format options.
status = system(cmd);Downloading: "https://dl.fbaipublicfiles.com/demucs/hybrid_transformer/f7e0c4bc-ba3fe64a.th" to /home/matlab/.cache/torch/hub/checkpoints/f7e0c4bc-ba3fe64a.th
0% 0.00/80.2M [00:00<?, ?B/s]
52% 41.8M/80.2M [00:00<00:00, 437MB/s]
100% 80.2M/80.2M [00:00<00:00, 462MB/s]
Downloading: "https://dl.fbaipublicfiles.com/demucs/hybrid_transformer/d12395a8-e57c48e6.th" to /home/matlab/.cache/torch/hub/checkpoints/d12395a8-e57c48e6.th
0% 0.00/80.2M [00:00<?, ?B/s]
47% 37.5M/80.2M [00:00<00:00, 393MB/s]
100% 80.2M/80.2M [00:00<00:00, 447MB/s]
Downloading: "https://dl.fbaipublicfiles.com/demucs/hybrid_transformer/92cfc3b6-ef3bcb9c.th" to /home/matlab/.cache/torch/hub/checkpoints/92cfc3b6-ef3bcb9c.th
0% 0.00/80.2M [00:00<?, ?B/s]
17% 13.4M/80.2M [00:00<00:00, 140MB/s]
39% 31.4M/80.2M [00:00<00:00, 168MB/s]
67% 53.5M/80.2M [00:00<00:00, 197MB/s]
100% 80.2M/80.2M [00:00<00:00, 217MB/s]
Downloading: "https://dl.fbaipublicfiles.com/demucs/hybrid_transformer/04573f0d-f3cf25b2.th" to /home/matlab/.cache/torch/hub/checkpoints/04573f0d-f3cf25b2.th
0% 0.00/80.2M [00:00<?, ?B/s]
54% 43.5M/80.2M [00:00<00:00, 455MB/s]
100% 80.2M/80.2M [00:00<00:00, 471MB/s]
Selected model is a bag of 4 models. You will see that many progress bars per track.
Separated tracks will be stored in /MATLAB Drive/demucs/demucs_output/htdemucs_ft
Separating track audio.mp3
0%| | 0.0/64.35 [00:00<?, ?seconds/s]
9%|██████▋ | 5.85/64.35 [00:04<00:48, 1.21seconds/s]
18%|█████████████▎ | 11.7/64.35 [00:06<00:24, 2.16seconds/s]
27%|████████████████ | 17.549999999999997/64.35 [00:07<00:16, 2.78seconds/s]
36%|██████████████████████████▌ | 23.4/64.35 [00:08<00:12, 3.25seconds/s]
45%|████████████████████████████████▋ | 29.25/64.35 [00:10<00:09, 3.58seconds/s]
55%|████████████████████████████████▏ | 35.099999999999994/64.35 [00:11<00:07, 3.89seconds/s]
64%|█████████████████████████████████████▌ | 40.949999999999996/64.35 [00:12<00:05, 4.10seconds/s]
73%|█████████████████████████████████████████████████████ | 46.8/64.35 [00:13<00:04, 4.25seconds/s]
82%|██████████████████████████████████████████████████████████▉ | 52.65/64.35 [00:15<00:02, 4.27seconds/s]
91%|██████████████████████████████████████████████████████████████████▎ | 58.5/64.35 [00:16<00:01, 4.42seconds/s]
100%|████████████████████████████████████████████████████████████████████████| 64.35/64.35 [00:17<00:00, 4.48seconds/s]
100%|████████████████████████████████████████████████████████████████████████| 64.35/64.35 [00:17<00:00, 3.63seconds/s]
0%| | 0.0/64.35 [00:00<?, ?seconds/s]
9%|██████▋ | 5.85/64.35 [00:01<00:12, 4.50seconds/s]
18%|█████████████▎ | 11.7/64.35 [00:02<00:11, 4.71seconds/s]
27%|████████████████ | 17.549999999999997/64.35 [00:03<00:09, 4.80seconds/s]
36%|██████████████████████████▌ | 23.4/64.35 [00:05<00:08, 4.61seconds/s]
45%|████████████████████████████████▋ | 29.25/64.35 [00:06<00:07, 4.53seconds/s]
55%|████████████████████████████████▏ | 35.099999999999994/64.35 [00:07<00:06, 4.54seconds/s]
64%|█████████████████████████████████████▌ | 40.949999999999996/64.35 [00:08<00:05, 4.58seconds/s]
73%|█████████████████████████████████████████████████████ | 46.8/64.35 [00:10<00:03, 4.59seconds/s]
82%|██████████████████████████████████████████████████████████▉ | 52.65/64.35 [00:11<00:02, 4.54seconds/s]
91%|██████████████████████████████████████████████████████████████████▎ | 58.5/64.35 [00:12<00:01, 4.60seconds/s]
100%|████████████████████████████████████████████████████████████████████████| 64.35/64.35 [00:14<00:00, 4.40seconds/s]
100%|████████████████████████████████████████████████████████████████████████| 64.35/64.35 [00:14<00:00, 4.54seconds/s]
0%| | 0.0/64.35 [00:00<?, ?seconds/s]
9%|██████▋ | 5.85/64.35 [00:01<00:12, 4.86seconds/s]
18%|█████████████▎ | 11.7/64.35 [00:02<00:10, 4.82seconds/s]
27%|████████████████ | 17.549999999999997/64.35 [00:03<00:09, 4.78seconds/s]
36%|██████████████████████████▌ | 23.4/64.35 [00:04<00:08, 4.62seconds/s]
45%|████████████████████████████████▋ | 29.25/64.35 [00:06<00:07, 4.65seconds/s]
55%|████████████████████████████████▏ | 35.099999999999994/64.35 [00:07<00:06, 4.73seconds/s]
64%|█████████████████████████████████████▌ | 40.949999999999996/64.35 [00:08<00:04, 4.74seconds/s]
73%|█████████████████████████████████████████████████████ | 46.8/64.35 [00:09<00:03, 4.71seconds/s]
82%|██████████████████████████████████████████████████████████▉ | 52.65/64.35 [00:11<00:02, 4.78seconds/s]
91%|██████████████████████████████████████████████████████████████████▎ | 58.5/64.35 [00:12<00:01, 4.73seconds/s]
100%|████████████████████████████████████████████████████████████████████████| 64.35/64.35 [00:13<00:00, 4.85seconds/s]
100%|████████████████████████████████████████████████████████████████████████| 64.35/64.35 [00:13<00:00, 4.76seconds/s]
0%| | 0.0/64.35 [00:00<?, ?seconds/s]
9%|██████▋ | 5.85/64.35 [00:01<00:14, 3.93seconds/s]
18%|█████████████▎ | 11.7/64.35 [00:02<00:12, 4.33seconds/s]
27%|████████████████ | 17.549999999999997/64.35 [00:03<00:10, 4.52seconds/s]
36%|██████████████████████████▌ | 23.4/64.35 [00:05<00:08, 4.76seconds/s]
45%|████████████████████████████████▋ | 29.25/64.35 [00:06<00:07, 4.87seconds/s]
55%|████████████████████████████████▏ | 35.099999999999994/64.35 [00:07<00:05, 4.94seconds/s]
64%|█████████████████████████████████████▌ | 40.949999999999996/64.35 [00:08<00:04, 4.92seconds/s]
73%|█████████████████████████████████████████████████████ | 46.8/64.35 [00:09<00:03, 4.89seconds/s]
82%|██████████████████████████████████████████████████████████▉ | 52.65/64.35 [00:11<00:02, 4.86seconds/s]
91%|██████████████████████████████████████████████████████████████████▎ | 58.5/64.35 [00:12<00:01, 4.73seconds/s]
100%|████████████████████████████████████████████████████████████████████████| 64.35/64.35 [00:13<00:00, 4.46seconds/s]
100%|████████████████████████████████████████████████████████████████████████| 64.35/64.35 [00:13<00:00, 4.66seconds/s]
/home/matlab/venvs/env/lib/python3.10/site-packages/torchaudio/_backend/utils.py:337: UserWarning: In 2.9, this function's implementation will be changed to use torchaudio.save_with_torchcodec` under the hood. Some parameters like format, encoding, bits_per_sample, buffer_size, and ``backend`` will be ignored. We recommend that you port your code to rely directly on TorchCodec's encoder instead: https://docs.pytorch.org/torchcodec/stable/generated/torchcodec.encoders.AudioEncoder
warnings.warn(
/home/matlab/venvs/env/lib/python3.10/site-packages/torchaudio/_backend/ffmpeg.py:247: UserWarning: torio.io._streaming_media_encoder.StreamingMediaEncoder has been deprecated. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information. It will be removed from the 2.9 release.
s = torchaudio.io.StreamWriter(uri, format=muxer, buffer_size=buffer_size)
if status ~= 0
error('Demucs failed to run');
endfilePath = fullfile(outputDir,'htdemucs_ft','audio');
[vocals, fs] = audioread(fullfile(filePath, 'vocals.wav'));
[bass, ~] = audioread(fullfile(filePath, 'bass.wav'));
drums = audioread(fullfile(filePath, 'drums.wav'));
others = audioread(fullfile(filePath, 'other.wav'));
figure;
subplot(4,1,1); plot(vocals); title('Vocals');
subplot(4,1,2); plot(bass); title('Bass');
subplot(4,1,3); plot(drums); title('Drums');
subplot(4,1,4); plot(others); title('Other');