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