Last active
May 10, 2021 19:27
-
-
Save adelin-b/0bfdbb289e04247c66157f50a84a84e2 to your computer and use it in GitHub Desktop.
spleeter.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "spleeter.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"toc_visible": true, | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"display_name": "Python 3", | |
"name": "python3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/adelin-b/0bfdbb289e04247c66157f50a84a84e2/spleeter.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "K6mcSc0mmp3i" | |
}, | |
"source": [ | |
"# Install spleeter and youtube-dl" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "f8Brdfh6mzEz" | |
}, | |
"source": [ | |
"!apt install ffmpeg" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "V_6Ram1lmc1F" | |
}, | |
"source": [ | |
"pip install spleeter" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "W0LktyMypXqE" | |
}, | |
"source": [ | |
"from IPython.display import Audio" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "U61OHsJ-AAK8" | |
}, | |
"source": [ | |
"!pip install youtube-dl" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "zHKIgovqAZ6k" | |
}, | |
"source": [ | |
"Choose a song\n", | |
"\n", | |
"#" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "IsaVPuWJAopR" | |
}, | |
"source": [ | |
"import youtube_dl\n", | |
"\n", | |
"YoutubeUrl = 'https://www.youtube.com/watch?v=Ieqb9mYhRQ4' #@param {type: \"string\"}\n", | |
"filename = ''\n", | |
"\n", | |
"ydl_opts = {\n", | |
" 'format': 'bestaudio/best',\n", | |
" 'postprocessors': [{\n", | |
" 'key': 'FFmpegExtractAudio',\n", | |
" 'preferredcodec': 'mp3',\n", | |
" 'preferredquality': '192',\n", | |
" }],\n", | |
"}\n", | |
"with youtube_dl.YoutubeDL(ydl_opts) as ydl:\n", | |
" info = ydl.extract_info(YoutubeUrl, download=True)\n", | |
" filename = ydl.prepare_filename(info)\n", | |
" filename = os.path.splitext(filename)[0]+'.mp3'\n", | |
" print(filename)\n", | |
" # ydl.download([YoutubeUrl])\n", | |
"\n" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "H1ddE72bB2zn" | |
}, | |
"source": [ | |
"!ls" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "afbcUSken16L" | |
}, | |
"source": [ | |
"# Separate from command line" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "ibG6uF55p4lH" | |
}, | |
"source": [ | |
"Audio(filename)" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "kOAqBcPhn6IU" | |
}, | |
"source": [ | |
"!spleeter separate -h" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "dGL-k5xxoKbu" | |
}, | |
"source": [ | |
"!spleeter separate -o output/ \"$filename\" -p spleeter:5stems" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "IDuPWcAMoZP_" | |
}, | |
"source": [ | |
"!ls output/audio_example" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "e7CHpyiloxrk" | |
}, | |
"source": [ | |
"Audio('output/audio_example/vocals.wav')" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "ibXd-WCTpT0w" | |
}, | |
"source": [ | |
"Audio('output/audio_example/accompaniment.wav')" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "u_gaypg_KNeG" | |
}, | |
"source": [ | |
"!for i in output/**/*.wav; do ffmpeg -i \"$i\" \"${i%.*}.mp3\"; done" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "tYD27nq89LG5" | |
}, | |
"source": [ | |
"import os\n", | |
"import IPython.display as dis\n", | |
"\n", | |
"\n", | |
"directory = r'output/Cómo te lhama (Himno) - Orquesta Atípica de Lhamas-Ieqb9mYhRQ4/'\n", | |
"for entry in os.scandir(directory):\n", | |
" if (entry.path.endswith(\".wav\")\n", | |
" or entry.path.endswith(\".wav\")) and entry.is_file():\n", | |
" dis.display(Audio(entry.path))\n", | |
" print(entry.path)" | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment