Skip to content

Instantly share code, notes, and snippets.

@kinjo kinjo/osx-say.el
Last active Aug 29, 2015

What would you like to do?
;;; osx-say.el --- Utilizing `say' command which Mac OSX has for Emacs
;; Copyright (C) 2014 Takumi Kinjo
;; Author: Takumi Kinjo <>
;; Keywords: local, hypermedia
;; This file is not part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <>.
;;; Commentary:
;; Utilizing `say' command which Mac OSX has for Emacs.
;; This library was forked from
;;; Code:
(defgroup osx-say nil
"Option for osx-say."
:group 'osx-say)
(defcustom osx-say-speed 180
"Adjust speak speed."
:group 'osx-say :type 'integer)
(defcustom osx-say-voice "Alex"
"Kathy, Vicki, Victoria, Alex, Bruce and Fred are available."
:group 'osx-say
:type '(choice (const "Kathy")
(const "Vicki")
(const "Victoria")
(const "Alex")
(const "Bruce")
(const "Fred")))
(defconst osx-say-buffer "*osx say*")
(defun osx-say-stop ()
(when (get-buffer osx-say-buffer)
(kill-buffer osx-say-buffer)))
(defun osx-say (&optional $word $speed)
"Utilize `say' command that Mac OSX has."
(unless (executable-find "say")
(error (message "`say' command not found")))
(cond ($word $word)
(setq $word
(region-beginning) (region-end))))
((setq $word (thing-at-point 'word)))
(t (setq $word (read-string "word: "))))
(mapc (lambda ($r)
(setq $word (replace-regexp-in-string (car $r) (cdr $r) $word)))
(list ;;'("'" . "\\\\'")
'("\"" . "\\\\\"")
'("?" . "\\\\?")
'("\n" . " ")
'("\(" . "\\\\(")
'("\)" . "\\\\)")
'("\\[" . "\\\\[")
'("\\]" . "\\\\]")
'("\;" . "\\\\;")
'("\&" . "\\\\&")
'("\|" . "\\\\|")))
(start-process "OSX Say" osx-say-buffer
"say" "-v" osx-say-voice "-r"
(number-to-string (or $speed osx-say-speed)) $word)))
(defun osx-say-word ()
"Do osx-say with a word at point."
(osx-say (thing-at-point 'word)))
(defun osx-say-line ()
"Do osx-say with a line at point."
(line-beginning-position) (line-end-position))))
(define-minor-mode osx-say-minor-mode
"Toggle osx-say minor mode."
;; The initial value.
:init-value nil
;; The indicator for the mode line.
:lighter " say"
;; The minor mode bindings.
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c s w") 'osx-say-word)
(define-key map (kbd "C-c s l") 'osx-say-line)
(provide 'osx-say)
;;; osx-say.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.