-
Notifications
You must be signed in to change notification settings - Fork 23
Add eca-chat-talk command #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This command uses whisper.el (if installed) to record audio until the user presses `RET`. The recorded audio will then be transcribed to text and placed into the chat buffer.
eca-chat.el
Outdated
| (defun eca-chat-talk () | ||
| "Talk to the assistent by recording audio and transcribing it." | ||
| (interactive) | ||
| (unless (featurep 'whisper) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be a if and do not execute the rest of the code if whisper is not installed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I would say calling this function (via M-x or the keybinding) without whisper.el installed is a user error and we should tell them what to do instead, no? I don't really mind, but I would not be silent about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, agree, but my point is that the unless block is not wrapping the rest of the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, so in my mind this is a guard, because user-error raises a condition. The code following it, won't be called. See: https://www.gnu.org/software/emacs/manual/html_node/elisp/Signaling-Errors.html
Here is a similar example from the CIDER code base:
https://github.com/r0man/cider/blob/aa8d638814d4f4da70e5f0fe5a9aec63eb6c5a8f/cider-clojuredocs.el#L195-L196
I could do an if/else branch like this if you prefer:
(defun eca-chat-talk ()
"Talk to the assistent by recording audio and transcribing it."
(interactive)
(if (not (require 'whisper nil t))
(user-error "Whisper.el is not available, please install it first")
(eca-chat-open)
(with-current-buffer (eca-chat--get-buffer)
(goto-char (point-max)))
(let ((buffer (get-buffer-create "*whisper-stdout*")))
(with-current-buffer buffer
(erase-buffer)
(make-local-variable 'whisper-after-transcription-hook)
(add-hook 'whisper-after-transcription-hook
(lambda ()
(let ((transcription (buffer-substring
(line-beginning-position)
(line-end-position))))
(with-current-buffer eca-chat-buffer-name
(insert transcription)
(newline)
(eca-chat--key-pressed-return))))
nil t)
(whisper-run)
(eca-info "Recording audio. Press RET when you are done.")
(while (not (equal ?\r (read-char)))
(sit-for 0.5))
(whisper-run)))))Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh makes sense, forgot about this behavior of error.
|
I added 2 more commits:
|
|
Looks good! |
This command uses whisper.el (if installed) to record audio until the user presses
RET. The recorded audio will then be transcribed to text and placed into the chat buffer.Open questions, things todo:
eca-chat-talka good command name? Other options could beeca-chat-record,eca-chat-whisper, ....message. Using the eca spinner would be better, but whipser.el itself usesmessagecalls under the hood and I wasn't able to silence them (due to them being called in an async way in hooks).