@@ -17,6 +17,7 @@ local deprecated = {
1717 chat_system_prompt = " `chat_system_prompt`\n " .. switch_to_agent ,
1818 command_prompt_prefix = " `command_prompt_prefix`\n Please use `command_prompt_prefix_template`"
1919 .. " with support for \n `{{agent}}` variable so you know which agent is currently active" ,
20+ whisper_max_time = " `whisper_max_time`\n Please use fully customizable `whisper_rec_cmd`" ,
2021}
2122
2223---- ----------------------------------------------------------------------------
@@ -2863,41 +2864,35 @@ M.Whisper = function(callback)
28632864 return
28642865 end
28652866
2867+ local rec_file = M .config .whisper_dir .. " /rec.wav"
28662868 local rec_options = {
28672869 sox = {
28682870 cmd = " sox" ,
28692871 opts = {
2870- -- single channel
28712872 " -c" ,
28722873 " 1" ,
2873- -- small buffer
28742874 " --buffer" ,
28752875 " 32" ,
28762876 " -d" ,
2877- -- output file
2878- M .config .whisper_dir .. " /rec.wav" ,
2879- -- max recording time
2877+ " rec.wav" ,
28802878 " trim" ,
28812879 " 0" ,
2882- M . config . whisper_max_time ,
2880+ " 3600 " ,
28832881 },
28842882 exit_code = 0 ,
28852883 },
28862884 arecord = {
28872885 cmd = " arecord" ,
28882886 opts = {
2889- -- single channel
28902887 " -c" ,
28912888 " 1" ,
28922889 " -f" ,
28932890 " S16_LE" ,
28942891 " -r" ,
28952892 " 48000" ,
2896- -- max recording time
28972893 " -d" ,
28982894 3600 ,
2899- -- output file
2900- M .config .whisper_dir .. " /rec.wav" ,
2895+ " rec.wav" ,
29012896 },
29022897 exit_code = 1 ,
29032898 },
@@ -2911,7 +2906,7 @@ M.Whisper = function(callback)
29112906 " :0" ,
29122907 " -t" ,
29132908 " 3600" ,
2914- M . config . whisper_dir .. " / rec.wav" ,
2909+ " rec.wav" ,
29152910 },
29162911 exit_code = 255 ,
29172912 },
@@ -3047,25 +3042,48 @@ M.Whisper = function(callback)
30473042 end )
30483043 end
30493044
3050- local rec_cmd = " sox"
3051- if vim .fn .executable (" ffmpeg" ) == 1 then
3052- local devices = vim .fn .system (" ffmpeg -devices -v quiet | grep -i avfoundation | wc -l" )
3053- devices = string.gsub (devices , " ^%s*(.-)%s*$" , " %1" )
3054- if devices == " 1" then
3055- rec_cmd = " ffmpeg"
3045+ local cmd = {}
3046+
3047+ local rec_cmd = M .config .whisper_rec_cmd
3048+ -- if rec_cmd not set explicitly, try to autodetect
3049+ if not rec_cmd then
3050+ rec_cmd = " sox"
3051+ if vim .fn .executable (" ffmpeg" ) == 1 then
3052+ local devices = vim .fn .system (" ffmpeg -devices -v quiet | grep -i avfoundation | wc -l" )
3053+ devices = string.gsub (devices , " ^%s*(.-)%s*$" , " %1" )
3054+ if devices == " 1" then
3055+ rec_cmd = " ffmpeg"
3056+ end
30563057 end
3058+ if vim .fn .executable (" arecord" ) == 1 then
3059+ rec_cmd = " arecord"
3060+ end
3061+ end
3062+
3063+ if type (rec_cmd ) == " table" and rec_cmd [1 ] and rec_options [rec_cmd [1 ]] then
3064+ rec_cmd = vim .deepcopy (rec_cmd )
3065+ cmd .cmd = table.remove (rec_cmd , 1 )
3066+ cmd .exit_code = rec_options [cmd .cmd ].exit_code
3067+ cmd .opts = rec_cmd
3068+ elseif type (rec_cmd ) == " string" and rec_options [rec_cmd ] then
3069+ cmd = rec_options [rec_cmd ]
3070+ else
3071+ M .error (string.format (" Whisper got invalid recording command: %s" , rec_cmd ))
3072+ close ()
3073+ return
30573074 end
3058- if vim .fn .executable (" arecord" ) == 1 then
3059- rec_cmd = " arecord"
3075+ for i , v in ipairs (cmd .opts ) do
3076+ if v == " rec.wav" then
3077+ cmd .opts [i ] = rec_file
3078+ end
30603079 end
30613080
3062- local cmd = rec_options [rec_cmd ]
30633081 M ._H .process (nil , cmd .cmd , cmd .opts , function (code , signal , stdout , stderr )
30643082 close ()
30653083
30663084 if code and code ~= cmd .exit_code then
30673085 M .error (
3068- rec_cmd
3086+ cmd . cmd
30693087 .. " exited with code and signal:\n code: "
30703088 .. code
30713089 .. " , signal: "
0 commit comments