Text-to-Speech in Emacs

前端 未结 2 625
轻奢々
轻奢々 2021-02-04 19:27

I\'m not blind, I just want to have a way to have my Windows machine read the contents of a buffer outloud. Here are the basic requirements:

  • Read any English text
2条回答
  •  不要未来只要你来
    2021-02-04 19:56

    I have a simple solution based on the Python pyttsx module. This starts a python script as an emacs process and sends it strings to be read out.

    (defvar tts nil "text to speech process")
    
    (defun tts-up ()
      (interactive)
      (and (not (null tts))
           (eq (process-status tts) 'run)))
    
    (defun tts-start ()
      (interactive)
      (if (not (tts-up))
          (setq tts
                (start-process "tts-python"
                               "*tts-python*"
                               "python" "speak.py"))))
    
    (defun tts-end ()
      (interactive)
      (delete-process tts)
      (setq tts nil))
    
    (defun tts-say (text)
      (interactive)
      (tts-start)
      (process-send-string tts (concat text "\n")))
    

    The python file speak.py:

    import pyttsx
    
    engine = pyttsx.init()
    
    def say(data):
        engine.say(data)
        engine.runAndWait()
    
    while True:
        say(raw_input())
    

提交回复
热议问题