compile whisper.cpp on Linux
First you need to clone whisper.cpp repository :
iman@Debian:~/whisper.cpp$ git clone https://github.com/ggml-org/whisper.cpp
cd whisper.cpp
Then save this as build.sh in the whisper.cpp directory and chmod +x build.sh
#!/bin/bash
export LANG=en_US.UTF-8
## depends cuda-toolkit cmake curl libcurl4-openssl-dev
# Check dependencies
DEPENDENCIES=(
'cuda-toolkit'
'cmake'
'curl'
'libcurl4-openssl-dev'
)
for i in "${DEPENDENCIES[@]}"; do
dpkg -s $i > /dev/null 2>&1;
if [ $? == 1 ]; then
echo >&2 "'$i' package is required, but not available. Aborting.";
exit 1;
fi
done
# Auto-detect CUDA compute capability
if command -v nvidia-smi &> /dev/null; then
CC=$(nvidia-smi --query-gpu=compute_cap --format=csv,noheader | head -1 | tr -d ' ')
echo "π― Detected GPU compute capability: $CC"
ARCH=$(echo $CC | sed 's/\./ /' | awk '{printf "%s%s", $1, $2}')
echo "CUDA_ARCHITECTURES: $ARCH"
else
ARCH="86" # fallback
echo "β οΈ nvidia-smi not found, using default CC 86"
fi
## see https://github.com/ggml-org/whisper.cpp
# Parse script arguments
NOZIP=false
while [[ $# -gt 0 ]]; do
case "$1" in
--no-zip|-nz) NOZIP=true ;;
*) ;; # ignore other args
esac
shift
done
# get current git commit and zip bin directory
COMMIT_ID=`git rev-parse --short HEAD`
echo $COMMIT_ID
#FILE="bin-*-$COMMIT_ID.zip"
ZIP="bin-`date +%Y%m%d`-$COMMIT_ID.zip"
if [ "$NOZIP" = false ]; then
if [ ! -f $ZIP ]; then
# zip -r bin-`date +%Y%m%d`-$COMMIT_ID.zip bin/
zip -r "$ZIP" bin/
echo "β
Created: File $ZIP"
else
echo "File $ZIP exists: skipping zip creation."
fi
else
echo "--no-zip flag set: skipping zip creation."
fi
git pull
# Configure the project in the current directory
echo "π§ Configuring cmake..."
cmake -B . --fresh -DGGML_CUDA=1 -DCMAKE_CUDA_ARCHITECTURES="$ARCH" # -DGGML_CUDA_FA_ALL_QUANTS=ON
# Build the project in the current directory
# Git version
COMMIT_ID=$(git rev-parse --short HEAD)
echo "π¨ Building commit: $COMMIT_ID"
cmake --build . --config Release -j$(nproc) --clean-first
iman@Debian:~/whisper.cpp$ ./build.sh
Download a model (only required once) :
iman@Debian:~/whisper.cpp$ ./models/download-ggml-model.sh ggml-large-v3-q5_0.bin
iman@Debian:~/whisper.cpp$ ls bin
bench main test-vad test-vad-full whisper-bench whisper-cli whisper-quantize whisper-server whisper-vad-speech-segments
Run your first inference :
iman@Debian:~/whisper.cpp$ bin/whisper-cli -m ../models/ggml-large-v3-q5_0.bin -f /path/to/input.wav --output-txt true --output-file /path/to/output.txt --language en --no-timestamps true
Check whisper-cli README.md
Category:
LLM