home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / speak.el < prev    next >
Encoding:
Text File  |  1992-05-16  |  3.0 KB  |  89 lines

  1. ;; LCD Archive Entry:
  2. ;; speak|Dave Brennan|brennan@hal.com|
  3. ;; Make Emacs speak on Sun Sparc (requires Brown U. speak package)|
  4. ;; 92-02-13|1.0|~/misc/speak.el|
  5.  
  6. ;; Copyright 1992, David J. Brennan
  7. ;; GNU Copyleft applies.
  8.  
  9. ;; This is a simple interface to the speak package from Brown University.
  10. ;; Speak can be ftped from the machine wilma.cs.brown.edu.
  11.  
  12. ;; Interesting functions:
  13.  
  14. ;; M-x speak             Prompt for a string and speak it
  15. ;; M-x speak-region      Speak the current region
  16. ;; M-x speak-buffer      Speak the current buffer
  17.  
  18. ;; The next three variables are interesting:
  19.  
  20. ;; Make sure scat is in your path or set this to the full path in your .emacs.
  21. (defvar speak-program "scat"
  22.   "*Name of the speak executable.")
  23.  
  24. (defvar speak-phoneme-directory nil
  25.   "*Directory to look for phonemes.  nil mean use default directory.")
  26.  
  27. (defvar speak-volume nil
  28.   "*Speech volume from 0.0 to 1.0.  Changes to this variable will (currently)
  29. not change the speech volume after the speech process has started.  nil
  30. means use the default volume of speak-program.")
  31.  
  32. ;; Casual users probably don't care about anything below this.
  33.  
  34. (defvar speak-phoneme-dir-flag "-d"
  35.   "Option flag used to set the phoneme directory.")
  36.  
  37. (defvar speak-volume-flag "-v"
  38.   "Option flag used to set the speech volume.")
  39.  
  40. (defvar speak-process nil
  41.   "Process of the speak-program.")
  42.  
  43. (defun speak (string)
  44.   (interactive "sSpeak: ")
  45.   "Speak STRING.  When used interactively prompts for string."
  46.   (speak-start-process)
  47.   (process-send-string speak-process (concat string "\n")))
  48.  
  49. (defun speak-region (start end)
  50.   (interactive "r")
  51.   "Speak the text in region.
  52. When called from a program takes two arguments: START and END."
  53.   (speak-start-process)
  54.   (process-send-region speak-process start end)
  55.   (process-send-string speak-process "\n"))
  56.  
  57. (defun speak-buffer (&optional buffer)
  58.   (interactive)
  59.   "Speak the text in the current buffer.
  60. When called from a program takes optional arg BUFFER."
  61.   (if buffer
  62.       (save-excursion
  63.     (set-buffer buffer)
  64.     (speak-region (point-min) (point-max)))))
  65.  
  66. (defun speak-start-process ()
  67.   "Start the speak process if it isn't already running."
  68.   (if (or (eq speak-process nil)
  69.       (not (eq (process-status speak-process) 'run)))
  70.       (if (file-exists-p speak-program)
  71.       (let ((args (list speak-program)))
  72.         ;; Compute arguments
  73.         (message "Starting the speak process...")
  74.         (if speak-phoneme-directory
  75.         (setq args (append args (list speak-phoneme-dir-flag
  76.                           speak-phoneme-directory))))
  77.         (if speak-volume
  78.         (setq args (append (args (list speak-volume-flag
  79.                            speak-volume)))))
  80.         (setq speak-process (apply 'start-process "speak" nil args))
  81.         (setq process-sentinel speak-process speak-process-sentinel)
  82.         (message "Starting the speak process...done."))
  83.     (error "Can't find speak executable: %s." speak-program))))
  84.  
  85. (defun speak-process-sentinel (proc status)
  86.   "Reset the speak-process variable if the state changes."
  87.   (message "Speak process exited with status %s" status)
  88.   (setq speak-process nil))
  89.