Article·Tutorials·Aug 22, 2022

How To Transcribe YouTube Videos From Your Terminal

Kevin Lewis
By Kevin Lewis
PublishedAug 22, 2022
UpdatedJun 13, 2024

In our internal Deepgram Slack workspace, there's a channel where folks can share fun and wacky things they've achieved on the terminal (#bash-hall-of-fame). Over five years ago, our CEO Scott shared a nice little snippet that allows you to download just the audio from a YouTube video. Today, I'm going to take that still-functional piece of code and show you how to download audio from a YouTube video and then transcribe it with Deepgram's Speech Recognition API.

The steps are remarkably similar to our Transcribing YouTube Videos with Node.js post, but entirely on the terminal.

You will need to download youtube-dlffmpeg, and jq for this tutorial to work. If you use macOS and have homebrew installed, this is brew install youtube-dlbrew install ffmpeg, and brew install jq. You will also need a Deepgram API Key - get one here.

Download Audio From YouTube Video with youtube_dl

We'll use the following YouTube ID: 9NZDwZbyDus. Starting with Scott's original snippet:

Given that we use the same value twice, let's abstract the video ID into a variable:

Transcribe With Deepgram

Now that we have a local file and know its file format, we can use cURL to get a transcript from Deepgram:

Using jq to extract just the transcript text and saving that to a file:

Delete Audio File

Finally, if you no longer require the audio file, delete it:

Bringing It All Together

When we first introduced a variable to this script, we separated the declaration and the cURL command with a semicolon. We can do exactly the same with all subsequent steps. The one-liner for this project is:

If you have any questions, please let us know - we love to help!

If you have any feedback about this post, or anything else around Deepgram, we'd love to hear from you. Please let us know in our GitHub discussions .

Unlock language AI at scale with an API call.

Get conversational intelligence with transcription and understanding on the world's best speech AI platform.