Skip to content

Commit edf1ee1

Browse files
authored
whisper : enhance model download scripts functionality and resolve compiler warning (#2925)
* whisper : improve whisper-cli executable path detection in model download shell scripts If whisper-cli is found on the path, do not suggest invoking from build directory. This improves flexibility and usability for distribution and packaging scenarios. * whisper : enhance Windows model download batch script to have comparable functionality and behaviour as shell scripts * Download models to the current directory if the script is executed from the \bin\ directory (for future distribution scenarios where the script is in the \bin\ subdirectory of a Windows build) * Add model_path command line argument * If whisper-cli is found on the path, do not suggest invoking from build directory * whisper : resolve compiler warning by removing duplicate definition of NOMINMAX in whisper-cli code
1 parent cf5ddb8 commit edf1ee1

File tree

4 files changed

+73
-19
lines changed

4 files changed

+73
-19
lines changed

examples/cli/cli.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#include <cstring>
1414

1515
#if defined(_WIN32)
16+
#ifndef NOMINMAX
1617
#define NOMINMAX
18+
#endif
1719
#include <windows.h>
1820
#endif
1921

models/download-coreml-model.sh

+12-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,18 @@ if [ $? -ne 0 ]; then
8585
exit 1
8686
fi
8787

88-
printf "Done! Model '%s' saved in 'models/ggml-%s.mlmodel'\n" "$model" "$model"
88+
# Check if 'whisper-cli' is available in the system PATH
89+
if command -v whisper-cli >/dev/null 2>&1; then
90+
# If found, use 'whisper-cli' (relying on PATH resolution)
91+
whisper_cmd="whisper-cli"
92+
else
93+
# If not found, use the local build version
94+
whisper_cmd="./build/bin/whisper-cli"
95+
fi
96+
97+
printf "Done! Model '%s' saved in '%s/ggml-%s.bin'\n" "$model" "$models_path" "$model"
8998
printf "Run the following command to compile it:\n\n"
90-
printf " $ xcrun coremlc compile ./models/ggml-%s.mlmodel ./models\n\n" "$model"
99+
printf " $ xcrun coremlc compile %s/ggml-%s.mlmodel %s\n\n" "$models_path" "$model" "$models_path"
91100
printf "You can now use it like this:\n\n"
92-
printf " $ ./build/bin/whisper-cli -m models/ggml-%s.bin -f samples/jfk.wav\n" "$model"
101+
printf " $ %s -m %s/ggml-%s.bin -f samples/jfk.wav\n" "$whisper_cmd" "$models_path" "$model"
93102
printf "\n"

models/download-ggml-model.cmd

+49-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
@echo off
22

3-
pushd %~dp0
4-
set models_path=%CD%
5-
for %%d in (%~dp0..) do set root_path=%%~fd
6-
popd
3+
rem Save the original working directory
4+
set "orig_dir=%CD%"
75

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
825
set argc=0
926
for %%x in (%*) do set /A argc+=1
1027

@@ -21,11 +38,20 @@ large-v2 large-v2-q5_0 large-v2-q8_0 ^
2138
large-v3 large-v3-q5_0 ^
2239
large-v3-turbo large-v3-turbo-q5_0 large-v3-turbo-q8_0
2340

24-
if %argc% neq 1 (
25-
echo.
26-
echo Usage: download-ggml-model.cmd model
27-
CALL :list_models
28-
goto :eof
41+
rem If argc is not equal to 1 or 2, print usage information and exit
42+
if %argc% NEQ 1 (
43+
if %argc% NEQ 2 (
44+
echo.
45+
echo Usage: download-ggml-model.cmd model [models_path]
46+
CALL :list_models
47+
goto :eof
48+
)
49+
)
50+
51+
if %argc% EQU 2 (
52+
set models_path=%2
53+
) else (
54+
set models_path=%default_download_path%
2955
)
3056

3157
set model=%1
@@ -44,24 +70,32 @@ goto :eof
4470
:download_model
4571
echo Downloading ggml model %model%...
4672

47-
cd "%models_path%"
48-
49-
if exist "ggml-%model%.bin" (
73+
if exist "%models_path%\\ggml-%model%.bin" (
5074
echo Model %model% already exists. Skipping download.
5175
goto :eof
5276
)
5377

54-
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "Start-BitsTransfer -Source https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-%model%.bin -Destination ggml-%model%.bin"
78+
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "Start-BitsTransfer -Source https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-%model%.bin -Destination \"%models_path%\\ggml-%model%.bin\""
5579

5680
if %ERRORLEVEL% neq 0 (
5781
echo Failed to download ggml model %model%
5882
echo Please try again later or download the original Whisper model files and convert them yourself.
5983
goto :eof
6084
)
6185

62-
echo Done! Model %model% saved in %root_path%\models\ggml-%model%.bin
86+
rem Check if 'whisper-cli' is available in the system PATH
87+
where whisper-cli >nul 2>&1
88+
if %ERRORLEVEL%==0 (
89+
rem If found, suggest 'whisper-cli' (relying on PATH resolution)
90+
set "whisper_cmd=whisper-cli"
91+
) else (
92+
rem If not found, suggest the local build version
93+
set "whisper_cmd=%root_path%\build\bin\Release\whisper-cli.exe"
94+
)
95+
96+
echo Done! Model %model% saved in %models_path%\ggml-%model%.bin
6397
echo You can now use it like this:
64-
echo %~dp0build\bin\Release\whisper-cli.exe -m %root_path%\models\ggml-%model%.bin -f %root_path%\samples\jfk.wav
98+
echo %whisper_cmd% -m %models_path%\ggml-%model%.bin -f samples\jfk.wav
6599

66100
goto :eof
67101

models/download-ggml-model.sh

+10-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,16 @@ if [ $? -ne 0 ]; then
134134
exit 1
135135
fi
136136

137+
# Check if 'whisper-cli' is available in the system PATH
138+
if command -v whisper-cli >/dev/null 2>&1; then
139+
# If found, use 'whisper-cli' (relying on PATH resolution)
140+
whisper_cmd="whisper-cli"
141+
else
142+
# If not found, use the local build version
143+
whisper_cmd="./build/bin/whisper-cli"
144+
fi
145+
137146
printf "Done! Model '%s' saved in '%s/ggml-%s.bin'\n" "$model" "$models_path" "$model"
138147
printf "You can now use it like this:\n\n"
139-
printf " $ ./build/bin/whisper-cli -m %s/ggml-%s.bin -f samples/jfk.wav\n" "$models_path" "$model"
148+
printf " $ %s -m %s/ggml-%s.bin -f samples/jfk.wav\n" "$whisper_cmd" "$models_path" "$model"
140149
printf "\n"

0 commit comments

Comments
 (0)