diff --git a/tech_docs/music/extract_mp3_tracks.md b/tech_docs/music/guide_to_working_with_audio_on_linux.md similarity index 66% rename from tech_docs/music/extract_mp3_tracks.md rename to tech_docs/music/guide_to_working_with_audio_on_linux.md index 01722dd..a5571ce 100644 --- a/tech_docs/music/extract_mp3_tracks.md +++ b/tech_docs/music/guide_to_working_with_audio_on_linux.md @@ -1,3 +1,193 @@ +### Comprehensive Guide to Working with Audio Tracks on Linux + +This guide will provide you with the necessary tools and steps to convert MP3 files to WAV, separate audio tracks, and analyze and manipulate these tracks using a combination of tools such as FFmpeg, yt-dlp, Spleeter, Audacity, Librosa, and PyDub. + +#### Tools You Will Use + +1. **FFmpeg**: For converting audio files between formats. +2. **yt-dlp**: For downloading audio from YouTube. +3. **Spleeter**: For separating audio tracks into stems (vocals, instruments). +4. **Audacity**: For manual audio editing. +5. **Librosa**: For detailed audio analysis. +6. **PyDub**: For automated audio manipulation. + +### Step-by-Step Process + +#### 1. Downloading Audio from YouTube + +**Tool**: `yt-dlp` + +**Installation**: +```bash +pip install yt-dlp +sudo apt install ffmpeg # Required for audio extraction +``` + +**Usage**: +- Download and convert YouTube video to MP3: + ```bash + yt-dlp -x --audio-format mp3 + ``` + +#### 2. Converting MP3 to WAV + +**Tool**: `FFmpeg` + +**Installation**: +```bash +sudo apt install ffmpeg +``` + +**Usage**: +- Convert MP3 to WAV: + ```bash + ffmpeg -i input.mp3 output.wav + ``` + +#### 3. Separating Audio Tracks + +**Tool**: `Spleeter` + +**Installation**: +```bash +pip install spleeter +``` + +**Usage**: +- Separate into 2 stems (vocals and accompaniment): + ```bash + spleeter separate -i output.wav -p spleeter:2stems -o output/ + ``` + +#### 4. Manual Audio Editing + +**Tool**: `Audacity` + +**Installation**: +```bash +sudo apt install audacity +``` + +**Usage**: +1. Open Audacity and import the WAV files: + - `File > Import > Audio...` +2. Use the editing tools to apply effects, trim, and adjust tracks. +3. Export the edited tracks: + - `File > Export > Export as WAV...` + +#### 5. Detailed Audio Analysis + +**Tool**: `Librosa` + +**Installation**: +```bash +pip install librosa matplotlib numpy scipy +``` + +**Usage**: +- Analyze and visualize audio features: + ```python + import librosa + import matplotlib.pyplot as plt + + y, sr = librosa.load('output/vocals.wav', sr=None) + plt.figure(figsize=(14, 5)) + librosa.display.waveshow(y, sr=sr) + plt.title('Waveform') + plt.show() + + D = np.abs(librosa.stft(y)) + DB = librosa.amplitude_to_db(D, ref=np.max) + + plt.figure(figsize=(14, 5)) + librosa.display.specshow(DB, sr=sr, x_axis='time', y_axis='log') + plt.colorbar(format='%+2.0f dB') + plt.title('Spectrogram') + plt.show() + ``` + +#### 6. Automated Audio Manipulation + +**Tool**: `PyDub` + +**Installation**: +```bash +pip install pydub +``` + +**Usage**: +- Load and manipulate audio: + ```python + from pydub import AudioSegment + + sound = AudioSegment.from_wav('output/vocals.wav') + louder_sound = sound + 6 # Increase volume by 6 dB + louder_sound.export('output/louder_vocals.wav', format='wav') + ``` + +### Project Structure and Best Practices + +1. **Organize Your Files**: + - Create a project directory with subdirectories for raw files, separated stems, edited files, and final outputs. + ``` + project_directory/ + ├── raw_files/ + │ ├── input.mp3 + ├── separated_stems/ + │ ├── vocals.wav + │ ├── accompaniment.wav + ├── edited_files/ + │ ├── edited_vocals.wav + ├── final_outputs/ + │ ├── final_output.mp3 + ``` + +2. **Use Scripts for Automation**: + - Create scripts to automate repetitive tasks like downloading, converting, and processing audio files. + - Example script for downloading and converting: + ```bash + #!/bin/bash + yt-dlp -x --audio-format mp3 -o 'raw_files/%(title)s.%(ext)s' $1 + ffmpeg -i raw_files/*.mp3 raw_files/*.wav + ``` + +3. **Document Your Process**: + - Keep a README file in your project directory to document the steps you’ve taken, tools used, and any important notes. + +4. **Backup Your Data**: + - Regularly backup your project directory to prevent data loss. + +### Example Workflow + +1. **Download and Convert Audio**: + ```bash + yt-dlp -x --audio-format mp3 -o 'raw_files/%(title)s.%(ext)s' https://www.youtube.com/watch?v=dQw4w9WgXcQ + ffmpeg -i raw_files/*.mp3 raw_files/*.wav + ``` + +2. **Separate Audio Tracks**: + ```bash + spleeter separate -i raw_files/input.wav -p spleeter:2stems -o separated_stems/ + ``` + +3. **Edit Tracks in Audacity**: + - Import `separated_stems/vocals.wav` and make adjustments. + - Export edited file to `edited_files/edited_vocals.wav`. + +4. **Analyze and Manipulate with Python**: + ```python + import librosa + y, sr = librosa.load('edited_files/edited_vocals.wav', sr=None) + # Perform analysis and visualization + + from pydub import AudioSegment + sound = AudioSegment.from_wav('edited_files/edited_vocals.wav') + louder_sound = sound + 6 + louder_sound.export('final_outputs/final_output.wav', format='wav') + ``` + +By following this guide, you can effectively manage and process audio tracks using a combination of powerful tools available on Linux. + ### Analyze Programmatically Using Librosa for Detailed Feature Extraction and PyDub for Automated Audio Manipulations #### Librosa: Detailed Feature Extraction