{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "spleeter.ipynb",
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "K6mcSc0mmp3i",
"colab_type": "text"
},
"source": [
"# Install spleeter"
]
},
{
"cell_type": "code",
"metadata": {
"id": "f8Brdfh6mzEz",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 109
},
"outputId": "c63dae8e-1d33-48f2-879f-dd15393a5034"
},
"source": [
"!apt install ffmpeg"
],
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": [
"Reading package lists... Done\n",
"Building dependency tree \n",
"Reading state information... Done\n",
"ffmpeg is already the newest version (7:3.4.6-0ubuntu0.18.04.1).\n",
"0 upgraded, 0 newly installed, 0 to remove and 28 not upgraded.\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "V_6Ram1lmc1F",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"outputId": "26a8df7b-6b6c-41e7-d874-acea0247d181"
},
"source": [
"pip install spleeter"
],
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"text": [
"Collecting spleeter\n",
" Downloading https://files.pythonhosted.org/packages/67/81/7234f9f5f61b5ec50c346e8bf5a2313008f0ea655a640bbc345a200e3fdb/spleeter-1.4.1.tar.gz\n",
"Collecting musdb==0.3.1\n",
" Downloading https://files.pythonhosted.org/packages/57/bd/98ba16482f610bcfa7fcc212175dc0bbf11976e0bc69319b4204b6dc3aec/musdb-0.3.1-py2.py3-none-any.whl\n",
"Collecting museval==0.3.0\n",
" Downloading https://files.pythonhosted.org/packages/5a/5d/1419271e96537ea973d039818c7f164a150e68867fd216fd591d0a5e43b7/museval-0.3.0-py2.py3-none-any.whl\n",
"Collecting norbert==0.2.1\n",
" Downloading https://files.pythonhosted.org/packages/22/85/1e4f09c84d28b5541a4a8eece320902c4d2fa264dfe51f779548396f0fea/norbert-0.2.1-py2.py3-none-any.whl\n",
"Collecting pandas==0.25.1\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/73/9b/52e228545d14f14bb2a1622e225f38463c8726645165e1cb7dde95bfe6d4/pandas-0.25.1-cp36-cp36m-manylinux1_x86_64.whl (10.5MB)\n",
"\u001b[K |████████████████████████████████| 10.5MB 19.4MB/s \n",
"\u001b[?25hRequirement already satisfied: requests in /usr/local/lib/python3.6/dist-packages (from spleeter) (2.21.0)\n",
"Collecting tensorflow==1.14.0\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/de/f0/96fb2e0412ae9692dbf400e5b04432885f677ad6241c088ccc5fe7724d69/tensorflow-1.14.0-cp36-cp36m-manylinux1_x86_64.whl (109.2MB)\n",
"\u001b[K |████████████████████████████████| 109.2MB 21kB/s \n",
"\u001b[?25hCollecting importlib_resources\n",
" Downloading https://files.pythonhosted.org/packages/2f/f7/b4aa02cdd3ee7ebba375969d77c00826aa15c5db84247d23c89522dccbfa/importlib_resources-1.0.2-py2.py3-none-any.whl\n",
"Collecting pyaml\n",
" Downloading https://files.pythonhosted.org/packages/33/1a/936074f3492156693fc9e471269fc5747fa3b7d9d7f8a33af054f6b24066/pyaml-19.4.1-py2.py3-none-any.whl\n",
"Collecting soundfile>=0.9.0\n",
" Downloading https://files.pythonhosted.org/packages/68/64/1191352221e2ec90db7492b4bf0c04fd9d2508de67b3f39cbf093cd6bd86/SoundFile-0.10.2-py2.py3-none-any.whl\n",
"Requirement already satisfied: numpy>=1.7 in /usr/local/lib/python3.6/dist-packages (from musdb==0.3.1->spleeter) (1.17.3)\n",
"Requirement already satisfied: tqdm in /usr/local/lib/python3.6/dist-packages (from musdb==0.3.1->spleeter) (4.28.1)\n",
"Collecting stempeg>=0.1.7\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/29/ab/6e7362cbff21c25e99cfc3ef116057a7f9ebe6f429a44038eef82de3479d/stempeg-0.1.8-py3-none-any.whl (509kB)\n",
"\u001b[K |████████████████████████████████| 512kB 48.1MB/s \n",
"\u001b[?25hCollecting simplejson\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/e3/24/c35fb1c1c315fc0fffe61ea00d3f88e85469004713dab488dee4f35b0aff/simplejson-3.16.0.tar.gz (81kB)\n",
"\u001b[K |████████████████████████████████| 81kB 10.8MB/s \n",
"\u001b[?25hRequirement already satisfied: scipy in /usr/local/lib/python3.6/dist-packages (from museval==0.3.0->spleeter) (1.3.1)\n",
"Requirement already satisfied: jsonschema in /usr/local/lib/python3.6/dist-packages (from museval==0.3.0->spleeter) (2.6.0)\n",
"Requirement already satisfied: python-dateutil>=2.6.1 in /usr/local/lib/python3.6/dist-packages (from pandas==0.25.1->spleeter) (2.6.1)\n",
"Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.6/dist-packages (from pandas==0.25.1->spleeter) (2018.9)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests->spleeter) (2019.9.11)\n",
"Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests->spleeter) (1.24.3)\n",
"Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests->spleeter) (2.8)\n",
"Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests->spleeter) (3.0.4)\n",
"Requirement already satisfied: protobuf>=3.6.1 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.14.0->spleeter) (3.10.0)\n",
"Requirement already satisfied: absl-py>=0.7.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.14.0->spleeter) (0.8.1)\n",
"Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.14.0->spleeter) (1.12.0)\n",
"Requirement already satisfied: gast>=0.2.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.14.0->spleeter) (0.2.2)\n",
"Collecting tensorboard<1.15.0,>=1.14.0\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/91/2d/2ed263449a078cd9c8a9ba50ebd50123adf1f8cfbea1492f9084169b89d9/tensorboard-1.14.0-py3-none-any.whl (3.1MB)\n",
"\u001b[K |████████████████████████████████| 3.2MB 40.8MB/s \n",
"\u001b[?25hRequirement already satisfied: grpcio>=1.8.6 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.14.0->spleeter) (1.15.0)\n",
"Requirement already satisfied: wheel>=0.26 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.14.0->spleeter) (0.33.6)\n",
"Collecting tensorflow-estimator<1.15.0rc0,>=1.14.0rc0\n",
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/3c/d5/21860a5b11caf0678fbc8319341b0ae21a07156911132e0e71bffed0510d/tensorflow_estimator-1.14.0-py2.py3-none-any.whl (488kB)\n",
"\u001b[K |████████████████████████████████| 491kB 3.1MB/s \n",
"\u001b[?25hRequirement already satisfied: wrapt>=1.11.1 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.14.0->spleeter) (1.11.2)\n",
"Requirement already satisfied: google-pasta>=0.1.6 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.14.0->spleeter) (0.1.7)\n",
"Requirement already satisfied: astor>=0.6.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.14.0->spleeter) (0.8.0)\n",
"Requirement already satisfied: termcolor>=1.1.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.14.0->spleeter) (1.1.0)\n",
"Requirement already satisfied: keras-preprocessing>=1.0.5 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.14.0->spleeter) (1.1.0)\n",
"Requirement already satisfied: keras-applications>=1.0.6 in /usr/local/lib/python3.6/dist-packages (from tensorflow==1.14.0->spleeter) (1.0.8)\n",
"Requirement already satisfied: PyYAML in /usr/local/lib/python3.6/dist-packages (from pyaml->musdb==0.3.1->spleeter) (3.13)\n",
"Requirement already satisfied: cffi>=1.0 in /usr/local/lib/python3.6/dist-packages (from soundfile>=0.9.0->musdb==0.3.1->spleeter) (1.13.1)\n",
"Requirement already satisfied: setuptools in /usr/local/lib/python3.6/dist-packages (from protobuf>=3.6.1->tensorflow==1.14.0->spleeter) (41.4.0)\n",
"Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.6/dist-packages (from tensorboard<1.15.0,>=1.14.0->tensorflow==1.14.0->spleeter) (3.1.1)\n",
"Requirement already satisfied: werkzeug>=0.11.15 in /usr/local/lib/python3.6/dist-packages (from tensorboard<1.15.0,>=1.14.0->tensorflow==1.14.0->spleeter) (0.16.0)\n",
"Requirement already satisfied: h5py in /usr/local/lib/python3.6/dist-packages (from keras-applications>=1.0.6->tensorflow==1.14.0->spleeter) (2.8.0)\n",
"Requirement already satisfied: pycparser in /usr/local/lib/python3.6/dist-packages (from cffi>=1.0->soundfile>=0.9.0->musdb==0.3.1->spleeter) (2.19)\n",
"Building wheels for collected packages: spleeter, simplejson\n",
" Building wheel for spleeter (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for spleeter: filename=spleeter-1.4.1-cp36-none-any.whl size=44685 sha256=81af6d09b9674ffa9180ed599ba08711291fb5cdc99d2b264cc011c3a5571380\n",
" Stored in directory: /root/.cache/pip/wheels/a4/0f/48/49ee373da43abd1d595f0073c3d8d675ee6b5268643b578bd9\n",
" Building wheel for simplejson (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for simplejson: filename=simplejson-3.16.0-cp36-cp36m-linux_x86_64.whl size=114024 sha256=2c6b10f5f2087fe03db2dbaf00d1fcf2ff395703629be371d99668840c5b2d9d\n",
" Stored in directory: /root/.cache/pip/wheels/5d/1a/1e/0350bb3df3e74215cd91325344cc86c2c691f5306eb4d22c77\n",
"Successfully built spleeter simplejson\n",
"Installing collected packages: pyaml, soundfile, stempeg, musdb, pandas, simplejson, museval, norbert, tensorboard, tensorflow-estimator, tensorflow, importlib-resources, spleeter\n",
" Found existing installation: pandas 0.25.2\n",
" Uninstalling pandas-0.25.2:\n",
" Successfully uninstalled pandas-0.25.2\n",
" Found existing installation: tensorboard 1.15.0\n",
" Uninstalling tensorboard-1.15.0:\n",
" Successfully uninstalled tensorboard-1.15.0\n",
" Found existing installation: tensorflow-estimator 1.15.1\n",
" Uninstalling tensorflow-estimator-1.15.1:\n",
" Successfully uninstalled tensorflow-estimator-1.15.1\n",
" Found existing installation: tensorflow 1.15.0\n",
" Uninstalling tensorflow-1.15.0:\n",
" Successfully uninstalled tensorflow-1.15.0\n",
"Successfully installed importlib-resources-1.0.2 musdb-0.3.1 museval-0.3.0 norbert-0.2.1 pandas-0.25.1 pyaml-19.4.1 simplejson-3.16.0 soundfile-0.10.2 spleeter-1.4.1 stempeg-0.1.8 tensorboard-1.14.0 tensorflow-1.14.0 tensorflow-estimator-1.14.0\n"
],
"name": "stdout"
},
{
"output_type": "display_data",
"data": {
"application/vnd.colab-display-data+json": {
"pip_warning": {
"packages": [
"pandas"
]
}
}
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "W0LktyMypXqE",
"colab_type": "code",
"colab": {}
},
"source": [
"from IPython.display import Audio"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "afbcUSken16L",
"colab_type": "text"
},
"source": [
"# Separate from command line"
]
},
{
"cell_type": "code",
"metadata": {
"id": "O1kQaoJSoAD0",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 311
},
"outputId": "cd1868b4-6992-47c3-8a2b-920e6f288614"
},
"source": [
"!wget https://github.com/deezer/spleeter/raw/master/audio_example.mp3"
],
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"text": [
"--2019-11-05 13:28:31-- https://github.com/deezer/spleeter/raw/master/audio_example.mp3\n",
"Resolving github.com (github.com)... 140.82.118.4\n",
"Connecting to github.com (github.com)|140.82.118.4|:443... connected.\n",
"HTTP request sent, awaiting response... 302 Found\n",
"Location: https://raw.githubusercontent.com/deezer/spleeter/master/audio_example.mp3 [following]\n",
"--2019-11-05 13:28:32-- https://raw.githubusercontent.com/deezer/spleeter/master/audio_example.mp3\n",
"Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...\n",
"Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 262867 (257K) [audio/mpeg]\n",
"Saving to: ‘audio_example.mp3’\n",
"\n",
"audio_example.mp3 100%[===================>] 256.71K --.-KB/s in 0.02s \n",
"\n",
"2019-11-05 13:28:32 (15.7 MB/s) - ‘audio_example.mp3’ saved [262867/262867]\n",
"\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "ibG6uF55p4lH",
"colab_type": "code",
"outputId": "f2785922-0ee1-4769-807a-6ee69313993c",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 60
}
},
"source": [
"Audio('audio_example.mp3')"
],
"execution_count": 6,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"metadata": {
"tags": []
},
"execution_count": 6
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "kOAqBcPhn6IU",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 660
},
"outputId": "23e14ad5-209d-4ed6-b909-7c0cd966bd0c"
},
"source": [
"!spleeter separate -h"
],
"execution_count": 7,
"outputs": [
{
"output_type": "stream",
"text": [
"usage: python -m spleeter separate [-h] [-a AUDIO_ADAPTER]\n",
" [-p PARAMS_FILENAME] [--verbose] -i\n",
" AUDIO_FILENAMES [AUDIO_FILENAMES ...]\n",
" [-o OUTPUT_PATH] [-n {directory,filename}]\n",
" [-d MAX_DURATION]\n",
" [-c {wav,mp3,ogg,m4a,wma,flac}] [-m]\n",
"\n",
"optional arguments:\n",
" -h, --help show this help message and exit\n",
" -a AUDIO_ADAPTER, --adapter AUDIO_ADAPTER\n",
" Name of the audio adapter to use for audio I/O\n",
" -p PARAMS_FILENAME, --params_filename PARAMS_FILENAME\n",
" JSON filename that contains params\n",
" --verbose Shows verbose logs\n",
" -i AUDIO_FILENAMES [AUDIO_FILENAMES ...], --audio_filenames AUDIO_FILENAMES [AUDIO_FILENAMES ...]\n",
" List of input audio filenames\n",
" -o OUTPUT_PATH, --output_path OUTPUT_PATH\n",
" Path of the output directory to write audio files in\n",
" -n {directory,filename}, --output_naming {directory,filename}\n",
" Choice for naming the output base path: \"filename\"\n",
" (use the input filename, i.e /path/to/audio/mix.wav\n",
" will be separated to\n",
" /mix/.wav,\n",
" /mix/.wav...) or \"directory\"\n",
" (use the name of the input last level directory, for\n",
" instance /path/to/audio/mix.wav will be separated to\n",
" /audio/.wav,\n",
" /audio/.wav)\n",
" -d MAX_DURATION, --max_duration MAX_DURATION\n",
" Set a maximum duration for processing audio (only\n",
" separate max_duration first seconds of the input file)\n",
" -c {wav,mp3,ogg,m4a,wma,flac}, --audio_codec {wav,mp3,ogg,m4a,wma,flac}\n",
" Audio codec to be used for the separated output\n",
" -m, --mwf Whether to use multichannel Wiener filtering for\n",
" separation\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "dGL-k5xxoKbu",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 533
},
"outputId": "dd8d6a7f-515c-47f0-8388-39e179ef652a"
},
"source": [
"!spleeter separate -i audio_example.mp3 -o output/"
],
"execution_count": 8,
"outputs": [
{
"output_type": "stream",
"text": [
"INFO:tensorflow:Downloading model archive https://github.com/deezer/spleeter/releases/download/v1.4.0/2stems.tar.gz\n",
"INFO:tensorflow:Using config: {'_model_dir': 'pretrained_models/2stems', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': gpu_options {\n",
" per_process_gpu_memory_fraction: 0.7\n",
"}\n",
", '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_device_fn': None, '_protocol': None, '_eval_distribute': None, '_experimental_distribute': None, '_experimental_max_worker_delay_secs': None, '_service': None, '_cluster_spec': , '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1}\n",
"INFO:tensorflow:Calling model_fn.\n",
"WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/spleeter/model/functions/unet.py:29: The name tf.keras.initializers.he_uniform is deprecated. Please use tf.compat.v1.keras.initializers.he_uniform instead.\n",
"\n",
"INFO:tensorflow:Apply unet for vocals_spectrogram\n",
"INFO:tensorflow:Apply unet for accompaniment_spectrogram\n",
"INFO:tensorflow:Done calling model_fn.\n",
"WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/array_ops.py:1354: add_dispatch_support..wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.\n",
"Instructions for updating:\n",
"Use tf.where in 2.0, which has the same broadcast rule as np.where\n",
"INFO:tensorflow:Graph was finalized.\n",
"WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/training/saver.py:1276: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.\n",
"Instructions for updating:\n",
"Use standard file APIs to check for files with this prefix.\n",
"INFO:tensorflow:Restoring parameters from pretrained_models/2stems/model\n",
"INFO:tensorflow:Running local_init_op.\n",
"INFO:tensorflow:Done running local_init_op.\n",
"WARNING:tensorflow:The dtype of the watched tensor must be floating (e.g. tf.float32), got tf.string\n",
"WARNING:tensorflow:The dtype of the watched tensor must be floating (e.g. tf.float32), got tf.int32\n",
"WARNING:tensorflow:The dtype of the watched tensor must be floating (e.g. tf.float32), got tf.string\n",
"INFO:tensorflow:Loading audio b'audio_example.mp3' from 0.0 to 600.0\n",
"INFO:tensorflow:File output/audio_example/vocals.wav written\n",
"INFO:tensorflow:File output/audio_example/accompaniment.wav written\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "IDuPWcAMoZP_",
"colab_type": "code",
"outputId": "3f9a05fd-afab-41c7-d47c-433fc614283b",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 63
}
},
"source": [
"!ls output/audio_example"
],
"execution_count": 0,
"outputs": [
{
"output_type": "stream",
"text": [
"accompaniment.wav vocals.wav\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "e7CHpyiloxrk",
"colab_type": "code",
"outputId": "d1ff17ac-8cef-4b9d-913a-01c2688ffef1",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 60
}
},
"source": [
"Audio('output/audio_example/vocals.wav')"
],
"execution_count": 9,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"metadata": {
"tags": []
},
"execution_count": 9
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "ibXd-WCTpT0w",
"colab_type": "code",
"outputId": "6716708d-1cdb-4be5-da22-593075de78ca",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 60
}
},
"source": [
"Audio('output/audio_example/accompaniment.wav')"
],
"execution_count": 10,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"metadata": {
"tags": []
},
"execution_count": 10
}
]
}
]
}