| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# generate/whispercpp/convert-pyannote-models-to-ggml.sh |
| 4 |
# Anastasia Shchupak, 21 March 2026, 30 May 2026 |
| 5 |
# |
| 6 |
# Shell script that converts one of the two models required by the |
| 7 |
# pyannote/speaker-diarization-3.0 pipeline to ggml binary format, using the |
| 8 |
# Python scripts convert-pyannote-segmentation-to-ggml.py and |
| 9 |
# convert-pyannote-embedding-to-ggml.py. |
| 10 |
# |
| 11 |
# Which converter runs is decided from the model path: |
| 12 |
# a path containing "pyannote-segmentation.bin" -> segmentation model (-> ggml-segmentation.bin) |
| 13 |
# a path containing "pyannote-embedding.bin" -> embedding model (-> ggml-embedding.bin) |
| 14 |
# |
| 15 |
# The two models (both are downloaded from HuggingFace repos) |
| 16 |
# Segmentation: pyannote/segmentation-3.0 (pyannote-segmentation.bin) |
| 17 |
# Embedding: pyannote/wespeaker-voxceleb-resnet34-LM (pyannote-embedding.bin) |
| 18 |
# |
| 19 |
# Usage: convert-pyannote-models-to-ggml.sh <model-path> <output-dir> [--inspect] |
| 20 |
# Example: convert-pyannote-models-to-ggml.sh ./models/pyannote-segmentation.bin ./models |
| 21 |
|
| 22 |
set -e # stop if any command fails |
| 23 |
|
| 24 |
# We need this version as the newer Python (3.14) broke the import chain below. |
| 25 |
PYTHON_BIN="python3.12" |
| 26 |
|
| 27 |
usage() { |
| 28 |
printf "Usage: %s <model-path> <output-dir>\n" "$0" |
| 29 |
printf "or %s <model-path> --inspect\n" "$0" |
| 30 |
printf "Example: %s ./models/pyannote-segmentation.bin ./models\n" "$0" |
| 31 |
printf "\nThe converter is chosen from the model path:\n" |
| 32 |
printf " path containing 'pyannote-segmentation.bin' -> segmentation model\n" |
| 33 |
printf " path containing 'pyannote-embedding.bin' -> embedding model\n\n" |
| 34 |
} |
| 35 |
|
| 36 |
# check that the required arguments are provided |
| 37 |
if [ -z "$1" ] || [ -z "$2" ]; then |
| 38 |
usage |
| 39 |
exit 1 |
| 40 |
fi |
| 41 |
|
| 42 |
MODEL_PT="$1" |
| 43 |
OUT_DIR="$2" |
| 44 |
|
| 45 |
DO_INSPECT=0 |
| 46 |
if [ "$3" = "--inspect" ]; then |
| 47 |
DO_INSPECT=1 |
| 48 |
fi |
| 49 |
|
| 50 |
# validate the model path and pick its converter |
| 51 |
case "$MODEL_PT" in |
| 52 |
*pyannote-segmentation.bin*) CONVERTER="convert-pyannote-segmentation-to-ggml.py" ;; |
| 53 |
*pyannote-embedding.bin*) CONVERTER="convert-pyannote-embedding-to-ggml.py" ;; |
| 54 |
*) echo "ERROR: model name must be 'pyannote-segmentation.bin' or 'pyannote-embedding.bin'" >&2; usage 1 ;; |
| 55 |
esac |
| 56 |
|
| 57 |
echo "Creating virtual environment..." |
| 58 |
"$PYTHON_BIN" -m venv venv |
| 59 |
|
| 60 |
echo "Activating virtual environment..." |
| 61 |
source venv/bin/activate |
| 62 |
|
| 63 |
echo "Installing pyannote.audio and dependencies..." |
| 64 |
# The embedding path imports pyannote -> speaker_verification.py -> speechbrain, and speechbrain |
| 65 |
# calls torchaudio.list_audio_backends() at import time. Recent torchaudio removed that function, |
| 66 |
# so the import crashes; hence the earlier versions are specified below. Also, everything is |
| 67 |
# installed in one pip command for pip to complain if pyannote needs another version of torchaudio. |
| 68 |
pip install \ |
| 69 |
"torchaudio==2.8.0" \ |
| 70 |
"torchcodec==0.7.0" \ |
| 71 |
speechbrain \ |
| 72 |
pyannote.audio |
| 73 |
|
| 74 |
if [ "$DO_INSPECT" -eq 1 ]; then |
| 75 |
echo "Inspecting model: ${MODEL_PT}" |
| 76 |
python3 "$CONVERTER" --inspect "$MODEL_PT" |
| 77 |
else |
| 78 |
mkdir -p "$OUT_DIR" |
| 79 |
echo "Converting model: ${MODEL_PT} -> ${OUT_DIR}/" |
| 80 |
python3 "$CONVERTER" "$MODEL_PT" "$OUT_DIR" |
| 81 |
fi |
| 82 |
|
| 83 |
echo "Deactivating virtual environment..." |
| 84 |
deactivate |
| 85 |
|
| 86 |
echo "Done." |