Spaces:
Running
Running
whisper.nvim : add helper script for the Neovim integration
Browse files
examples/whisper.nvim/whisper.nvim
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# INSTRUCTIONS
|
| 4 |
+
#
|
| 5 |
+
# This simple script is called by Neovim to capture audio from the microphone and transcribe it with Whisper.
|
| 6 |
+
# In order for this to work, you need to clone the whisper.cpp repo and build the 'stream' tool
|
| 7 |
+
#
|
| 8 |
+
# git clone https://github.com/ggerganov/whisper.cpp
|
| 9 |
+
# cd whisper.cpp
|
| 10 |
+
# make stream
|
| 11 |
+
#
|
| 12 |
+
# Also, make sure the current script is in your PATH env variable. You should be able to run the following command:
|
| 13 |
+
#
|
| 14 |
+
# whisper.nvim
|
| 15 |
+
#
|
| 16 |
+
# Next, export the path to the whisper.cpp repository via the WHISPER_CPP_HOME env variable:
|
| 17 |
+
#
|
| 18 |
+
# export WHISPER_CPP_HOME=/path/to/whisper.cpp
|
| 19 |
+
#
|
| 20 |
+
# Finally, add the following lines to your ~/.config/nvim/init.vim:
|
| 21 |
+
#
|
| 22 |
+
# 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
|
| 23 |
+
# 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
|
| 24 |
+
# 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
|
| 25 |
+
#
|
| 26 |
+
# This allows you to press Ctrl-G in order to capture audio from the microphone and transcribe it.
|
| 27 |
+
# When you are done speaking - press Ctrl-C
|
| 28 |
+
#
|
| 29 |
+
|
| 30 |
+
# the Whisper model to use
|
| 31 |
+
model="base.en"
|
| 32 |
+
|
| 33 |
+
# export the path to the whisper.cpp repo in the WHISPER_CPP_HOME env variable
|
| 34 |
+
# https://github.com/ggerganov/whisper.cpp
|
| 35 |
+
cd ${WHISPER_CPP_HOME}
|
| 36 |
+
|
| 37 |
+
if [ ! -f ./stream ] ; then
|
| 38 |
+
echo "whisper.nvim: the 'stream' executable was not found! WHISPER_CPP_HOME=${WHISPER_CPP_HOME}" > /tmp/whisper.nvim
|
| 39 |
+
exit 1
|
| 40 |
+
fi
|
| 41 |
+
|
| 42 |
+
if [ ! -f ./models/ggml-${model}.bin ] ; then
|
| 43 |
+
echo "whisper.nvim: the '$model' model was not found! WHISPER_CPP_HOME=${WHISPER_CPP_HOME}" > /tmp/whisper.nvim
|
| 44 |
+
exit 2
|
| 45 |
+
fi
|
| 46 |
+
|
| 47 |
+
# fine-tune the parameters according to your machine specs
|
| 48 |
+
./stream -t 8 -m models/ggml-base.en.bin --step 350 --length 10000 -f /tmp/whisper.nvim 2> /dev/null
|
| 49 |
+
|
| 50 |
+
exit 0
|