Skip to content

Commit 49ded50

Browse files
authored
Merge pull request #125 from teto/teto/whisper-dynamic-lang
make it possible tu use :GpWhisper <LANGUAGE>
2 parents 0878f2f + 6a7a78f commit 49ded50

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
indent_size = 1
6+
tab_width = 4
7+
end_of_line = lf
8+
insert_final_newline = true
9+
charset = utf-8
10+

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,15 @@ Provides custom context per repository:
311311

312312
## Speech commands
313313

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

316316
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..
317317

318318
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.
319319

320+
You can override the default language by setting {lang} with the 2 letter
321+
shortname of your language (e.g. "en" for English, "fr" for French etc).
322+
320323
#### `:GpWhisperRewrite` <!-- {doc=:GpWhisperRewrite} -->
321324

322325
Similar to `:GpRewrite`, but the prompt instruction dialog uses transcribed spoken instructions.

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)