Created
March 25, 2025 02:43
-
-
Save kamilersz/ec18011177ab19cb044a5d374a60da36 to your computer and use it in GitHub Desktop.
YT Karaoke Generator - creating instrumental audio file by having youtube link
This file contains hidden or 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
| #!/bin/bash | |
| set -e # Exit on error | |
| echo "Installing dependencies for audio processing tools..." | |
| # Detect OS | |
| if [[ "$OSTYPE" == "linux-gnu"* ]]; then | |
| # Linux installation | |
| echo "Detected Linux system" | |
| # Install Python and pip if not present | |
| if ! command -v python3 &> /dev/null; then | |
| sudo apt-get update | |
| sudo apt-get install -y python3 python3-pip | |
| fi | |
| # Install ffmpeg with CUDA support | |
| sudo apt-get update | |
| sudo apt-get install -y ffmpeg | |
| # Check if CUDA is properly installed for ffmpeg | |
| if ! ffmpeg -hwaccels | grep -q "cuda"; then | |
| echo "WARNING: CUDA acceleration may not be available for ffmpeg." | |
| echo "You may need to compile ffmpeg with CUDA support manually." | |
| fi | |
| elif [[ "$OSTYPE" == "darwin"* ]]; then | |
| # macOS installation | |
| echo "Detected macOS system" | |
| # Check if Homebrew is installed, install if not | |
| if ! command -v brew &> /dev/null; then | |
| echo "Installing Homebrew..." | |
| /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
| fi | |
| # Install Python and ffmpeg | |
| brew install python ffmpeg | |
| echo "Note: CUDA acceleration is typically not available on macOS." | |
| echo "The script will work but may use CPU only for ffmpeg." | |
| else | |
| echo "Unsupported operating system: $OSTYPE" | |
| exit 1 | |
| fi | |
| # Install Python packages | |
| echo "Installing Python packages..." | |
| pip3 install --upgrade pip | |
| pip3 install yt-dlp | |
| # Install audio-separator | |
| pip3 install audio-separator | |
| echo "Creating directory for audio processing models..." | |
| mkdir -p ~/.audio-separator/models | |
| echo "Installation completed!" | |
| echo "You may need to log out and log back in for changes to take effect." | |
| echo "The audio processing utility is installed as 'process-audio.sh'" |
This file contains hidden or 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
| #!/bin/bash | |
| # Check if the script is called with sufficient arguments | |
| if [ "$#" -lt 2 ]; then | |
| echo "Usage: $0 <input> <output>" | |
| echo " <input>: URL or path to the input media file" | |
| echo " <output>: Name of the output MP3 file (without extension)" | |
| exit 1 | |
| fi | |
| INPUT="$1" | |
| OUTPUT="$2.mp3" | |
| TEMP_DIR=$(mktemp -d) | |
| TEMP_AUDIO="$TEMP_DIR/audio.opus" | |
| echo "Step 1: Downloading/extracting audio..." | |
| yt-dlp -x --audio-format opus -o "$TEMP_AUDIO" "$INPUT" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to download or extract audio." | |
| rm -rf "$TEMP_DIR" | |
| exit 1 | |
| fi | |
| echo "Step 2: Separating audio components..." | |
| audio-separator "$TEMP_AUDIO" --model_filename=model_bs_roformer_ep_317_sdr_12.9755.ckpt --output_dir="$TEMP_DIR" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to separate audio components." | |
| rm -rf "$TEMP_DIR" | |
| exit 1 | |
| fi | |
| # Get the instrumental file path | |
| INSTRUMENTAL_FILE=$(find "$TEMP_DIR" -type f -name "*Instrumental*.flac" | head -n 1) | |
| if [ -z "$INSTRUMENTAL_FILE" ]; then | |
| echo "Error: Could not find the instrumental track." | |
| rm -rf "$TEMP_DIR" | |
| exit 1 | |
| fi | |
| echo "Step 3: Converting instrumental track to MP3..." | |
| if command -v nvidia-smi &> /dev/null; then | |
| # Use CUDA if available | |
| ffmpeg -hwaccel cuda -i "$INSTRUMENTAL_FILE" -c:a libmp3lame -q:a 0 "$OUTPUT" | |
| else | |
| # Fall back to CPU if CUDA is not available | |
| ffmpeg -i "$INSTRUMENTAL_FILE" -c:a libmp3lame -q:a 0 "$OUTPUT" | |
| fi | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to convert to MP3." | |
| rm -rf "$TEMP_DIR" | |
| exit 1 | |
| fi | |
| # Clean up temporary files | |
| rm -rf "$TEMP_DIR" | |
| echo "Process completed successfully!" | |
| echo "Output saved as: $OUTPUT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment