comparison plugins/voicenote/voicenote.vim @ 18:203279635445 default tip

Adding in the voice note ability. It's not perfect but it is working.
author Luka Sitas <lsitas@avatarasoftware.com>
date Tue, 16 Dec 2025 11:03:27 -0500
parents
children
comparison
equal deleted inserted replaced
17:412c33afd395 18:203279635445
1 let g:audio_record_file = -1
2 let g:audio_record_tmp_file = -1
3 let g:audio_record_cmd = expand('~/record.sh')
4 let g:audio_transcribe_cmd = expand('~/transcribe.sh')
5 let g:audio_record_pid = -1
6 let g:audio_record_transcript_file = -1
7
8 function! ToggleVoiceNote()
9 if g:audio_record_pid != -1
10 call StopRecording()
11 call TranscribeLastRecording()
12 else
13 call StartRecording()
14 endif
15 endfunction
16
17 function! StartRecording()
18 if g:audio_record_pid != -1
19 echo "Recording already in progress (PID " . g:audio_record_pid . ")"
20 return
21 endif
22
23 " Temp file where record.sh will write the WAV path
24 let l:temp_file = tempname()
25
26 " Run record.sh; its stdout (the wav path) goes to temp_file.
27 " Then echo the background PID.
28 let l:cmd = printf('%s > %s 2>/dev/null & echo $!', shellescape(g:audio_record_cmd), shellescape(l:temp_file))
29
30 let l:pid = str2nr(system(l:cmd))
31
32 if l:pid <= 0
33 echoerr "Failed to start recording"
34 return
35 endif
36
37 " Read the file path written by record.sh
38 let g:audio_record_file = trim(system('cat ' . shellescape(l:temp_file)))
39 let g:audio_record_tmp_file = l:temp_file
40 let g:audio_record_pid = l:pid
41
42 echo "Recording started (PID " . g:audio_record_pid . ") -> " . g:audio_record_file
43 endfunction
44
45 function! StopRecording()
46 if g:audio_record_pid == -1
47 echo "No recording in progress"
48 return
49 endif
50
51 call system('kill ' . g:audio_record_pid)
52
53 if g:audio_record_tmp_file != -1
54 call system('rm -f ' . shellescape(g:audio_record_tmp_file))
55 let g:audio_record_tmp_file = -1
56 endif
57
58 let g:audio_record_pid = -1
59 let g:audio_record_transcript_file = -1
60
61 echo "Recording stopped."
62 endfunction
63
64
65 function! TranscribeLastRecording()
66 if g:audio_record_file == -1
67 echo "No recent recording"
68 return
69 endif
70
71 let l:cmd = printf('%s %s', shellescape(g:audio_transcribe_cmd), shellescape(g:audio_record_file))
72
73 " transcribe.sh echoes the .txt path
74 let l:transcription_file = trim(system(l:cmd))
75
76 if v:shell_error != 0 || empty(l:transcription_file)
77 echoerr "Transcription failed"
78 return
79 endif
80
81 let g:audio_record_file = -1
82 execute 'tabe' fnameescape(l:transcription_file)
83 endfunction
84
85
86
87 " BINDINGS
88
89 command! VoiceNote call ToggleVoiceNote()
90
91 nnoremap <Leader>vn :VoiceNote<CR>