natrys / whisper.el

Speech-to-Text interface for Emacs using OpenAI's whisper model and whisper.cpp as inference engine.
140 stars 10 forks source link

Add post-insert hook #21

Closed cashpw closed 7 months ago

cashpw commented 7 months ago

I included docs in this one. My bad on the last (#20).

cashpw commented 7 months ago

My primary use case for this is piping whisper's transcription directly into gptel.


(after! (:and gptel whisper)
  (setq
   cashpw/gptel-after-whisper nil
   whisper-return-cursor-to-start nil)

  (defun cashpw/whisper-run-and-cue-gptel ()
    (interactive)
    (setq
     cashpw/gptel-after-whisper t)
    (whisper-run))

  (defun cashpw/maybe-gptel-after-whisper ()
    (when cashpw/gptel-after-whisper
      (gptel-send)
      (setq
       cashpw/gptel-after-whisper nil)))

  (add-hook 'whisper-post-insert-hook
            #'cashpw/maybe-gptel-after-whisper))

(map!
 ;; Keep in alphabetical order.
 (:leader
  ;; ...
  :desc "LLM" :n "l" #'gptel-send
  :n "r" #'whisper-run
  :n "R" #'cashpw/whisper-run-and-cue-gptel
  ;; ...
))
natrys commented 7 months ago

That's pretty cool. I felt the need for this recently (#19) actually. Thanks a lot for doing it.

(I had to resolve conflict after I made some doc change. Then I locally squashed the commits but github now can't pick up the merge here, sorry about that.)

Anyway, I wonder if it now makes sense to rename post-process-hook to after-transcription-hook for more clarity.

cashpw commented 7 months ago

Renaming is all good by me! I can make the change or you can, whichever is easier.

On Sun, Feb 11, 2024, 06:11 Imran Khan @.***> wrote:

That's pretty cool. I felt the need for this recently (#19 https://github.com/natrys/whisper.el/issues/19) actually. Thanks a lot for doing it.

(I had to resolve conflict after I made some doc change. Then I locally squashed the commits but github now can't pick up the merge here, sorry about that.)

Anyway, I wonder if it now makes sense to rename post-process-hook to after-transcription-hook for more clarity.

— Reply to this email directly, view it on GitHub https://github.com/natrys/whisper.el/pull/21#issuecomment-1937765867, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANRKHUHSIFU6NGPUTSPSSUTYTDGRHAVCNFSM6AAAAABDDBCXO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZXG43DKOBWG4 . You are receiving this because you authored the thread.Message ID: @.***>

natrys commented 7 months ago

A little late but I got to it. Small heads up, had to rename your whisper-post-insert-hook to whisper-after-insert-hook for consistency with other renames.