|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# This script downloads Whisper VAD model files that have already been converted |
| 4 | +# to ggml format. This way you don't have to convert them yourself. |
| 5 | + |
| 6 | +src="https://huggingface.co/ggml-org/whisper-vad" |
| 7 | +pfx="resolve/main/ggml" |
| 8 | + |
| 9 | +BOLD="\033[1m" |
| 10 | +RESET='\033[0m' |
| 11 | + |
| 12 | +# get the path of this script |
| 13 | +get_script_path() { |
| 14 | + if [ -x "$(command -v realpath)" ]; then |
| 15 | + dirname "$(realpath "$0")" |
| 16 | + else |
| 17 | + _ret="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit ; pwd -P)" |
| 18 | + echo "$_ret" |
| 19 | + fi |
| 20 | +} |
| 21 | + |
| 22 | +script_path="$(get_script_path)" |
| 23 | + |
| 24 | +# Check if the script is inside a /bin/ directory |
| 25 | +case "$script_path" in |
| 26 | + */bin) default_download_path="$PWD" ;; # Use current directory as default download path if in /bin/ |
| 27 | + *) default_download_path="$script_path" ;; # Otherwise, use script directory |
| 28 | +esac |
| 29 | + |
| 30 | +models_path="${2:-$default_download_path}" |
| 31 | + |
| 32 | +# Whisper VAD models |
| 33 | +models="silero-v5.1.2" |
| 34 | + |
| 35 | +# list available models |
| 36 | +list_models() { |
| 37 | + printf "\n" |
| 38 | + printf "Available models:" |
| 39 | + model_class="" |
| 40 | + for model in $models; do |
| 41 | + this_model_class="${model%%[.-]*}" |
| 42 | + if [ "$this_model_class" != "$model_class" ]; then |
| 43 | + printf "\n " |
| 44 | + model_class=$this_model_class |
| 45 | + fi |
| 46 | + printf " %s" "$model" |
| 47 | + done |
| 48 | + printf "\n\n" |
| 49 | +} |
| 50 | + |
| 51 | +if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then |
| 52 | + printf "Usage: %s <model> [models_path]\n" "$0" |
| 53 | + list_models |
| 54 | + exit 1 |
| 55 | +fi |
| 56 | + |
| 57 | +model=$1 |
| 58 | + |
| 59 | +if ! echo "$models" | grep -q -w "$model"; then |
| 60 | + printf "Invalid model: %s\n" "$model" |
| 61 | + list_models |
| 62 | + |
| 63 | + exit 1 |
| 64 | +fi |
| 65 | + |
| 66 | +# download ggml model |
| 67 | +printf "Downloading ggml model %s from '%s' ...\n" "$model" "$src" |
| 68 | + |
| 69 | +cd "$models_path" || exit |
| 70 | + |
| 71 | +if [ -f "ggml-$model.bin" ]; then |
| 72 | + printf "Model %s already exists. Skipping download.\n" "$model" |
| 73 | + exit 0 |
| 74 | +fi |
| 75 | + |
| 76 | +if [ -x "$(command -v wget2)" ]; then |
| 77 | + wget2 --no-config --progress bar -O ggml-"$model".bin $src/$pfx-"$model".bin |
| 78 | +elif [ -x "$(command -v wget)" ]; then |
| 79 | + wget --no-config --quiet --show-progress -O ggml-"$model".bin $src/$pfx-"$model".bin |
| 80 | +elif [ -x "$(command -v curl)" ]; then |
| 81 | + curl -L --output ggml-"$model".bin $src/$pfx-"$model".bin |
| 82 | +else |
| 83 | + printf "Either wget or curl is required to download models.\n" |
| 84 | + exit 1 |
| 85 | +fi |
| 86 | + |
| 87 | +if [ $? -ne 0 ]; then |
| 88 | + printf "Failed to download ggml model %s \n" "$model" |
| 89 | + printf "Please try again later or download the original Whisper model files and convert them yourself.\n" |
| 90 | + exit 1 |
| 91 | +fi |
| 92 | + |
| 93 | +# Check if 'whisper-cli' is available in the system PATH |
| 94 | +if command -v whisper-cli >/dev/null 2>&1; then |
| 95 | + # If found, use 'whisper-cli' (relying on PATH resolution) |
| 96 | + whisper_cmd="whisper-cli" |
| 97 | +else |
| 98 | + # If not found, use the local build version |
| 99 | + whisper_cmd="./build/bin/whisper-cli" |
| 100 | +fi |
| 101 | + |
| 102 | +printf "Done! Model '%s' saved in '%s/ggml-%s.bin'\n" "$model" "$models_path" "$model" |
| 103 | +printf "You can now use it like this:\n\n" |
| 104 | +printf " $ %s -vm %s/ggml-%s.bin --vad -f samples/jfk.wav -m models/ggml-base.en.bin\n" "$whisper_cmd" "$models_path" "$model" |
| 105 | +printf "\n" |
0 commit comments