openai-whisper-cpp: init at 1.0.4

This commit is contained in:
Mostly Void 2022-12-07 20:56:15 +05:30
parent e8b8afb255
commit 54c0e4c4bb
No known key found for this signature in database
GPG Key ID: E2B7342D0CAA82C2
3 changed files with 106 additions and 0 deletions

View File

@ -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 ];
};
}

View File

@ -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"

View File

@ -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 { };