diff options
author | Ryan Lahfa <masterancpp@gmail.com> | 2022-12-31 22:30:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-31 22:30:03 +0100 |
commit | 6dad2ef140c5585a352c53976d122b7883f6ada3 (patch) | |
tree | 923773c26bc8120caae5bcbd9deb5fab1fe2c4a3 /pkgs/tools/audio | |
parent | 77451d9a85dca70af51d47a828194268b8fbd371 (diff) | |
parent | 54c0e4c4bb095ff374f7a29879a92aa2954e2dd0 (diff) |
Merge pull request #205008 from dit7ya/openai-whisper-cpp
openai-whisper-cpp: init at 1.0.4
Diffstat (limited to 'pkgs/tools/audio')
-rw-r--r-- | pkgs/tools/audio/openai-whisper-cpp/default.nix | 60 | ||||
-rw-r--r-- | pkgs/tools/audio/openai-whisper-cpp/download-models.patch | 42 |
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 0000000000000..b59016e2c9f18 --- /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 0000000000000..419ddced72b94 --- /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" |