Spaces:
Running
Running
vad : add download-vad-model scripts (#3149)
Browse files* vad : add download-vad-model scripts
This commit adds a script to download VAD models.
* vad : add vad model download script for windows [no ci]
Refs: https://github.com/ggml-org/whisper.cpp/issues/3146
- models/download-vad-model.cmd +99 -0
- models/download-vad-model.sh +105 -0
models/download-vad-model.cmd
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
|
| 3 |
+
rem Save the original working directory
|
| 4 |
+
set "orig_dir=%CD%"
|
| 5 |
+
|
| 6 |
+
rem Get the script directory
|
| 7 |
+
set "script_dir=%~dp0"
|
| 8 |
+
|
| 9 |
+
rem Check if the script directory contains "\bin\" (case-insensitive)
|
| 10 |
+
echo %script_dir% | findstr /i "\\bin\\" >nul
|
| 11 |
+
if %ERRORLEVEL%==0 (
|
| 12 |
+
rem If script is in a \bin\ directory, use the original working directory as default download path
|
| 13 |
+
set "default_download_path=%orig_dir%"
|
| 14 |
+
) else (
|
| 15 |
+
rem Otherwise, use script directory
|
| 16 |
+
pushd %~dp0
|
| 17 |
+
set "default_download_path=%CD%"
|
| 18 |
+
popd
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
rem Set the root path to be the parent directory of the script
|
| 22 |
+
for %%d in (%~dp0..) do set "root_path=%%~fd"
|
| 23 |
+
|
| 24 |
+
rem Count number of arguments passed to script
|
| 25 |
+
set argc=0
|
| 26 |
+
for %%x in (%*) do set /A argc+=1
|
| 27 |
+
|
| 28 |
+
set models=silero-v5.1.2
|
| 29 |
+
|
| 30 |
+
rem If argc is not equal to 1 or 2, print usage information and exit
|
| 31 |
+
if %argc% NEQ 1 (
|
| 32 |
+
if %argc% NEQ 2 (
|
| 33 |
+
echo.
|
| 34 |
+
echo Usage: download-vad-model.cmd model [models_path]
|
| 35 |
+
CALL :list_models
|
| 36 |
+
goto :eof
|
| 37 |
+
)
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
if %argc% EQU 2 (
|
| 41 |
+
set models_path=%2
|
| 42 |
+
) else (
|
| 43 |
+
set models_path=%default_download_path%
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
set model=%1
|
| 47 |
+
|
| 48 |
+
for %%b in (%models%) do (
|
| 49 |
+
if "%%b"=="%model%" (
|
| 50 |
+
CALL :download_model
|
| 51 |
+
goto :eof
|
| 52 |
+
)
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
echo Invalid model: %model%
|
| 56 |
+
CALL :list_models
|
| 57 |
+
goto :eof
|
| 58 |
+
|
| 59 |
+
:download_model
|
| 60 |
+
echo Downloading vad model %model%...
|
| 61 |
+
|
| 62 |
+
if exist "%models_path%\\ggml-%model%.bin" (
|
| 63 |
+
echo Model %model% already exists. Skipping download.
|
| 64 |
+
goto :eof
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "Start-BitsTransfer -Source https://huggingface.co/ggml-org/whisper-vad/resolve/main/ggml-%model%.bin -Destination \"%models_path%\\ggml-%model%.bin\""
|
| 69 |
+
|
| 70 |
+
if %ERRORLEVEL% neq 0 (
|
| 71 |
+
echo Failed to download ggml model %model%
|
| 72 |
+
echo Please try again later or download the original Whisper model files and convert them yourself.
|
| 73 |
+
goto :eof
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
rem Check if 'whisper-cli' is available in the system PATH
|
| 77 |
+
where whisper-cli >nul 2>&1
|
| 78 |
+
if %ERRORLEVEL%==0 (
|
| 79 |
+
rem If found, suggest 'whisper-cli' (relying on PATH resolution)
|
| 80 |
+
set "whisper_cmd=whisper-cli"
|
| 81 |
+
) else (
|
| 82 |
+
rem If not found, suggest the local build version
|
| 83 |
+
set "whisper_cmd=%root_path%\build\bin\Release\whisper-cli.exe"
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
echo Done! Model %model% saved in %models_path%\ggml-%model%.bin
|
| 87 |
+
echo You can now use it like this:
|
| 88 |
+
echo %whisper_cmd% -vm %models_path%\ggml-%model%.bin --vad -m models/ggml-base.en.bin -f samples\jfk.wav
|
| 89 |
+
|
| 90 |
+
goto :eof
|
| 91 |
+
|
| 92 |
+
:list_models
|
| 93 |
+
echo.
|
| 94 |
+
echo Available models:
|
| 95 |
+
(for %%a in (%models%) do (
|
| 96 |
+
echo %%a
|
| 97 |
+
))
|
| 98 |
+
echo.
|
| 99 |
+
exit /b
|
models/download-vad-model.sh
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"
|