about summary refs log tree commit diff
path: root/pkgs/tools/audio/openai-whisper-cpp
diff options
context:
space:
mode:
authorMostly Void <7rat13@gmail.com>2022-12-07 20:56:15 +0530
committerMostly Void <7rat13@gmail.com>2022-12-31 20:11:33 +0530
commit54c0e4c4bb095ff374f7a29879a92aa2954e2dd0 (patch)
tree0405038a25fa7fbd3b4fb41ab70ee65d60ec9ef9 /pkgs/tools/audio/openai-whisper-cpp
parente8b8afb2552b76e9ac2cf8b9245c9fe31f8ac9d2 (diff)
downloadnixlib-54c0e4c4bb095ff374f7a29879a92aa2954e2dd0.tar
nixlib-54c0e4c4bb095ff374f7a29879a92aa2954e2dd0.tar.gz
nixlib-54c0e4c4bb095ff374f7a29879a92aa2954e2dd0.tar.bz2
nixlib-54c0e4c4bb095ff374f7a29879a92aa2954e2dd0.tar.lz
nixlib-54c0e4c4bb095ff374f7a29879a92aa2954e2dd0.tar.xz
nixlib-54c0e4c4bb095ff374f7a29879a92aa2954e2dd0.tar.zst
nixlib-54c0e4c4bb095ff374f7a29879a92aa2954e2dd0.zip
openai-whisper-cpp: init at 1.0.4
Diffstat (limited to 'pkgs/tools/audio/openai-whisper-cpp')
-rw-r--r--pkgs/tools/audio/openai-whisper-cpp/default.nix60
-rw-r--r--pkgs/tools/audio/openai-whisper-cpp/download-models.patch42
2 files changed, 102 insertions, 0 deletions
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"