Download Audio from YouTube

Reading time: approx. 8 min

What You Will Learn

In this moment we install the first tool we need: yt-dlp. It is a command-line tool that lets us download video and audio from YouTube. We will configure it to automatically extract the audio, convert it to an MP3 file, and save it in your "Downloads" folder.

The Terminal

We will be using the terminal, which is a text-based interface for talking to your computer. Each step involves typing or pasting a command and pressing Enter. It is simple once you get started.

Step-by-Step Installation

1. Open a Terminal

Find and open the program called "Terminal" or "Console".

2. Create a Personal bin Folder

This is a standard location for programs you install yourself. The command creates the folder if it does not already exist.

mkdir -p ~/bin

3. Download yt-dlp

This command uses curl to download the latest version of yt-dlp and saves it in the folder you just created.

curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp \
     -o ~/bin/yt-dlp

4. Make the File Executable

You must give the system permission to run the file as a program.

chmod +x ~/bin/yt-dlp

5. Add Your bin Folder to the System Path

This allows you to run yt-dlp from any folder in the terminal.

echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc

Then load the change into your current terminal session:

source ~/.bashrc

If you use Zsh instead of Bash, change .bashrc to .zshrc in the commands above.

6. Install ffmpeg

ffmpeg is a tool for working with audio and video. yt-dlp uses it to convert the downloaded audio to MP3 format.

For Debian/Ubuntu:

sudo apt update && sudo apt install ffmpeg

For Fedora:

sudo dnf install ffmpeg

For Arch Linux:

sudo pacman -S ffmpeg

Smart Default Configuration

Now we will make sure yt-dlp always does what we want: extracts audio as MP3 to a specific folder.

1. Create a Configuration Folder

mkdir -p ~/.config/yt-dlp

2. Create the Configuration File

Copy and paste this entire block into the terminal and press Enter:

cat << 'EOF' > ~/.config/yt-dlp/config
# Extract audio
-x
# Set audio format to mp3
--audio-format mp3
# Choose highest audio quality
--audio-quality 0
# Ensure filenames are clean from strange characters
--restrict-filenames
# Save in Downloads folder with video title as filename
-o ~/Downloads/%(title)s.%(ext)s
EOF

3. Download an MP3

Everything is ready! Open the terminal and run:

yt-dlp <YOUTUBE_URL>

Replace <YOUTUBE_URL> with the link to a real YouTube video.

4. Find Your File

Open your file manager and go to the "Downloads" folder. There you should find an MP3 file with the video's title.

Next Step

Now that we can retrieve audio files from YouTube, the next step is to convert the speech in the file to text. In the next moment we set up the environment required to run KB-Whisper.