emacs-nano-tts-minor-mode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit cda12a8338fead45f8c35b346a070d60b00dcc47
parent 9bdbeea061e8e043aa50cd791778126ed938ae6c
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Sat,  8 Jul 2023 17:11:59 +0300

Now you have to manually kill the process before starting another text-to-speech process.

Diffstat:
Mnano-tts.el | 42++++++++++++++++++++++++++++++++++++------
1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/nano-tts.el b/nano-tts.el @@ -1,12 +1,37 @@ ;; -*- lexical-binding: t -*- +(defvar nano-tts--tts-process + nil + "The process of a running text-to-speech engine. + +nil when no text-to-speech engine is running.") + + (defun nano-tts-speak () (interactive) - (let ((start (min (mark) (point))) - (end (max (mark) (point)))) - (call-process-region start - end - "espeak"))) + + (unless nano-tts--tts-process + ;; We start the engine so that later we can send text to it. + (setq nano-tts--tts-process + (make-process + :name "espeak" + :command (list "espeak"))) + + (let* ((start (min (mark) (point))) + (end (max (mark) (point))) + (text-to-speak (buffer-substring start + end))) + (process-send-string nano-tts--tts-process + (concat text-to-speak "\n"))))) + + +(defun nano-tts-kill () + (interactive) + + (kill-process nano-tts--tts-process) + (setq nano-tts--tts-process + nil)) + (define-minor-mode nano-tts "A very small text to speech thingimajig." @@ -16,6 +41,11 @@ (list (cons (kbd "C-c c") 'nano-tts-speak) (cons (kbd "C-c C-c") - 'nano-tts-speak))) + 'nano-tts-speak) + (cons (kbd "C-c k") + 'nano-tts-kill) + (cons (kbd "C-c C-k") + 'nano-tts-kill))) + (provide 'nano-tts)