@@ -17,6 +17,7 @@ local deprecated = {
17
17
chat_system_prompt = " `chat_system_prompt`\n " .. switch_to_agent ,
18
18
command_prompt_prefix = " `command_prompt_prefix`\n Please use `command_prompt_prefix_template`"
19
19
.. " 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`" ,
20
21
}
21
22
22
23
---- ----------------------------------------------------------------------------
@@ -2863,41 +2864,35 @@ M.Whisper = function(callback)
2863
2864
return
2864
2865
end
2865
2866
2867
+ local rec_file = M .config .whisper_dir .. " /rec.wav"
2866
2868
local rec_options = {
2867
2869
sox = {
2868
2870
cmd = " sox" ,
2869
2871
opts = {
2870
- -- single channel
2871
2872
" -c" ,
2872
2873
" 1" ,
2873
- -- small buffer
2874
2874
" --buffer" ,
2875
2875
" 32" ,
2876
2876
" -d" ,
2877
- -- output file
2878
- M .config .whisper_dir .. " /rec.wav" ,
2879
- -- max recording time
2877
+ " rec.wav" ,
2880
2878
" trim" ,
2881
2879
" 0" ,
2882
- M . config . whisper_max_time ,
2880
+ " 3600 " ,
2883
2881
},
2884
2882
exit_code = 0 ,
2885
2883
},
2886
2884
arecord = {
2887
2885
cmd = " arecord" ,
2888
2886
opts = {
2889
- -- single channel
2890
2887
" -c" ,
2891
2888
" 1" ,
2892
2889
" -f" ,
2893
2890
" S16_LE" ,
2894
2891
" -r" ,
2895
2892
" 48000" ,
2896
- -- max recording time
2897
2893
" -d" ,
2898
2894
3600 ,
2899
- -- output file
2900
- M .config .whisper_dir .. " /rec.wav" ,
2895
+ " rec.wav" ,
2901
2896
},
2902
2897
exit_code = 1 ,
2903
2898
},
@@ -2911,7 +2906,7 @@ M.Whisper = function(callback)
2911
2906
" :0" ,
2912
2907
" -t" ,
2913
2908
" 3600" ,
2914
- M . config . whisper_dir .. " / rec.wav" ,
2909
+ " rec.wav" ,
2915
2910
},
2916
2911
exit_code = 255 ,
2917
2912
},
@@ -3047,25 +3042,48 @@ M.Whisper = function(callback)
3047
3042
end )
3048
3043
end
3049
3044
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
3056
3057
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
3057
3074
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
3060
3079
end
3061
3080
3062
- local cmd = rec_options [rec_cmd ]
3063
3081
M ._H .process (nil , cmd .cmd , cmd .opts , function (code , signal , stdout , stderr )
3064
3082
close ()
3065
3083
3066
3084
if code and code ~= cmd .exit_code then
3067
3085
M .error (
3068
- rec_cmd
3086
+ cmd . cmd
3069
3087
.. " exited with code and signal:\n code: "
3070
3088
.. code
3071
3089
.. " , signal: "
0 commit comments