Skip to content

Instantly share code, notes, and snippets.

@Fortyseven
Last active October 15, 2024 09:13
Show Gist options
  • Save Fortyseven/ace34fab464c4d8274b46d37c11db7af to your computer and use it in GitHub Desktop.
Save Fortyseven/ace34fab464c4d8274b46d37c11db7af to your computer and use it in GitHub Desktop.
Quick script to pull down a youtube video and dump a whispertranscription (requires whisper, yt-dlp, ffmpeg)
#!/usr/bin/bash
MODEL_PATH="/models/whisper/ggml-large.bin"
#MODEL_PATH="/models/whisper/ggml-base.bin"
YT_ID=$1
# Check if the user has provided a YouTube video ID
if [ -z "$YT_ID" ]; then
echo "Please provide a YouTube video ID"
exit 1
fi
echo "- Downloading video $YT_ID"
# check if mp3 already exists and download it if not
if [ ! -f /tmp/$YT_ID.mp3 ]; then
yt-dlp $YT_ID -x --audio-format mp3 -o /tmp/$YT_ID.mp3
fi
# convert to whisper-friendly wav format
ffmpeg -y -i "/tmp/$YT_ID.mp3" -acodec pcm_s16le -ac 1 -ar 16000 "/tmp/$YT_ID.wav"
# transcribe
whisper.bin -f "/tmp/$YT_ID.wav" -m $MODEL_PATH -pp -t 24 -pc -l en -otxt -of $YT_ID
# clean up
# we'll keep the mp3 in tmp since that can be an expensive operation
# if wav exists
if [ -f "/tmp/$YT_ID.wav" ]; then
rm "/tmp/$YT_ID.wav"
fi
@Fortyseven
Copy link
Author

Might require some changes to the binary path for whisper; whisper.bin is not typical; I wanted to differentiate an existing whisper script on my machine from the base, unadorned, raw whisper binary. Tweak to taste.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment