Skip to content

Instantly share code, notes, and snippets.

@zmactep
Created April 4, 2023 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zmactep/6f0697aa90093874f8850fd1814a2fac to your computer and use it in GitHub Desktop.
Save zmactep/6f0697aa90093874f8850fd1814a2fac to your computer and use it in GitHub Desktop.
Small script to transcribe voice messages
#!/bin/sh
# Install whisper.cpp from here: https://github.com/ggerganov/whisper.cpp
# You may also need ffmpeg for conversion
WHISPER_PATH=/Users/pavel/.local/share/whisper.cpp
MODEL="large"
usage()
{
echo "Usage:"
echo " $0 [wav-file]"
echo " You can also use non-wav audio file, ffmpeg will be used for conversion then."
}
if [ "$#" -ne 1 ]; then
echo "Error: wrong arguments count!"
usage
exit 1
fi
inputfile=$1
extension="${inputfile##*.}"
if [ "$extension" != "wav" ]; then
echo "Warining: Not a wav-file! Trying to convert with ffmpeg." >& 2
tempfile="$(mktemp).wav"
ffmpeg -i $inputfile -ac 1 -ar 16000 $tempfile
if [ "$?" -ne 0 ]; then
echo "Error: failed to convert file to wav."
usage
exit 1
fi
inputfile=$tempfile
fi
$WHISPER_PATH/whisper -m $WHISPER_PATH/models/ggml-$MODEL.bin -f $inputfile -pc -l ru -nt -su 2> /dev/null
if [[ -n "${tempfile+x}" ]]; then
rm $tempfile
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment