diff options
Diffstat (limited to 'modules/transcription-config.el')
| -rw-r--r-- | modules/transcription-config.el | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/modules/transcription-config.el b/modules/transcription-config.el index 566cea499..944063b88 100644 --- a/modules/transcription-config.el +++ b/modules/transcription-config.el @@ -173,13 +173,17 @@ TITLE and MESSAGE are strings. URGENCY is normal or critical." :body message :urgency (or urgency 'normal)))) -(defun cj/--start-transcription-process (audio-file &optional cleanup-file) +(defun cj/--start-transcription-process (audio-file &optional cleanup-file output-base) "Start async transcription process for AUDIO-FILE. Returns the process object. When CLEANUP-FILE is non-nil, delete that path once the transcription sentinel fires (success or failure). Used by the video flow to drop -the temp audio file produced by ffmpeg after transcription completes." +the temp audio file produced by ffmpeg after transcription completes. + +OUTPUT-BASE, when non-nil, is the path the .txt/.log outputs derive from +instead of AUDIO-FILE. The video flow passes the original video so the +transcript lands alongside the source, not next to the temp /tmp audio." (unless (file-exists-p audio-file) (user-error "Audio file does not exist: %s" audio-file)) @@ -187,10 +191,12 @@ the temp audio file produced by ffmpeg after transcription completes." (user-error "Not an audio file: %s" audio-file)) (let* ((script (cj/--transcription-script-path)) - (outputs (cj/--transcription-output-files audio-file)) + (outputs (cj/--transcription-output-files (or output-base audio-file))) (txt-file (car outputs)) (log-file (cdr outputs)) (buffer-name (format " *transcribe-%s*" (file-name-nondirectory audio-file))) + (stderr-buffer-name (format " *transcribe-stderr-%s*" + (file-name-nondirectory audio-file))) (process-name (format "transcribe-%s" (file-name-nondirectory audio-file)))) (unless (file-executable-p script) @@ -199,15 +205,25 @@ the temp audio file produced by ffmpeg after transcription completes." (cj/--init-log-file log-file audio-file script) (let* ((process-environment (cj/--build-process-environment cj/transcribe-backend)) + ;; A live, explicitly-managed buffer for stderr. Passing a file PATH + ;; to :stderr makes Emacs create a phantom buffer named after the + ;; path, so the error text never reaches the log file and that buffer + ;; leaks per run; the sentinel drains this buffer into the log and + ;; kills it. Keeping stderr off the stdout :buffer leaves the + ;; transcript (stdout) clean. + (stderr-buffer (with-current-buffer (get-buffer-create stderr-buffer-name) + (erase-buffer) + (current-buffer))) (process (make-process :name process-name :buffer (get-buffer-create buffer-name) :command (list script audio-file) :sentinel (lambda (proc event) - (cj/--transcription-sentinel proc event audio-file txt-file log-file) + (cj/--transcription-sentinel proc event audio-file + txt-file log-file stderr-buffer) (when cleanup-file (ignore-errors (delete-file cleanup-file)))) - :stderr log-file))) + :stderr stderr-buffer))) (cj/--track-transcription process audio-file) (cj/--notify "Transcription" (format "Started on %s" (file-name-nondirectory audio-file))) @@ -290,20 +306,25 @@ References TXT-FILE on success (normal urgency), LOG-FILE on failure (format "Errored. Logs in %s" (file-name-nondirectory log-file)) 'critical))) -(defun cj/--transcription-sentinel (process event _audio-file txt-file log-file) +(defun cj/--transcription-sentinel (process event _audio-file txt-file log-file stderr-buffer) "Sentinel for transcription PROCESS. EVENT is the process event string. TXT-FILE and LOG-FILE are the -associated output files." +associated output files. STDERR-BUFFER holds the process's stderr; its +contents are appended to LOG-FILE so the \"Logs in <file>\" notification +points at real error text, and the buffer is then killed so it does not +leak per run." (let* ((success-p (and (string-match-p "finished" event) (= 0 (process-exit-status process)))) (process-buffer (process-buffer process))) (cj/--write-transcript-on-success process-buffer success-p txt-file) - (cj/--append-to-log process-buffer log-file event) + (cj/--append-to-log stderr-buffer log-file event) (cj/--update-transcription-status process success-p) (when (and success-p (not (cj/--should-keep-log success-p))) (delete-file log-file)) (when (buffer-live-p process-buffer) (kill-buffer process-buffer)) + (when (buffer-live-p stderr-buffer) + (kill-buffer stderr-buffer)) (cj/--notify-completion success-p txt-file log-file) (run-at-time 600 nil #'cj/--cleanup-completed-transcriptions) (force-mode-line-update t))) @@ -371,7 +392,9 @@ FILE.log with process logs. Uses the backend in (cj/--extract-audio-from-video path extracted (lambda () - (cj/--start-transcription-process extracted extracted)))))))) + ;; Pass the source video as the output base so the .txt/.log land + ;; alongside it, not next to the temp /tmp audio. + (cj/--start-transcription-process extracted extracted path)))))))) ;;;###autoload (defun cj/transcribe-media-at-point () |
