Merge pull request #205008 from dit7ya/openai-whisper-cpp
openai-whisper-cpp: init at 1.0.4
This commit is contained in:
commit
6dad2ef140
3 changed files with 106 additions and 0 deletions
60
pkgs/tools/audio/openai-whisper-cpp/default.nix
Normal file
60
pkgs/tools/audio/openai-whisper-cpp/default.nix
Normal 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 ];
|
||||
};
|
||||
}
|
42
pkgs/tools/audio/openai-whisper-cpp/download-models.patch
Normal file
42
pkgs/tools/audio/openai-whisper-cpp/download-models.patch
Normal 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"
|
|
@ -17850,6 +17850,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 { };
|
||||
|
|
Loading…
Reference in a new issue