Skip to content

Instantly share code, notes, and snippets.

@ryseto
Created March 31, 2012 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryseto/2260412 to your computer and use it in GitHub Desktop.
Save ryseto/2260412 to your computer and use it in GitHub Desktop.
Speaking a selected region in Japanese (Emacs+OSX)
(defun MyTool-speech-region-Kyoko ()
"Convert text to audible speech by /usr/bin/say of OSX."
(interactive)
(let ((str (concat (buffer-substring-no-properties (point) (mark)))))
(setq str (replace-regexp-in-string "\\\\%" "percent" str))
(setq str (replace-regexp-in-string "%\n" "" str))
(setq str (replace-regexp-in-string "\\%[^\n]+" "" str))
(setq str (replace-regexp-in-string "%" "" str))
(setq str (replace-regexp-in-string "\\\\[a-zA-Z]+" " " str))
(setq str (replace-regexp-in-string "[$_^\n()~{}|;]" " " str))
(setq str (replace-regexp-in-string "\\ +" " " str))
(message str)
(if (eq (process-status "speech") 'run)
(delete-process "speech"))
(process-kill-without-query
(start-process-shell-command "speech" nil
"/usr/bin/say -v Kyoko" (concat "\"" str "\"" )))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment