@@ -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
---- ----------------------------------------------------------------------------
@@ -2784,41 +2785,35 @@ M.Whisper = function(callback)
2784
2785
return
2785
2786
end
2786
2787
2788
+ local rec_file = M .config .whisper_dir .. " /rec.wav"
2787
2789
local rec_options = {
2788
2790
sox = {
2789
2791
cmd = " sox" ,
2790
2792
opts = {
2791
- -- single channel
2792
2793
" -c" ,
2793
2794
" 1" ,
2794
- -- small buffer
2795
2795
" --buffer" ,
2796
2796
" 32" ,
2797
2797
" -d" ,
2798
- -- output file
2799
- M .config .whisper_dir .. " /rec.wav" ,
2800
- -- max recording time
2798
+ " rec.wav" ,
2801
2799
" trim" ,
2802
2800
" 0" ,
2803
- M . config . whisper_max_time ,
2801
+ " 3600 " ,
2804
2802
},
2805
2803
exit_code = 0 ,
2806
2804
},
2807
2805
arecord = {
2808
2806
cmd = " arecord" ,
2809
2807
opts = {
2810
- -- single channel
2811
2808
" -c" ,
2812
2809
" 1" ,
2813
2810
" -f" ,
2814
2811
" S16_LE" ,
2815
2812
" -r" ,
2816
2813
" 48000" ,
2817
- -- max recording time
2818
2814
" -d" ,
2819
2815
3600 ,
2820
- -- output file
2821
- M .config .whisper_dir .. " /rec.wav" ,
2816
+ " rec.wav" ,
2822
2817
},
2823
2818
exit_code = 1 ,
2824
2819
},
@@ -2832,7 +2827,7 @@ M.Whisper = function(callback)
2832
2827
" :0" ,
2833
2828
" -t" ,
2834
2829
" 3600" ,
2835
- M . config . whisper_dir .. " / rec.wav" ,
2830
+ " rec.wav" ,
2836
2831
},
2837
2832
exit_code = 255 ,
2838
2833
},
@@ -2968,25 +2963,48 @@ M.Whisper = function(callback)
2968
2963
end )
2969
2964
end
2970
2965
2971
- local rec_cmd = " sox"
2972
- if vim .fn .executable (" ffmpeg" ) == 1 then
2973
- local devices = vim .fn .system (" ffmpeg -devices -v quiet | grep -i avfoundation | wc -l" )
2974
- devices = string.gsub (devices , " ^%s*(.-)%s*$" , " %1" )
2975
- if devices == " 1" then
2976
- rec_cmd = " ffmpeg"
2966
+ local cmd = {}
2967
+
2968
+ local rec_cmd = M .config .whisper_rec_cmd
2969
+ -- if rec_cmd not set explicitly, try to autodetect
2970
+ if not rec_cmd then
2971
+ rec_cmd = " sox"
2972
+ if vim .fn .executable (" ffmpeg" ) == 1 then
2973
+ local devices = vim .fn .system (" ffmpeg -devices -v quiet | grep -i avfoundation | wc -l" )
2974
+ devices = string.gsub (devices , " ^%s*(.-)%s*$" , " %1" )
2975
+ if devices == " 1" then
2976
+ rec_cmd = " ffmpeg"
2977
+ end
2977
2978
end
2979
+ if vim .fn .executable (" arecord" ) == 1 then
2980
+ rec_cmd = " arecord"
2981
+ end
2982
+ end
2983
+
2984
+ if type (rec_cmd ) == " table" and rec_cmd [1 ] and rec_options [rec_cmd [1 ]] then
2985
+ rec_cmd = vim .deepcopy (rec_cmd )
2986
+ cmd .cmd = table.remove (rec_cmd , 1 )
2987
+ cmd .exit_code = rec_options [cmd .cmd ].exit_code
2988
+ cmd .opts = rec_cmd
2989
+ elseif type (rec_cmd ) == " string" and rec_options [rec_cmd ] then
2990
+ cmd = rec_options [rec_cmd ]
2991
+ else
2992
+ M .error (string.format (" Whisper got invalid recording command: %s" , rec_cmd ))
2993
+ close ()
2994
+ return
2978
2995
end
2979
- if vim .fn .executable (" arecord" ) == 1 then
2980
- rec_cmd = " arecord"
2996
+ for i , v in ipairs (cmd .opts ) do
2997
+ if v == " rec.wav" then
2998
+ cmd .opts [i ] = rec_file
2999
+ end
2981
3000
end
2982
3001
2983
- local cmd = rec_options [rec_cmd ]
2984
3002
M ._H .process (nil , cmd .cmd , cmd .opts , function (code , signal , stdout , stderr )
2985
3003
close ()
2986
3004
2987
3005
if code and code ~= cmd .exit_code then
2988
3006
M .error (
2989
- rec_cmd
3007
+ cmd . cmd
2990
3008
.. " exited with code and signal:\n code: "
2991
3009
.. code
2992
3010
.. " , signal: "
0 commit comments