Skip to content

Commit

Permalink
Merge branch 'main' into signature_cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Robitx authored Jul 17, 2024
2 parents 90f61c7 + a55dbda commit 0362efe
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
indent_style = tab
indent_size = 1
tab_width = 4
end_of_line = lf
insert_final_newline = true
charset = utf-8

5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,15 @@ Provides custom context per repository:

## Speech commands

#### `:GpWhisper` <!-- {doc=:GpWhisper} -->
#### `:GpWhisper` {lang?} <!-- {doc=:GpWhisper} -->

Transcription replaces the current line, visual selection or range in the current buffer. Use your mouth to ask a question in a chat buffer instead of writing it by hand, dictate some comments for the code, notes or even your next novel..

For the rest of the whisper commands, the transcription is used as an editable prompt for the equivalent non whisper command - `GpWhisperRewrite` dictates instructions for `GpRewrite` etc.

You can override the default language by setting {lang} with the 2 letter
shortname of your language (e.g. "en" for English, "fr" for French etc).

#### `:GpWhisperRewrite` <!-- {doc=:GpWhisperRewrite} -->

Similar to `:GpRewrite`, but the prompt instruction dialog uses transcribed spoken instructions.
Expand Down
9 changes: 6 additions & 3 deletions doc/gp.nvim.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*gp.nvim.txt* For NVIM v0.8.0 Last change: 2024 July 16
*gp.nvim.txt* For NVIM v0.8.0 Last change: 2024 July 17

==============================================================================
Table of Contents *gp.nvim-table-of-contents*
Expand Down Expand Up @@ -252,7 +252,7 @@ options might get deprecated and so on - it’s better to change only things
where the default doesn’t fit your needs.


https://github.com/Robitx/gp.nvim/blob/2169a731aec0108ad545b68bd95ef705e6c0e27b/lua/gp/config.lua#L8-L569
https://github.com/Robitx/gp.nvim/blob/3adf3dc7589f54cf7af887879c995aa9846aace5/lua/gp/config.lua#L8-L568


==============================================================================
Expand Down Expand Up @@ -396,7 +396,7 @@ Provides custom context per repository:
SPEECH COMMANDS *gp.nvim-speech-commands*


:GpWhisper *:GpWhisper*
:GpWhisper {lang?} *:GpWhisper*

Transcription replaces the current line, visual selection or range in the
current buffer. Use your mouth to ask a question in a chat buffer instead of
Expand All @@ -407,6 +407,9 @@ For the rest of the whisper commands, the transcription is used as an editable
prompt for the equivalent non whisper command - `GpWhisperRewrite` dictates
instructions for `GpRewrite` etc.

You can override the default language by setting {lang} with the 2 letter
shortname of your language (e.g. "en" for English, "fr" for French etc).


:GpWhisperRewrite *:GpWhisperRewrite*

Expand Down
15 changes: 11 additions & 4 deletions lua/gp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ M.prepare_commands = function()
end

M.cmd["Whisper" .. command] = function(params)
M.Whisper(function(text)
M.Whisper(M.config.whisper_language, function(text)
vim.schedule(function()
cmd(params, text)
end)
Expand Down Expand Up @@ -3269,7 +3269,7 @@ M.Prompt = function(params, target, agent, template, prompt, whisper)
end

---@param callback function # callback function(text)
M.Whisper = function(callback)
M.Whisper = function(language, callback)
-- make sure sox is installed
if vim.fn.executable("sox") == 0 then
M.error("sox is not installed")
Expand Down Expand Up @@ -3425,7 +3425,7 @@ M.Whisper = function(callback)
.. M.config.openai_api_key
.. '" -H "Content-Type: multipart/form-data" '
.. '-F model="whisper-1" -F language="'
.. M.config.whisper_language
.. language
.. '" -F file="@final.mp3" '
.. '-F response_format="json"'

Expand Down Expand Up @@ -3528,7 +3528,14 @@ M.cmd.Whisper = function(params)
end_line = params.line2
end

M.Whisper(function(text)
local args = vim.split(params.args, " ")

local language = config.whisper_language
if args[1] ~= "" then
language = args[1]
end

M.Whisper(language, function(text)
if not vim.api.nvim_buf_is_valid(buf) then
return
end
Expand Down

0 comments on commit 0362efe

Please sign in to comment.