Skip to content

Instantly share code, notes, and snippets.

@PaperNick
Last active July 19, 2024 08:06
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}"
MODEL="models/ggml-large.bin"
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:
-h, --help Show this help message and exit
EOF
)
if [ "$FILE_TO_TRANSCRIBE" = "" ]; then
echo "$HELP_TEXT"
exit 1
fi
for flag in "$@"; do
case "$flag" in
-h|--help)
echo "$HELP_TEXT"
exit 0
;;
esac
done
if [ "$FILE_TO_TRANSCRIBE" != "$FILE_TO_TRANSCRIBE_WAV" ]; 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 "$MODEL" --file "$FILE_TO_TRANSCRIBE_WAV" --language "$LANGUAGE" --output-srt
else
echo "Could not find audio file due to an error. Path: $FILE_TO_TRANSCRIBE_WAV"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment