Skip to content

Commit 44f6256

Browse files
committed
make it possible tu use :GpWhisper <LANGUAGE>
so this can be changed on the fly.
1 parent 5cc8a4e commit 44f6256

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lua/gp/init.lua

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ M.prepare_commands = function()
11611161
end
11621162

11631163
M.cmd["Whisper" .. command] = function(params)
1164-
M.Whisper(function(text)
1164+
M.Whisper(M.config.whisper_language, function(text)
11651165
vim.schedule(function()
11661166
cmd(params, text)
11671167
end)
@@ -3200,7 +3200,7 @@ M.Prompt = function(params, target, prompt, model, template, system_template, wh
32003200
end
32013201

32023202
---@param callback function # callback function(text)
3203-
M.Whisper = function(callback)
3203+
M.Whisper = function(language, callback)
32043204
-- make sure sox is installed
32053205
if vim.fn.executable("sox") == 0 then
32063206
M.error("sox is not installed")
@@ -3356,7 +3356,7 @@ M.Whisper = function(callback)
33563356
.. M.config.openai_api_key
33573357
.. '" -H "Content-Type: multipart/form-data" '
33583358
.. '-F model="whisper-1" -F language="'
3359-
.. M.config.whisper_language
3359+
.. language
33603360
.. '" -F file="@final.mp3" '
33613361
.. '-F response_format="json"'
33623362

@@ -3459,7 +3459,14 @@ M.cmd.Whisper = function(params)
34593459
end_line = params.line2
34603460
end
34613461

3462-
M.Whisper(function(text)
3462+
local args = vim.split(params.args, " ")
3463+
3464+
local language = config.whisper_language
3465+
if args[1] ~= "" then
3466+
language = args[1]
3467+
end
3468+
3469+
M.Whisper(language, function(text)
34633470
if not vim.api.nvim_buf_is_valid(buf) then
34643471
return
34653472
end

0 commit comments

Comments
 (0)