<jupyter_start><jupyter_text>Song "Spleeter" Demo A click-through web page by [fat-tire](https://twitter.com/fat__tire)----*Note:  All credit for this goes to [Deezer](https://developers.deezer.com/) who created and trained the network and [provided it to the public](https://github.com/deezer/spleeter).  I'm just putting it in a slightly-easier click-through format within a Google Collaboratory web page.  [Deezer's github page](https://github.com/deezer/spleeter) also offers a [similar demo](https://colab.research.google.com/github/deezer/spleeter/blob/master/spleeter.ipynb), but this one here makes it very easy to upload your own songs + download the results.  It also uses the GPU version for faster processing.***Spleeter** is a deep learning network that can separate (split, or "spleet") a singer(s) vocals from the music.  You give it a "song.mp3", and it gives you two mp3s out: "vocals.mp3" and "accompaniment.mp3".  Spleeter supports various dimensions of separation, but the demo here just spleets into two parts (or "stems").  Deezer provides more details [here](https://github.com/deezer/spleeter/blob/master/README.md), including instructions for the other audio separation stems:  vocals, bass, drums, piano, & other.Potential uses for this might be to create tracks for:* Parodies* Karaoke* Remixes* Education  (like, what ARE the lyrics in [Louie Louie](https://www.youtube.com/watch?v=xKt75jUuKJY)?  Is there a [hidden F-bomb in Hey Jude](https://www.youtube.com/watch?v=qyo1ScwcDAc)?)* RehearsalInstructions:  Have an mp3 standing by with your favorite song (one you are authorized/licensed to use).  Now click through the "play" buttons below.  I'll walk you through the steps._Disclaimer_:  Use entirely at your own risk.  Do not violate copyrights.  Make sure you are authorized/licensed to use your audio with Spleeter.  See Deezer's original license [here](https://github.com/deezer/spleeter/blob/master/LICENSE).  Additions/changes by fat-tire in this collabatory document are also offered under the [MIT license](https://github.com/fat-tire/SongSpleeterColab/blob/master/LICENSE). Feel free to fork or save a copy of this Colab in Drive or Github (it's even an option under File in the menu above) or print out and press with flowers into your journal. STEP ONE:This first section will download all the prerequisites and set everything up.  Press the play button below and then wait about 10-15 minutes.⬇ Press the play button below<jupyter_code># we need pydub for later
! pip3 install pydub

# and this
from google.colab import files
import IPython.display as ipd
import sys

# get Anaconda...
! wget -c https://repo.anaconda.com/archive/Anaconda3-2019.10-Linux-x86_64.sh
! chmod +x Anaconda3-2019.10-Linux-x86_64.sh
! bash ./Anaconda3-2019.10-Linux-x86_64.sh -b -f -p /usr/local
sys.path.append('/usr/local/lib/python3.6/site-packages/')

# get spleeter dependencies
! sudo git clone  https://github.com/deezer/spleeter
! wget https://github.com/deezer/spleeter/blob/master/conda/spleeter-gpu.yaml

# set stuff up.  This takes a while.
! conda env create -f spleeter/conda/spleeter-gpu.yaml

# this goes fast.
! source activate spleeter-gpu
! export PATH=$"/usr/local/envs/spleeter-gpu/bin:$PATH"<jupyter_output><empty_output><jupyter_text>Now that we're done downloading and setting everything up, it's time for...  STEP TWOUpload Your "song.mp3!"!**On your computer, rename your song "song.mp3".  This is important, and I'm making you do this because I am too lazy to check the file's name.**(If you don't have a "song.mp3" and want to use the original demo example, you can skip this and go to STEP THREE below.)Press the `play button` to the left of the code section directly below, then select `Choose Files` and select your "song.mp3" on your computer.  The file should be uploaded, then moved to the right place.⬇ get your "song.mp3" file ready and press here<jupyter_code>! rm -f song.mp3  # remove the song.mp3 if it exists
files.upload()
! echo "Moving song.mp3...."
! mv song.mp3 spleeter/audio_example.mp3<jupyter_output><empty_output><jupyter_text>The following line will split the file into the two parts (voice and accompaniment), which will be outputted as "wav" files.  (Don't worry, we'll convert it to mp3 before you download.)⬇ Start Spleetin'!<jupyter_code>! /usr/local/envs/spleeter-gpu/bin/spleeter separate -i spleeter/audio_example.mp3 -p spleeter:2stems -o output<jupyter_output><empty_output><jupyter_text>STEP THREEThat went fast, huh?⬇ Now let's convert the output sound wav files-> mp3.<jupyter_code>from pydub import AudioSegment
sound = AudioSegment.from_wav("output/audio_example/vocals.wav")
sound.export("output/audio_example/vocals.mp3", format="mp3")
sound = AudioSegment.from_wav("output/audio_example/accompaniment.wav")
sound.export("output/audio_example/accompaniment.mp3", format="mp3")<jupyter_output><empty_output><jupyter_text>STEP FOURLet's preview just the vocals...<jupyter_code>ipd.Audio('output/audio_example/vocals.mp3')<jupyter_output><empty_output><jupyter_text>Now let's preview just the music...<jupyter_code>ipd.Audio('output/audio_example/accompaniment.mp3')<jupyter_output><empty_output><jupyter_text>Again, here is the original...<jupyter_code>ipd.Audio('spleeter/audio_example.mp3')<jupyter_output><empty_output><jupyter_text>STEP FIVETo download, press the ⋮(three vertical dots) in the previews above and choose `Download`.  Or, you can try these commands below.  (Some users may experience "fetch errors" with them, however.  Hopefully a fix will show up soon.)<jupyter_code>files.download('output/audio_example/vocals.mp3')<jupyter_output><empty_output><jupyter_text>Download the music below.<jupyter_code>files.download('output/audio_example/accompaniment.mp3')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10566298342541436, 'fraction_numerical': 0.01225828729281768, 'mean_word_length': 5.22234156820623, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 38, 'https://': 13, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '146340', 'license': 'MIT', 'n_tokens_mistral': 1956, 'n_tokens_neox': 1860, 'n_words': 608, 'path': 'Song_Spleeter_Colab.ipynb', 'repo_name': 'fat-tire/SongSpleeterColab', 'size': '5792'}