From 2298310dd8ed6d78baa56aee43d28674ed656bd3 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Fri, 28 Oct 2022 19:57:09 +0300 Subject: [PATCH] whisper.nvim : add helper script for the Neovim integration --- examples/whisper.nvim/whisper.nvim | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 examples/whisper.nvim/whisper.nvim diff --git a/examples/whisper.nvim/whisper.nvim b/examples/whisper.nvim/whisper.nvim new file mode 100755 index 0000000..8807fac --- /dev/null +++ b/examples/whisper.nvim/whisper.nvim @@ -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 :!whisper.nvim:let @a = system("cat /tmp/whisper.nvim \| tail -n 1 \| xargs -0 \| tr -d '\\n' \| sed -e 's/^[[:space:]]*//'")a +# nnoremap :!whisper.nvim:let @a = system("cat /tmp/whisper.nvim \| tail -n 1 \| xargs -0 \| tr -d '\\n' \| sed -e 's/^[[:space:]]*//'")"ap +# vnoremap c:!whisper.nvim:let @a = system("cat /tmp/whisper.nvim \| tail -n 1 \| xargs -0 \| tr -d '\\n' \| sed -e 's/^[[:space:]]*//'")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