Created
March 29, 2012 19:44
-
-
Save ryseto/2242924 to your computer and use it in GitHub Desktop.
Run 'say' command on Emacs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Convert text to audible speech by /usr/bin/say (Emacs + OSX) | |
(defun MyTeX-speech () | |
"Convert text to audible speech by /usr/bin/say of OSX." | |
(interactive) | |
(let (b e s | |
(block-sep-str "^\*\\|^\\ *%\\|^\\ *\n\\|\\\\item\\|\\\\begin\\|\\\\end")) | |
(if (eq (process-status "speech") 'run) | |
(delete-process "speech") | |
(progn | |
(if mark-active | |
(setq b (mark) e (point)) | |
(setq b (save-excursion | |
(progn | |
(re-search-backward block-sep-str (point-min) 1) | |
(point))) | |
e (save-excursion | |
(progn | |
(re-search-forward block-sep-str (point-max) 1) | |
(point))))) | |
(setq s (buffer-substring-no-properties b e) | |
s (replace-regexp-in-string "\\\\%" "percent" s) | |
s (replace-regexp-in-string "\\\\item" " " s) | |
s (replace-regexp-in-string "\\\\begin" " " s) | |
s (replace-regexp-in-string "\\\\end" " " s) | |
s (replace-regexp-in-string "%[^\n]*" "" s) | |
s (replace-regexp-in-string | |
"\\\\[a-zA-Z]+{\\|[$\\\\_^~(){}`*\n]" " " s) | |
s (replace-regexp-in-string "\\ +" " " s)) | |
(message s) | |
(process-kill-without-query | |
(start-process-shell-command "speech" nil | |
"/usr/bin/say" (concat "\"" s "\"" ))))))) | |
(define-key global-map [?\s-r] 'MyTeX-speech) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function converts text in a marked region or a block sectioned by %s at the beginning of a line to audible speech. It works on Mac OS X (/usr/bin/say is required.)