Created
December 21, 2020 08:12
-
-
Save henryamster/c851b21427186cc974637fa14f4a40b9 to your computer and use it in GitHub Desktop.
download an mp3 of isolated vocals from a youtube video link
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": "IsolatedVocalsMp3FromYoutubeLink.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"toc_visible": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "vyropgNB6zZg" | |
}, | |
"source": [ | |
"# Download an isolated vocal from a youtube link\r\n", | |
"\r\n", | |
"put together by [Henry Fritz](https://henryfritz.xyz)\r\n", | |
"\r\n", | |
"`@TODO: need to look into setting output from youtube-dl to a static value, eventually getting rid of the need to look at directory stuff`" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "zk4wknP_7Jpq" | |
}, | |
"source": [ | |
"# download ffmpeg\r\n", | |
"!apt install ffmpeg" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Sfd_Ig9j7TOa" | |
}, | |
"source": [ | |
"pip install spleeter" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "l-5Hai9iANC-" | |
}, | |
"source": [ | |
"pip install pydub" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Iq-Xv1FxAPNl" | |
}, | |
"source": [ | |
"pip install youtube-dl" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "84ZLGozg7xTX" | |
}, | |
"source": [ | |
"## Insert your youtube link\r\n", | |
"\r\n", | |
"make sure to keep the brackets and single quotes around the link as a string list is the expected input\r\n", | |
"\r\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "4Cywd0jW8Gwl" | |
}, | |
"source": [ | |
"from __future__ import unicode_literals\r\n", | |
"import youtube_dl\r\n", | |
"ydl_opts = {\r\n", | |
" 'format': 'bestaudio/best',\r\n", | |
" 'postprocessors': [{\r\n", | |
" 'key': 'FFmpegExtractAudio',\r\n", | |
" 'preferredcodec': 'mp3',\r\n", | |
" 'preferredquality': '320',\r\n", | |
" }],\r\n", | |
"}\r\n", | |
"#replace this youtube link with your youtube link\r\n", | |
"with youtube_dl.YoutubeDL(ydl_opts) as ydl:\r\n", | |
" ydl.download(['https://www.youtube.com/watch?v=DGnXL4pvdBg'])\r\n" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "g9BCMLDq9QnC" | |
}, | |
"source": [ | |
"## Separate vocals from band\r\n", | |
"\r\n", | |
"you'll want to see what the file is saved as in your local directory- if you are running this in the colab, this file should be located in your content folder" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "SRV7DtjR9RJn" | |
}, | |
"source": [ | |
"!spleeter separate -i '/content/Hero-DGnXL4pvdBg.mp3' -o output/" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Suxrjd-39hJn" | |
}, | |
"source": [ | |
"## Convert vocals back to mp3\r\n", | |
"\r\n", | |
"once again, check your directory, there should be a new folder called output, and inside of it there will be two files:\r\n", | |
"\r\n", | |
"\r\n", | |
"* **vocals.wav**: vocals from the youtube audio\r\n", | |
"* **accompaniment.wav**: everything else from the youtube audio\r\n", | |
"\r\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "yiYBqh969kSB" | |
}, | |
"source": [ | |
"import pydub\r\n", | |
"sound = pydub.AudioSegment.from_wav(\"output/Hero-DGnXL4pvdBg/vocals.wav\")\r\n", | |
"sound.export(\"output/Hero-DGnXL4pvdBg/isolatedVocals.mp3\", format=\"mp3\")" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "dQtHr-kd-CGG" | |
}, | |
"source": [ | |
"## Download isolated vocals mp3\r\n", | |
"you should be able to copy and paste this directly from the string param passed into the sound.export function above. Once you run this block, your file should begin to download, and once it hits 100% it should pop up in your browser\r\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "urcgY0w3-GNd" | |
}, | |
"source": [ | |
"from google.colab import files\r\n", | |
"files.download('output/Hero-DGnXL4pvdBg/isolatedVocals.mp3') " | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment