Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
My first defadvice
;; Read the inserted word out loud using the macOS speech synthesizer
;; when a misspelled word is corrected using the flyspell
;; `flyspell-auto-correct-word'-command. It will also work as a
;; say-at-point if the word at point is spelled correctly.
;;
;; Note this only work on macOS. It should be fairly easy to change to
;; work with other command line interface speech synthesize systems.
;;
;; Also note that this is my first defadvice function, so it might not
;; be art, but it seems to work. Also, there are some issues that need
;; to be corrected, like if a word is corrected to two words it will
;; only read the word the cursor is positioned on.
(defcustom mg/say-voice ""
"The voice to use, if nil use system voice"
:type '(choice
(const :tag "Default" "")
(const :tag "Magnus" "magnus")
(const :tag "Thomas" "thomas")
(const :tag "Samantha" "samantha")))
(defcustom mg/say-speech-rate 160
"The rate to use for the speech synthesizer"
:type 'integer)
(defun mg/say-at-point (&optional output-buffer)
(interactive)
(let ((voice (format "--voice=%s" mg/say-voice))
(rate (format "--rate=%d" mg/say-speech-rate))
(topic (format "/%s" (thing-at-point 'word))))
(start-process "speak" output-buffer "say" voice rate topic)))
(defadvice flyspell-auto-correct-word
(after mg/say-at-point activate)
(mg/say-at-point))
(ad-activate 'flyspell-auto-correct-word)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment