Skip to content

Instantly share code, notes, and snippets.

@2shortplanks
Last active January 25, 2024 21:19
Show Gist options
  • Save 2shortplanks/0432463c8197b9974f00ddcc2f060930 to your computer and use it in GitHub Desktop.
Save 2shortplanks/0432463c8197b9974f00ddcc2f060930 to your computer and use it in GitHub Desktop.
script to transcripe anything with whisper
#!/bin/sh
# this script relies on a bunch of stuff
#
# 1. ffmpeg has been installed by brew
# 2. The instructions from https://blog.castopod.org/install-whisper-cpp-on-your-mac-in-5mn-and-transcribe-all-your-podcasts-for-free/
# have been followed to install whisper.cpp and the models. These are:
# cd ~/co
# git clone https://github.com/ggerganov/whisper.cpp.git
# cd whisper.cpp
# make
# cd models
# ./download-ggml-model.sh small
# Create a temporary file
tempfile="$(mktemp).wav"
# convert the file into a wav file that whisper.cpp can read and put it there
ffmpeg -i "$1" -ar 16000 $tempfile 2>/dev/null
# use whisper to transcribe it
~/co/whisper.cpp/main \
-nt \
-m ~/co/whisper.cpp/models/ggml-small.bin \
-f $tempfile \
2>/dev/null \
| perl -e '$_ = join "", <>; s/^\s+//ms; s/\s+$//ms; print'
# Delete the temp file manually at the end of the script
rm -f $tempfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment