From 54c0e4c4bb095ff374f7a29879a92aa2954e2dd0 Mon Sep 17 00:00:00 2001 From: Mostly Void <7rat13@gmail.com> Date: Wed, 7 Dec 2022 20:56:15 +0530 Subject: [PATCH] openai-whisper-cpp: init at 1.0.4 --- .../audio/openai-whisper-cpp/default.nix | 60 +++++++++++++++++++ .../openai-whisper-cpp/download-models.patch | 42 +++++++++++++ pkgs/top-level/all-packages.nix | 4 ++ 3 files changed, 106 insertions(+) create mode 100644 pkgs/tools/audio/openai-whisper-cpp/default.nix create mode 100644 pkgs/tools/audio/openai-whisper-cpp/download-models.patch diff --git a/pkgs/tools/audio/openai-whisper-cpp/default.nix b/pkgs/tools/audio/openai-whisper-cpp/default.nix new file mode 100644 index 000000000000..b59016e2c9f1 --- /dev/null +++ b/pkgs/tools/audio/openai-whisper-cpp/default.nix @@ -0,0 +1,60 @@ +{ lib +, stdenv +, fetchFromGitHub +, SDL2 +, makeWrapper +, wget +, Accelerate +, CoreGraphics +, CoreVideo +}: + +stdenv.mkDerivation rec { + pname = "whisper-cpp"; + version = "1.0.4"; + + src = fetchFromGitHub { + owner = "ggerganov"; + repo = "whisper.cpp"; + rev = version; + sha256 = "sha256-lw+POI47bW66NlmMPJKAkqAYhOnyGaFqcS2cX5LRBbk="; + }; + + # The upstream download script tries to download the models to the + # directory of the script, which is not writable due to being + # inside the nix store. This patch changes the script to download + # the models to the current directory of where it is being run from. + patches = [ ./download-models.patch ]; + + nativeBuildInputs = [ makeWrapper ]; + + buildInputs = [ SDL2 ] ++ lib.optionals stdenv.isDarwin [ Accelerate CoreGraphics CoreVideo ]; + + makeFlags = [ "main" "stream" ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + cp ./main $out/bin/whisper-cpp + cp ./stream $out/bin/whisper-cpp-stream + + cp models/download-ggml-model.sh $out/bin/whisper-cpp-download-ggml-model + + wrapProgram $out/bin/whisper-cpp-download-ggml-model \ + --prefix PATH : ${lib.makeBinPath [wget]} + + runHook postInstall + ''; + + meta = with lib; { + description = "Port of OpenAI's Whisper model in C/C++"; + longDescription = '' + To download the models as described in the project's readme, you may + use the `whisper-cpp-download-ggml-model` binary from this package. + ''; + homepage = "https://github.com/ggerganov/whisper.cpp"; + license = licenses.mit; + maintainers = with maintainers; [ dit7ya ]; + }; +} diff --git a/pkgs/tools/audio/openai-whisper-cpp/download-models.patch b/pkgs/tools/audio/openai-whisper-cpp/download-models.patch new file mode 100644 index 000000000000..419ddced72b9 --- /dev/null +++ b/pkgs/tools/audio/openai-whisper-cpp/download-models.patch @@ -0,0 +1,42 @@ +diff --git a/models/download-ggml-model.sh b/models/download-ggml-model.sh +index cf54623..5e9c905 100755 +--- a/models/download-ggml-model.sh ++++ b/models/download-ggml-model.sh +@@ -9,18 +9,6 @@ + src="https://huggingface.co/datasets/ggerganov/whisper.cpp" + pfx="resolve/main/ggml" + +-# get the path of this script +-function get_script_path() { +- if [ -x "$(command -v realpath)" ]; then +- echo "$(dirname $(realpath $0))" +- else +- local ret="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)" +- echo "$ret" +- fi +-} +- +-models_path=$(get_script_path) +- + # Whisper models + models=( "tiny.en" "tiny" "base.en" "base" "small.en" "small" "medium.en" "medium" "large-v1" "large" ) + +@@ -54,8 +42,6 @@ fi + + printf "Downloading ggml model $model from '$src' ...\n" + +-cd $models_path +- + if [ -f "ggml-$model.bin" ]; then + printf "Model $model already exists. Skipping download.\n" + exit 0 +@@ -77,7 +63,7 @@ if [ $? -ne 0 ]; then + exit 1 + fi + +-printf "Done! Model '$model' saved in 'models/ggml-$model.bin'\n" ++printf "Done! Model '$model' saved in 'ggml-$model.bin'\n" + printf "You can now use it like this:\n\n" +-printf " $ ./main -m models/ggml-$model.bin -f samples/jfk.wav\n" ++printf " $ whisper-cpp -m ggml-$model.bin -f samples/jfk.wav\n" + printf "\n" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index f7a1949c7b5f..e3cee3b65334 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17534,6 +17534,10 @@ with pkgs; openai-whisper = with python3.pkgs; toPythonApplication openai-whisper; + openai-whisper-cpp = callPackage ../tools/audio/openai-whisper-cpp { + inherit (darwin.apple_sdk.frameworks) Accelerate CoreGraphics CoreVideo; + }; + opengrok = callPackage ../development/tools/misc/opengrok { }; openocd = callPackage ../development/embedded/openocd { };