| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# generate/whispercpp/convert-pt-to-ggml.sh |
| 4 |
# Anastasia Shchupak, 16 March 2026 |
| 5 |
# |
| 6 |
# Shell script that clones OpenAI Whisper repository, downloads an original OpenAI Whisper PyTorch model, |
| 7 |
# and converts it to GGML binary format, using the Python script convert-pt-to-ggml.py. |
| 8 |
# |
| 9 |
# Usage: convert-pt-to-ggml.sh <whisper-model-name> |
| 10 |
# Example: convert-pt-to-ggml.sh tiny |
| 11 |
|
| 12 |
set -e # stop if any command fails |
| 13 |
|
| 14 |
# OpenAI Whisper models available for conversion |
| 15 |
models="tiny tiny.en base base.en small small.en medium medium.en large-v1 large-v2 large-v3 large-v3-turbo" |
| 16 |
|
| 17 |
list_models() { |
| 18 |
printf "\nAvailable models:\n " |
| 19 |
for model in $models; do |
| 20 |
printf " %s" "$model" |
| 21 |
done |
| 22 |
printf "\n\n" |
| 23 |
printf ".en = english-only\n\n" |
| 24 |
} |
| 25 |
|
| 26 |
# check if a model name is provided |
| 27 |
if [ -z "$1" ]; then |
| 28 |
printf "Usage: %s <whisper-model-name>\n" "$0" |
| 29 |
printf "Example: %s tiny\n" "$0" |
| 30 |
list_models |
| 31 |
exit 1 |
| 32 |
fi |
| 33 |
|
| 34 |
MODEL_NAME="$1" |
| 35 |
|
| 36 |
# validate model name |
| 37 |
if ! echo "$models" | tr ' ' '\n' | grep -qx "$MODEL_NAME"; then |
| 38 |
printf "Invalid model: %s\n" "$MODEL_NAME" |
| 39 |
list_models |
| 40 |
exit 1 |
| 41 |
fi |
| 42 |
|
| 43 |
echo "Creating virtual environment..." |
| 44 |
python3 -m venv venv |
| 45 |
|
| 46 |
echo "Activating virtual environment..." |
| 47 |
source venv/bin/activate |
| 48 |
|
| 49 |
if [ -d "whisper" ]; then |
| 50 |
echo "OpenAI whisper repository already cloned, skipping." |
| 51 |
else |
| 52 |
echo "Cloning OpenAI whisper repository..." |
| 53 |
git clone https://github.com/openai/whisper |
| 54 |
fi |
| 55 |
|
| 56 |
echo "Installing openai-whisper and dependencies..." |
| 57 |
pip install openai-whisper |
| 58 |
|
| 59 |
echo "Downloading original PyTorch model..." |
| 60 |
python3 -c "import whisper; whisper.load_model('${MODEL_NAME}', download_root='./')" |
| 61 |
|
| 62 |
echo "Converting Whisper model to GGML format..." |
| 63 |
python3 convert-pt-to-ggml.py ./"${MODEL_NAME}".pt ./whisper/ ./ |
| 64 |
|
| 65 |
echo "Deactivating virtual environment..." |
| 66 |
deactivate |
| 67 |
|
| 68 |
mv ggml-model.bin ggml-"${MODEL_NAME}".bin |
| 69 |
|
| 70 |
echo "Done. Whisper model '${MODEL_NAME}' is downloaded and converted to GGML binary format." |