Skip to content

Paste a YouTube link and get seperated vocal and instrumental files, labeled with BPM & key detection

Notifications You must be signed in to change notification settings

mustafademiray/utube2stems

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

utube2stems

This script downloads audio from a YouTube video, processes it to detect BPM and key, separates vocals from instrumentals, and saves the processed files.

Features

  • Downloads audio from a given YouTube URL.
  • Converts audio to MP3 format.
  • Detects Beats Per Minute (BPM) and the musical key of the audio.
  • Separates vocals and instrumentals into two separate audio files.
  • Outputs MP3 files for vocals and instrumentals, named with their BPM and key (e.g., vocal_120bpm_C.mp3).

Prerequisites

Before running the script, ensure you have Python installed and the following dependencies:

  • FFmpeg: Spleeter (used for vocal separation) requires FFmpeg. Ensure it is installed and accessible in your system's PATH.
  • Python Libraries:
    • pytubefix: For downloading YouTube videos.
    • pydub: For audio manipulation (conversion to MP3).
    • librosa: For audio analysis (BPM and key detection).
    • spleeter: For vocal and instrumental separation.
    • numpy: A dependency for librosa and other numerical operations.

You can install the Python libraries using pip:

pip install pytubefix pydub librosa spleeter numpy

How to Run

  1. Clone this repository or download the youtube_audio_processor.py script.

  2. Ensure all prerequisites (FFmpeg and Python libraries) are installed.

  3. Open your terminal or command prompt.

  4. Navigate to the directory where you saved the script.

  5. Run the script using Python:

    python youtube_audio_processor.py
  6. The script will prompt you to enter a YouTube URL. Paste the URL and press Enter.

  7. The script will then perform the following steps:

    • Download audio (temporary files are created in the script's root directory and cleaned up).
    • Detect BPM and key.
    • Separate vocals and instrumentals (Spleeter uses a temporary spleeter_temp_processing/ directory which is also cleaned up).
    • Rename and save the final vocal_{bpm}bpm_{key}.mp3 and instrumental_{bpm}bpm_{key}.mp3 files into the output/separated_tracks/ directory (relative to the script).

File Structure

  • youtube_audio_processor.py: The main Python script.
  • _temp_initial_download.*: A temporary file for the initial audio download from YouTube, created in the script's root directory. This file is automatically cleaned up after conversion to MP3.
  • temp_audio.mp3: A temporary MP3 file created from the initial download, also in the script's root directory. This file is used for BPM/key detection and vocal separation, and is cleaned up afterwards.
  • spleeter_temp_processing/: A temporary directory created during runtime by Spleeter to store its intermediate separated .wav and .mp3 files. This directory and its contents are automatically cleaned up.
  • output/separated_tracks/: The directory where the final processed audio files are saved.
    • vocal_{bpm}bpm_{key}.mp3: The final vocals-only audio file.
    • instrumental_{bpm}bpm_{key}.mp3: The final instrumental-only audio file.

Notes

  • The quality of BPM and key detection, as well as vocal separation, can vary depending on the source audio.
  • The script uses specific itags (140, 251) for audio stream preference from YouTube for better quality, with fallbacks if these are not available.
  • Ensure you have a stable internet connection for downloading the YouTube audio.

About

Paste a YouTube link and get seperated vocal and instrumental files, labeled with BPM & key detection

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages