Skip to content

Instantly share code, notes, and snippets.

@mhasbini
Created April 5, 2023 19:01
Show Gist options
  • Save mhasbini/628fc85589026da928aaad4b6d4ed8d4 to your computer and use it in GitHub Desktop.
Save mhasbini/628fc85589026da928aaad4b6d4ed8d4 to your computer and use it in GitHub Desktop.
Script to generate srt for a directory that containes videos using https://github.com/ggerganov/whisper.cpp
set -Eeuo pipefail
msg() {
echo >&2 -e "${1-}"
}
source_dir="${1}"
for filename in $source_dir/*; do
[ -f "$filename" ] || continue
msg "$filename";
msg "Extracting wav";
ffmpeg -i "$filename" \
-hide_banner \
-vn \
-loglevel error \
-ar 16000 \
-ac 1 \
-c:a pcm_s16le \
-y \
"${filename}.wav";
msg "Transcribing to subtitle file";
./main -m models/ggml-tiny.bin -l en -t 4 -osrt -f "${filename}.wav";
msg "cleanup";
rm "${filename}.wav";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment