]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
whisper.nvim : add helper script for the Neovim integration
authorGeorgi Gerganov <redacted>
Fri, 28 Oct 2022 16:57:09 +0000 (19:57 +0300)
committerGeorgi Gerganov <redacted>
Fri, 28 Oct 2022 17:25:37 +0000 (20:25 +0300)
examples/whisper.nvim/whisper.nvim [new file with mode: 0755]

diff --git a/examples/whisper.nvim/whisper.nvim b/examples/whisper.nvim/whisper.nvim
new file mode 100755 (executable)
index 0000000..8807fac
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+# INSTRUCTIONS
+#
+# This simple script is called by Neovim to capture audio from the microphone and transcribe it with Whisper.
+# In order for this to work, you need to clone the whisper.cpp repo and build the 'stream' tool
+#
+#   git clone https://github.com/ggerganov/whisper.cpp
+#   cd whisper.cpp
+#   make stream
+#
+# Also, make sure the current script is in your PATH env variable. You should be able to run the following command:
+#
+#   whisper.nvim
+#
+# Next, export the path to the whisper.cpp repository via the WHISPER_CPP_HOME env variable:
+#
+#   export WHISPER_CPP_HOME=/path/to/whisper.cpp
+#
+# Finally, add the following lines to your ~/.config/nvim/init.vim:
+#
+#   inoremap <C-G>  <C-O>:!whisper.nvim<CR><C-O>:let @a = system("cat /tmp/whisper.nvim \| tail -n 1 \| xargs -0 \| tr -d '\\n' \| sed -e 's/^[[:space:]]*//'")<CR><C-R>a
+#   nnoremap <C-G>       :!whisper.nvim<CR>:let @a = system("cat /tmp/whisper.nvim \| tail -n 1 \| xargs -0 \| tr -d '\\n' \| sed -e 's/^[[:space:]]*//'")<CR>"ap
+#   vnoremap <C-G> c<C-O>:!whisper.nvim<CR><C-O>:let @a = system("cat /tmp/whisper.nvim \| tail -n 1 \| xargs -0 \| tr -d '\\n' \| sed -e 's/^[[:space:]]*//'")<CR><C-R>a
+#
+# This allows you to press Ctrl-G in order to capture audio from the microphone and transcribe it.
+# When you are done speaking - press Ctrl-C
+#
+
+# the Whisper model to use
+model="base.en"
+
+# export the path to the whisper.cpp repo in the WHISPER_CPP_HOME env variable
+# https://github.com/ggerganov/whisper.cpp
+cd ${WHISPER_CPP_HOME}
+
+if [ ! -f ./stream ] ; then
+    echo "whisper.nvim: the 'stream' executable was not found! WHISPER_CPP_HOME=${WHISPER_CPP_HOME}" > /tmp/whisper.nvim
+    exit 1
+fi
+
+if [ ! -f ./models/ggml-${model}.bin ] ; then
+    echo "whisper.nvim: the '$model' model was not found! WHISPER_CPP_HOME=${WHISPER_CPP_HOME}" > /tmp/whisper.nvim
+    exit 2
+fi
+
+# fine-tune the parameters according to your machine specs
+./stream -t 8 -m models/ggml-base.en.bin --step 350 --length 10000 -f /tmp/whisper.nvim 2> /dev/null
+
+exit 0