Skip to content

Instantly share code, notes, and snippets.

@PaperNick
Last active October 19, 2023 07:23
Show Gist options
  • Save PaperNick/3a6fe78662ea7a1c7cc5c573db348ac1 to your computer and use it in GitHub Desktop.
Save PaperNick/3a6fe78662ea7a1c7cc5c573db348ac1 to your computer and use it in GitHub Desktop.
Whisper.ccp transcription helper
#!/bin/bash
FILE_TO_TRANSCRIBE="$1"
FILE_TO_TRANSCRIBE_WAV="${1%.*}.wav"
LANGUAGE="${2:-en}"
HELP_TEXT=$(cat <<'EOF'
Usage: transcribe.sh <file> <lang>
Transcribe the given video or audio file.
Positional arguments:
file - video or audio file
lang - Specify the language of the audio file.
Defaults to English (en). Use 'auto' to identify the lang.
optional arguments:
-s, --skip-convert Skip the conversion to 16-bit WAV file
-h, --help Show this help message and exit
EOF
)
if [ "$FILE_TO_TRANSCRIBE" = "" ]; then
echo "$HELP_TEXT"
exit 1
fi
SHOULD_CONVERT="1"
for flag in "$@"; do
case "$flag" in
-s|--skip-convert)
SHOULD_CONVERT="0"
;;
-h|--help)
echo "$HELP_TEXT"
exit 0
;;
esac
done
if [ "$SHOULD_CONVERT" = "1" ]; then
# Convert to 16-bit WAV
ffmpeg -i "$FILE_TO_TRANSCRIBE" -ar 16000 -ac 1 -c:a pcm_s16le "$FILE_TO_TRANSCRIBE_WAV"
fi
if [ -f "$FILE_TO_TRANSCRIBE_WAV" ]; then
./main --model models/ggml-large.bin --file "$FILE_TO_TRANSCRIBE_WAV" --language "$LANGUAGE" --output-srt
else
./main --model models/ggml-large.bin --file "$FILE_TO_TRANSCRIBE" --language "$LANGUAGE" --output-srt
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment