Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make it possible tu use :GpWhisper <LANGUAGE> #125

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
make it possible tu use :GpWhisper <LANGUAGE>
so this can be changed on the fly.
  • Loading branch information
teto committed Apr 2, 2024
commit a8c628de1f8238f4695b53ca3404f74293331331
17 changes: 13 additions & 4 deletions lua/gp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ _H.process = function(buf, cmd, args, callback, out_reader, err_reader)
M.remove_handle(pid)
end))

M.info("spawning command: "..cmd)
handle, pid = vim.loop.spawn(cmd, {
args = args,
stdio = { nil, stdout, stderr },
Expand Down Expand Up @@ -982,7 +983,7 @@ M.prepare_commands = function()
end

M.cmd["Whisper" .. command] = function(params)
M.Whisper(function(text)
M.Whisper("en", function(text)
vim.schedule(function()
cmd(params, text)
end)
Expand Down Expand Up @@ -2793,7 +2794,8 @@ M.Prompt = function(params, target, prompt, model, template, system_template, wh
end

---@param callback function # callback function(text)
M.Whisper = function(callback)
M.Whisper = function(language, callback)
M.info("Whisper language set to "..language)
-- make sure sox is installed
if vim.fn.executable("sox") == 0 then
M.error("sox is not installed")
Expand Down Expand Up @@ -2949,7 +2951,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 @@ -3052,7 +3054,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