# Shared bits for the bundle build scripts. Source this; don't run it. # shellcheck shell=bash set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" DIST="$ROOT/dist" CACHE="${SIGIL_BUILD_CACHE:-$HOME/.cache/sigil-build}" mkdir -p "$DIST" "$CACHE" # Pretty logging. log() { printf '\033[1;36m==>\033[0m %s\n' "$*"; } warn() { printf '\033[1;33m!!\033[0m %s\n' "$*" >&2; } die() { printf '\033[1;31mxx\033[0m %s\n' "$*" >&2; exit 1; } # need [hint] — bail early on a missing host tool. need() { command -v "$1" >/dev/null 2>&1 || die "missing '$1'${2:+ — $2}"; } # fetch — download once, cache by dest path. Skips if present. fetch() { local url="$1" dest="$2" if [[ -s "$dest" ]]; then log "cached $(basename "$dest")" return fi log "download $(basename "$dest")" if command -v curl >/dev/null 2>&1; then curl -fL --retry 3 -o "$dest.part" "$url" elif command -v wget >/dev/null 2>&1; then wget -O "$dest.part" "$url" else die "need curl or wget to download $url" fi mv "$dest.part" "$dest" } # --------------------------------------------------------------------------- # Speech to text: whisper.cpp's whisper-cli, sigil-vocals + ONNX Runtime, and # the models. Both bundles ship them so transcription works out of the box. # # WITH_STT=0 leave all of it out (the launcher still works; speech # to text then needs the tools installed by hand) # WITH_MODELS=0 ship the programs but no models (the launcher # downloads them on first use, into its data folder) # WHISPER_MODEL=base ggml model to ship (tiny, base, small, medium, ...; # "base.en" etc. for English-only) # VOCAL_MODEL=UVR_MDXNET_1_9703 vocal model to ship (or Kim_Vocal_2) # WHISPER_VERSION=1.9.5 whisper.cpp release built from source # ORT_VERSION=1.31.1 ONNX Runtime release to ship WITH_STT="${WITH_STT:-1}" WITH_MODELS="${WITH_MODELS:-1}" WHISPER_MODEL="${WHISPER_MODEL:-base}" VOCAL_MODEL="${VOCAL_MODEL:-UVR_MDXNET_1_9703}" WHISPER_VERSION="${WHISPER_VERSION:-1.9.5}" ORT_VERSION="${ORT_VERSION:-1.31.1}" ORT_URL="https://github.com/microsoft/onnxruntime/releases/download/v$ORT_VERSION" # whisper_src — unpack the whisper.cpp source once; prints its directory. whisper_src() { local tar="$CACHE/whisper.cpp-$WHISPER_VERSION.tar.gz" local dir="$CACHE/whisper.cpp-$WHISPER_VERSION" fetch "https://github.com/ggml-org/whisper.cpp/archive/refs/tags/v$WHISPER_VERSION.tar.gz" "$tar" >&2 if [[ ! -f "$dir/CMakeLists.txt" ]]; then rm -rf "$dir"; mkdir -p "$dir" tar -xzf "$tar" -C "$dir" --strip-components=1 fi echo "$dir" } # build_whisper [cmake args...] — a single self-contained # whisper-cli (static ggml, no OpenMP, no SDL). AVX2/FMA/F16C are on: any # x86-64 CPU from ~2013 on. Prints the path of the built program. build_whisper() { local build="$1"; shift need cmake local src; src=$(whisper_src) log "build whisper-cli $WHISPER_VERSION ($(basename "$build"))" >&2 cmake -S "$src" -B "$build" -DCMAKE_BUILD_TYPE=Release \ -DBUILD_SHARED_LIBS=OFF -DGGML_NATIVE=OFF \ -DGGML_AVX=ON -DGGML_AVX2=ON -DGGML_FMA=ON -DGGML_F16C=ON \ -DGGML_OPENMP=OFF -DWHISPER_SDL2=OFF -DWHISPER_BUILD_TESTS=OFF \ -DWHISPER_BUILD_SERVER=OFF "$@" >&2 cmake --build "$build" --config Release -j"$(nproc)" --target whisper-cli >&2 local exe; exe=$(find "$build/bin" -maxdepth 1 -name 'whisper-cli*' -type f -print -quit) [[ -n "$exe" ]] || die "whisper-cli not built in $build" echo "$exe" } # stt_models — put the shipped models in (the launcher looks in # `models/` next to itself). Downloads are cached. stt_models() { local dir="$1" [[ "$WITH_MODELS" == "1" ]] || return 0 mkdir -p "$dir" "$CACHE/models" local w="ggml-$WHISPER_MODEL.bin" v="$VOCAL_MODEL.onnx" fetch "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/$w" "$CACHE/models/$w" fetch "https://github.com/TRvlvr/model_repo/releases/download/all_public_uvr_models/$v" "$CACHE/models/$v" cp "$CACHE/models/$w" "$CACHE/models/$v" "$dir/" }