2024-01-12 13:11:04 +01:00
|
|
|
#!/bin/sh
|
2023-04-15 12:21:27 +02:00
|
|
|
|
2024-04-24 13:56:30 +02:00
|
|
|
printf "whisper.cpp: this script hasn't been maintained and is not functional atm\n"
|
|
|
|
exit 1
|
|
|
|
|
2023-04-15 12:21:27 +02:00
|
|
|
# This script downloads Whisper model files that have already been converted to Core ML format.
|
|
|
|
# This way you don't have to convert them yourself.
|
|
|
|
|
|
|
|
src="https://huggingface.co/datasets/ggerganov/whisper.cpp-coreml"
|
|
|
|
pfx="resolve/main/ggml"
|
|
|
|
|
|
|
|
# get the path of this script
|
2024-01-12 13:11:04 +01:00
|
|
|
get_script_path() {
|
2023-04-15 12:21:27 +02:00
|
|
|
if [ -x "$(command -v realpath)" ]; then
|
2024-01-12 13:11:04 +01:00
|
|
|
dirname "$(realpath "$0")"
|
2023-04-15 12:21:27 +02:00
|
|
|
else
|
2024-01-12 13:11:04 +01:00
|
|
|
_ret="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit ; pwd -P)"
|
|
|
|
echo "$_ret"
|
2023-04-15 12:21:27 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
models_path="$(get_script_path)"
|
|
|
|
|
|
|
|
# Whisper models
|
2024-10-01 14:57:06 +02:00
|
|
|
models="tiny.en tiny base.en base small.en small medium.en medium large-v1 large-v2 large-v3 large-v3-turbo"
|
2023-04-15 12:21:27 +02:00
|
|
|
|
|
|
|
# list available models
|
2024-01-12 13:11:04 +01:00
|
|
|
list_models() {
|
|
|
|
printf "\n"
|
|
|
|
printf " Available models:"
|
|
|
|
for model in $models; do
|
|
|
|
printf " %s" "$models"
|
|
|
|
done
|
|
|
|
printf "\n\n"
|
2023-04-15 12:21:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$#" -ne 1 ]; then
|
2024-01-12 13:11:04 +01:00
|
|
|
printf "Usage: %s <model>\n" "$0"
|
2023-04-15 12:21:27 +02:00
|
|
|
list_models
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
model=$1
|
|
|
|
|
2024-01-12 13:11:04 +01:00
|
|
|
if ! echo "$models" | grep -q -w "$model"; then
|
|
|
|
printf "Invalid model: %s\n" "$model"
|
2023-04-15 12:21:27 +02:00
|
|
|
list_models
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# download Core ML model
|
|
|
|
|
2024-01-12 13:11:04 +01:00
|
|
|
printf "Downloading Core ML model %s from '%s' ...\n" "$model" "$src"
|
2023-04-15 12:21:27 +02:00
|
|
|
|
2024-01-12 13:11:04 +01:00
|
|
|
cd "$models_path" || exit
|
2023-04-15 12:21:27 +02:00
|
|
|
|
|
|
|
if [ -f "ggml-$model.mlmodel" ]; then
|
2024-01-12 13:11:04 +01:00
|
|
|
printf "Model %s already exists. Skipping download.\n" "$model"
|
2023-04-15 12:21:27 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -x "$(command -v wget)" ]; then
|
2024-01-12 13:11:04 +01:00
|
|
|
wget --quiet --show-progress -O ggml-"$model".mlmodel $src/$pfx-"$model".mlmodel
|
2023-04-15 12:21:27 +02:00
|
|
|
elif [ -x "$(command -v curl)" ]; then
|
2024-01-12 13:11:04 +01:00
|
|
|
curl -L --output ggml-"$model".mlmodel $src/$pfx-"$model".mlmodel
|
2023-04-15 12:21:27 +02:00
|
|
|
else
|
|
|
|
printf "Either wget or curl is required to download models.\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
2024-01-12 13:11:04 +01:00
|
|
|
printf "Failed to download Core ML model %s \n" "$model"
|
2023-04-15 12:21:27 +02:00
|
|
|
printf "Please try again later or download the original Whisper model files and convert them yourself.\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-01-12 13:11:04 +01:00
|
|
|
printf "Done! Model '%s' saved in 'models/ggml-%s.mlmodel'\n" "$model" "$model"
|
2023-04-15 12:21:27 +02:00
|
|
|
printf "Run the following command to compile it:\n\n"
|
2024-01-12 13:11:04 +01:00
|
|
|
printf " $ xcrun coremlc compile ./models/ggml-%s.mlmodel ./models\n\n" "$model"
|
2023-04-15 12:21:27 +02:00
|
|
|
printf "You can now use it like this:\n\n"
|
2024-01-12 13:11:04 +01:00
|
|
|
printf " $ ./main -m models/ggml-%s.bin -f samples/jfk.wav\n" "$model"
|
2023-04-15 12:21:27 +02:00
|
|
|
printf "\n"
|