Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Identify what the script does and who it is for.

Document prerequisites and installation/setup steps.

Explain configuration, API key handling, and environment variables.

Provide clear usage examples.

Describe outputs, workflow, troubleshooting, and security notes.

YouTube Audio Transcriber and Summarizer

A Bash script that downloads audio from a YouTube URL, splits it into manageable chunks, transcribes the audio with OpenAI Whisper, and summarizes the transcription using the OpenAI Responses API.

Features

  • Downloads audio from YouTube using yt-dlp
  • Converts/downloads audio as MP3
  • Splits long audio files into 30-minute chunks using ffmpeg
  • Transcribes each chunk using Whisper
  • Combines the transcription into a single text file
  • Sends the transcript to OpenAI for summarization
  • Supports summary output in a target language
  • Saves the final summary to a timestamped text file

Requirements

The script requires the following tools:

  • bash
  • ffmpeg
  • jq
  • curl
  • yt-dlp
  • Python 3
  • Python package: whisper
  • An OpenAI API key

Installation

1. Clone this repository

git clone https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git
cd YOUR_REPO_NAME

2. Install system dependencies

On Debian/Ubuntu:


sudo apt update
sudo apt install -y ffmpeg jq curl python3 python3-venv

3. Install yt-dlp

You can install yt-dlp from your package manager:


sudo apt install -y yt-dlp

Or download the standalone binary:


curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux -o ~/yt-dlp_linux
chmod +x ~/yt-dlp_linux

By default, the script expects yt-dlp at:


/home/$USERNAME/yt-dlp_linux

You can override this with the YTDLP_BIN environment variable.


4. Set up Python and Whisper

The script expects a Python executable at:


$WORKDIR/bin/python

By default:


/home/$USERNAME/whisper/bin/python

Create the environment:


mkdir -p ~/whisper
python3 -m venv ~/whisper
~/whisper/bin/pip install -U pip
~/whisper/bin/pip install openai-whisper

Depending on your system, you may also need PyTorch installed separately. See the official PyTorch installation guide:


https://pytorch.org/get-started/locally/


OpenAI API Key

The script needs an OpenAI API key.


You can provide it in one of two ways.


Option 1: Environment variable

export OPENAI_API_KEY="your_api_key_here"

Option 2: Key file

By default, the script looks for a key file at:


$WORKDIR/.openai_key

For example:


echo "your_api_key_here" > ~/whisper/.openai_key
chmod 600 ~/whisper/.openai_key

Usage

./script.sh <youtube_url> [target_lang]

Example:


./script.sh "https://www.youtube.com/watch?v=VIDEO_ID"

Summarize in another language:


./script.sh "https://www.youtube.com/watch?v=VIDEO_ID" spanish

./script.sh "https://www.youtube.com/watch?v=VIDEO_ID" french

./script.sh "https://www.youtube.com/watch?v=VIDEO_ID" german

If no target language is provided, the script defaults to:


english

Configuration

The script supports the following optional environment variables:


Variable	Description	Default
USERNAME	User used to build default paths	Invoking user or current user
MODEL	OpenAI model used for summarization	gpt-5.4-mini
WORKDIR	Working directory for audio, transcript, and output files	/home/$USERNAME/whisper
KEYFILE	File containing your OpenAI API key	$WORKDIR/.openai_key
YTDLP_BIN	Path to the yt-dlp executable	/home/$USERNAME/yt-dlp_linux
OPENAI_API_KEY	OpenAI API key. If set, this overrides KEYFILE	unset

Example with custom paths:


WORKDIR="$HOME/whisper" \
YTDLP_BIN="$(which yt-dlp)" \
MODEL="gpt-4.1-mini" \
./script.sh "https://www.youtube.com/watch?v=VIDEO_ID" english

Output Files

The script creates and uses the following files inside WORKDIR:


File	Description
input.mp3	Downloaded YouTube audio
output000.mp3, output001.mp3, etc.	30-minute audio chunks
transcription.txt	Full Whisper transcription
summary-YY-MM-DD-HH-MM-SS.txt	Final OpenAI-generated summary

Example output file:


summary-25-01-18-14-30-02.txt

How It Works

The script performs four main steps:


1. Download audio

Uses yt-dlp to download the audio from the provided YouTube URL and save it as input.mp3.


yt-dlp -x --audio-format mp3

2. Split audio

Uses ffmpeg to split the MP3 into 30-minute chunks.


ffmpeg -f segment -segment_time 1800

3. Transcribe audio

Uses Whisper with the turbo model to transcribe each audio chunk.


model = whisper.load_model("turbo")

The combined transcription is written to:


transcription.txt

4. Summarize transcription

Sends the transcript to the OpenAI Responses API and asks for a summary in the selected target language.


The summary is printed to the terminal and saved to a timestamped file.


Example

export OPENAI_API_KEY="your_api_key_here"

WORKDIR="$HOME/whisper" \
YTDLP_BIN="$(which yt-dlp)" \
./script.sh "https://www.youtube.com/watch?v=dQw4w9WgXcQ" english

Expected terminal output:


[INFO] Downloading audio...
[INFO] Splitting audio...
[INFO] Running Whisper transcription...
[DONE]
[INFO] Summarizing transcription with OpenAI gpt-5.4-mini...

The summary will be saved as something like:


summary-25-01-18-14-30-02.txt

Notes


The script deletes previous input.mp3, transcription.txt, and output*.mp3 files in the working directory before each run.

Audio is split into 1800-second, or 30-minute, segments.

Very long transcripts may exceed the input limit of the selected OpenAI model.

The default Whisper model is hardcoded as turbo inside the Python block.

The default OpenAI summarization model is set with the MODEL environment variable.


Troubleshooting

No OpenAI API key found

Set your API key:


export OPENAI_API_KEY="your_api_key_here"

Or create the key file:


echo "your_api_key_here" > ~/whisper/.openai_key
chmod 600 ~/whisper/.openai_key

yt-dlp not found

If you installed yt-dlp globally, run the script with:


YTDLP_BIN="$(which yt-dlp)" ./script.sh "https://www.youtube.com/watch?v=VIDEO_ID"

Whisper import error

Make sure Whisper is installed in the Python environment used by the script:


~/whisper/bin/pip install openai-whisper

ffmpeg not found

Install ffmpeg:


sudo apt install -y ffmpeg

OpenAI API error

If the script prints something like:


OpenAI API HTTP 401

Your API key may be missing, invalid, or expired.


If it prints:


OpenAI API HTTP 400

The transcript may be too large for the selected model, or the request payload may be invalid.


Security

Do not commit your OpenAI API key to GitHub.


Recommended:


echo ".openai_key" >> .gitignore
echo "input.mp3" >> .gitignore
echo "output*.mp3" >> .gitignore
echo "transcription.txt" >> .gitignore
echo "summary-*.txt" >> .gitignore

Example .gitignore:


.openai_key
input.mp3
output*.mp3
transcription.txt
summary-*.txt
/tmp/openai_body.json

Legal Notice

Make sure you have the right to download, process, transcribe, and summarize any content you use with this script. Follow YouTube's Terms of Service and all applicable laws.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages